import socket
import sys
s = socket.create_connection((\'leaveret.kr\', 14123))
def recv_until(t):
global s
d = \'\'
while t not in d:
c = s.recv(1)
sys.stdout.write(c)
d += c
return d
while True:
recv_until(\'STAGE\')
recv_until(\'\\n\')
assembly = recv_until(\'What\')[:-5].strip()
assembly = """.intel_syntax noprefix
.globl main
main:
push rbp
mov rbp, rsp
""" + assembly + """
mov rdi, offset format
mov rsi, rax
call printf
call exit
format: .asciz "%lu\\n"
"""
f = open(\'file.s\', \'wb\')
f.write(assembly)
f.close()
import os
os.system(\'gcc file.s -o file; ./file > output\')
output = open(\'output\', \'rb\')
RAX = int(output.read())
output.close()
print \'RAX is\', RAX
s.send(str(RAX) + \'\\n\')