#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int get_32(char *, int);
int /*<<< orphan*/ printf(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send_command(int, int, int /*<<< orphan*/,
                                int /*<<< orphan*/, int /*<<< orphan*/, char *);
void get_answer(int s) {
  char data[102400];
  int command = 0x1b;
  while (command == 0x1b) {
    int len;
    len = recv(s, data, 102400, 0);
    if (!len) {
      printf("\nalert! eof\n");
      return;
    }
    command = get_32(data, 36) & 0xFFFF;
    if (command == 0x1b)
      send_command(s, 0x1b, 0, 0, 0, data);
  }
}


x86 assembly (clang, -O0):
<get_answer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x19020,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1b,-0x19014(%rbp)
cmpl   $0x1b,-0x19014(%rbp)
jne    11ea <get_answer+0xaa>
mov    -0x4(%rbp),%edi
lea    -0x19010(%rbp),%rsi
mov    $0x19000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x19018(%rbp)
cmpl   $0x0,-0x19018(%rbp)
jne    119f <get_answer+0x5f>
lea    0xe6b(%rip),%rdi
call   1040 <printf@plt>
jmp    11ea <get_answer+0xaa>
lea    -0x19010(%rbp),%rdi
mov    $0x24,%esi
call   1050 <get_32@plt>
and    $0xffff,%eax
mov    %eax,-0x19014(%rbp)
cmpl   $0x1b,-0x19014(%rbp)
jne    11e5 <get_answer+0xa5>
mov    -0x4(%rbp),%edi
lea    -0x19010(%rbp),%r9
mov    $0x1b,%esi
xor    %r8d,%r8d
mov    %r8d,%edx
mov    %r8d,%ecx
call   1060 <send_command@plt>
jmp    1158 <get_answer+0x18>
add    $0x19020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_answer>:
push   %r14
push   %rbx
sub    $0x19008,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x19000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     11ae <get_answer+0x6e>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    $0x24,%esi
call   1050 <get_32@plt>
cmp    $0x1b,%ax
jne    11ba <get_answer+0x7a>
mov    %ebx,%edi
mov    $0x1b,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    %r14,%r9
call   1060 <send_command@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x19000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    1170 <get_answer+0x30>
lea    0xe4b(%rip),%rdi
call   1040 <puts@plt>
add    $0x19008,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"\0Aalert! eof\0A\00"
define void @get_answer(i32 %0) {
%2 = alloca i32
%3 = alloca [102400 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 27, i32* %4
br label %6
6: ; preds = %27, %1
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 27
br i1 %8, label %9, label %28
9: ; preds = %6
%10 = load i32, i32* %2
%11 = getelementptr inbounds [102400 x i8], [102400 x i8]* %3, i64 0, i64 0
%12 = call i32 @recv(i32 %10, i8* %11, i32 102400, i32 0)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %28
17: ; preds = %9
%18 = getelementptr inbounds [102400 x i8], [102400 x i8]* %3, i64 0, i64 0
%19 = call i32 @get_32(i8* %18, i32 36)
%20 = and i32 %19, 65535
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 27
br i1 %22, label %23, label %27
23: ; preds = %17
%24 = load i32, i32* %2
%25 = getelementptr inbounds [102400 x i8], [102400 x i8]* %3, i64 0, i64 0
%26 = call i32 @send_command(i32 %24, i32 27, i32 0, i32 0, i32 0, i8* %25)
br label %27
27: ; preds = %23, %17
br label %6
28: ; preds = %15, %6
ret void
}

LLVM IR (-O2):
@str = [12 x i8] c"\0Aalert! eof\00"
define void @get_answer(i32 %0) {
%2 = alloca [102400 x i8]
%3 = getelementptr inbounds [102400 x i8], [102400 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 102400, i32 0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %12, %1
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %16
8: ; preds = %1, %12
%9 = call i32 @get_32(i8* %3, i32 36)
%10 = and i32 %9, 65535
%11 = icmp eq i32 %10, 27
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = call i32 @send_command(i32 %0, i32 27, i32 0, i32 0, i32 0, i8* %3)
%14 = call i32 @recv(i32 %0, i8* %3, i32 102400, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %6, label %8
16: ; preds = %8, %6
ret void
}