#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 */
typedef int uint32_t;
struct sockaddr {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int socklen_t;

/* Variables and functions */
int ntohl(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recvfrom(int, int *, size_t, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int fnRecvGameState(int sockfd) {
  int i;
  size_t left;
  ssize_t read;
  uint32_t buffer[9], *pBuffer;
  struct sockaddr sourc_addr;
  socklen_t addr_len;
  addr_len = sizeof(struct sockaddr);
  left = sizeof(uint32_t) * 9;
  pBuffer = &buffer[0];
  while (left > 0) {
    if ((read = recvfrom(sockfd, pBuffer, left, 0, &sourc_addr, &addr_len)) < 0)
      return 1;
    left -= read;
    pBuffer += read;
  }
  for (i = 0; i < 9; i++) {
    buffer[i] = ntohl(buffer[i]);
  }
  printf("\t~ANSWER~\n");
  printf("iPlayerId: %x\n", buffer[0]);
  printf("iFlag: %x\n", buffer[8]);
  return 0;
}


x86 assembly (clang, -O0):
<fnRecvGameState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0x64(%rbp)
movq   $0x24,-0x18(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x18(%rbp)
jbe    11b5 <fnRecvGameState+0x85>
mov    -0x8(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x18(%rbp),%rdx
xor    %ecx,%ecx
lea    -0x60(%rbp),%r8
lea    -0x64(%rbp),%r9
call   1040 <recvfrom@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    1191 <fnRecvGameState+0x61>
movl   $0x1,-0x4(%rbp)
jmp    1222 <fnRecvGameState+0xf2>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    1152 <fnRecvGameState+0x22>
movl   $0x0,-0xc(%rbp)
cmpl   $0x9,-0xc(%rbp)
jge    11eb <fnRecvGameState+0xbb>
movslq -0xc(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%edi
call   1050 <ntohl@plt>
mov    %eax,%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x50(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bc <fnRecvGameState+0x8c>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x50(%rbp),%esi
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnRecvGameState>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x30,%rsp
mov    %edi,%r14d
movl   $0x4,0x24(%rsp)
mov    $0x24,%ebx
mov    %rsp,%rbp
lea    0x28(%rsp),%r15
lea    0x24(%rsp),%r12
nopl   0x0(%rax)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
xor    %ecx,%ecx
mov    %r15,%r8
mov    %r12,%r9
call   1050 <recvfrom@plt>
test   %rax,%rax
js     123f <fnRecvGameState+0xff>
lea    0x0(%rbp,%rax,4),%rbp
sub    %rax,%rbx
jne    1170 <fnRecvGameState+0x30>
mov    (%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,(%rsp)
mov    0x4(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x8(%rsp)
mov    0xc(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0xc(%rsp)
mov    0x10(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x10(%rsp)
mov    0x14(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x14(%rsp)
mov    0x18(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x18(%rsp)
mov    0x1c(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x1c(%rsp)
mov    0x20(%rsp),%edi
call   1060 <ntohl@plt>
mov    %eax,0x20(%rsp)
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
mov    (%rsp),%esi
lea    0xdde(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x20(%rsp),%esi
lea    0xdd9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1244 <fnRecvGameState+0x104>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [11 x i8] c"\09~ANSWER~\0A\00"
@.str.1 = [15 x i8] c"iPlayerId: %x\0A\00"
@.str.2 = [11 x i8] c"iFlag: %x\0A\00"
define i32 @fnRecvGameState(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca [9 x i32]
%8 = alloca i32*
%9 = alloca %struct.sockaddr
%10 = alloca i32
store i32 %0, i32* %3
store i32 4, i32* %10
store i64 36, i64* %5
%11 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 0
store i32* %11, i32** %8
br label %12
12: ; preds = %22, %1
%13 = load i64, i64* %5
%14 = icmp ugt i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %12
%16 = load i32, i32* %3
%17 = load i32*, i32** %8
%18 = load i64, i64* %5
%19 = call i64 @recvfrom(i32 %16, i32* %17, i64 %18, i32 0, %struct.sockaddr* %9, i32* %10)
store i64 %19, i64* %6
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 1, i32* %2
br label %53
22: ; preds = %15
%23 = load i64, i64* %6
%24 = load i64, i64* %5
%25 = sub i64 %24, %23
store i64 %25, i64* %5
%26 = load i64, i64* %6
%27 = load i32*, i32** %8
%28 = getelementptr inbounds i32, i32* %27, i64 %26
store i32* %28, i32** %8
br label %12
29: ; preds = %12
store i32 0, i32* %4
br label %30
30: ; preds = %42, %29
%31 = load i32, i32* %4
%32 = icmp slt i32 %31, 9
br i1 %32, label %33, label %45
33: ; preds = %30
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @ntohl(i32 %37)
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 %40
store i32 %38, i32* %41
br label %42
42: ; preds = %33
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %30
45: ; preds = %30
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%47 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 0
%48 = load i32, i32* %47
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 8
%51 = load i32, i32* %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %51)
store i32 0, i32* %2
br label %53
53: ; preds = %45, %21
%54 = load i32, i32* %2
ret i32 %54
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str.1 = [15 x i8] c"iPlayerId: %x\0A\00"
@.str.2 = [11 x i8] c"iFlag: %x\0A\00"
@str = [10 x i8] c"\09~ANSWER~\00"
define i32 @fnRecvGameState(i32 %0) {
%2 = alloca [9 x i32]
%3 = alloca %struct.sockaddr
%4 = alloca i32
%5 = bitcast [9 x i32]* %2 to i8*
%6 = bitcast %struct.sockaddr* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 0
br label %9
9: ; preds = %1, %14
%10 = phi i32* [ %8, %1 ], [ %16, %14 ]
%11 = phi i64 [ 36, %1 ], [ %15, %14 ]
%12 = call i64 @recvfrom(i32 %0, i32* %10, i64 %11, i32 0, %struct.sockaddr* %3, i32* %4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %50, label %14
14: ; preds = %9
%15 = sub i64 %11, %12
%16 = getelementptr inbounds i32, i32* %10, i64 %12
%17 = icmp eq i64 %15, 0
br i1 %17, label %18, label %9
18: ; preds = %14
%19 = load i32, i32* %8
%20 = call i32 @ntohl(i32 %19)
store i32 %20, i32* %8
%21 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @ntohl(i32 %22)
store i32 %23, i32* %21
%24 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 2
%25 = load i32, i32* %24
%26 = call i32 @ntohl(i32 %25)
store i32 %26, i32* %24
%27 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 3
%28 = load i32, i32* %27
%29 = call i32 @ntohl(i32 %28)
store i32 %29, i32* %27
%30 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 4
%31 = load i32, i32* %30
%32 = call i32 @ntohl(i32 %31)
store i32 %32, i32* %30
%33 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 5
%34 = load i32, i32* %33
%35 = call i32 @ntohl(i32 %34)
store i32 %35, i32* %33
%36 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 6
%37 = load i32, i32* %36
%38 = call i32 @ntohl(i32 %37)
store i32 %38, i32* %36
%39 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 7
%40 = load i32, i32* %39
%41 = call i32 @ntohl(i32 %40)
store i32 %41, i32* %39
%42 = getelementptr inbounds [9 x i32], [9 x i32]* %2, i64 0, i64 8
%43 = load i32, i32* %42
%44 = call i32 @ntohl(i32 %43)
store i32 %44, i32* %42
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%46 = load i32, i32* %8
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %42
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %48)
br label %50
50: ; preds = %9, %18
%51 = phi i32 [ 0, %18 ], [ 1, %9 ]
ret i32 %51
}