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

/* Variables and functions */
int /*<<< orphan*/ htonl(int);
scalar_t__ sendto(int, int /*<<< orphan*/ *, size_t, int /*<<< orphan*/,
                  struct sockaddr *, int /*<<< orphan*/);
int fnSendGameState(int iPlayerId, int iFlag, int sockfd,
                    struct sockaddr dest_addr, socklen_t addrlen) {
  ssize_t sent;
  size_t left;
  uint32_t buffer[9], *pBuffer;
  buffer[0] = htonl(iPlayerId);
  buffer[8] = htonl(iFlag);
  left = sizeof(uint32_t) * 9;
  pBuffer = &buffer[0];
  while (left > 0) {
    if ((sent = sendto(sockfd, pBuffer, left, 0, &dest_addr, addrlen)) < 0)
      return 1;
    left -= sent;
    pBuffer += sent;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fnSendGameState>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %ecx,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x50(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <htonl@plt>
mov    %eax,-0x30(%rbp)
movq   $0x24,-0x28(%rbp)
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x28(%rbp)
jbe    11c1 <fnSendGameState+0xa1>
mov    -0x14(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%r9d
xor    %ecx,%ecx
lea    -0x8(%rbp),%r8
call   1040 <sendto@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jge    119d <fnSendGameState+0x7d>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <fnSendGameState+0xa8>
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
add    -0x58(%rbp),%rax
mov    %rax,-0x58(%rbp)
jmp    115e <fnSendGameState+0x3e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnSendGameState>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    %r8d,%r14d
mov    %edx,%r15d
mov    %esi,%ebp
mov    %ecx,0x8(%rsp)
call   1030 <htonl@plt>
lea    0x10(%rsp),%rbx
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
call   1030 <htonl@plt>
mov    %eax,0x30(%rsp)
mov    $0x24,%ebp
lea    0x8(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %ecx,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
call   1040 <sendto@plt>
test   %rax,%rax
js     1188 <fnSendGameState+0x68>
lea    (%rbx,%rax,4),%rbx
sub    %rax,%rbp
jne    1160 <fnSendGameState+0x40>
xor    %eax,%eax
jmp    118d <fnSendGameState+0x6d>
mov    $0x1,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
define i32 @fnSendGameState(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca %struct.sockaddr
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i64
%13 = alloca i64
%14 = alloca [9 x i32]
%15 = alloca i32*
%16 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %7, i32 0, i32 0
store i32 %3, i32* %16
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %4, i32* %11
%17 = load i32, i32* %8
%18 = call i32 @htonl(i32 %17)
%19 = getelementptr inbounds [9 x i32], [9 x i32]* %14, i64 0, i64 0
store i32 %18, i32* %19
%20 = load i32, i32* %9
%21 = call i32 @htonl(i32 %20)
%22 = getelementptr inbounds [9 x i32], [9 x i32]* %14, i64 0, i64 8
store i32 %21, i32* %22
store i64 36, i64* %13
%23 = getelementptr inbounds [9 x i32], [9 x i32]* %14, i64 0, i64 0
store i32* %23, i32** %15
br label %24
24: ; preds = %35, %5
%25 = load i64, i64* %13
%26 = icmp ugt i64 %25, 0
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load i32, i32* %10
%29 = load i32*, i32** %15
%30 = load i64, i64* %13
%31 = load i32, i32* %11
%32 = call i64 @sendto(i32 %28, i32* %29, i64 %30, i32 0, %struct.sockaddr* %7, i32 %31)
store i64 %32, i64* %12
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %27
store i32 1, i32* %6
br label %43
35: ; preds = %27
%36 = load i64, i64* %12
%37 = load i64, i64* %13
%38 = sub i64 %37, %36
store i64 %38, i64* %13
%39 = load i64, i64* %12
%40 = load i32*, i32** %15
%41 = getelementptr inbounds i32, i32* %40, i64 %39
store i32* %41, i32** %15
br label %24
42: ; preds = %24
store i32 0, i32* %6
br label %43
43: ; preds = %42, %34
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
define i32 @fnSendGameState(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.sockaddr
%7 = alloca [9 x i32]
%8 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %6, i64 0, i32 0
store i32 %3, i32* %8
%9 = bitcast [9 x i32]* %7 to i8*
%10 = tail call i32 @htonl(i32 %0)
%11 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 0
store i32 %10, i32* %11
%12 = tail call i32 @htonl(i32 %1)
%13 = getelementptr inbounds [9 x i32], [9 x i32]* %7, i64 0, i64 8
store i32 %12, i32* %13
br label %14
14: ; preds = %5, %19
%15 = phi i32* [ %11, %5 ], [ %21, %19 ]
%16 = phi i64 [ 36, %5 ], [ %20, %19 ]
%17 = call i64 @sendto(i32 %2, i32* %15, i64 %16, i32 0, %struct.sockaddr* %6, i32 %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = sub i64 %16, %17
%21 = getelementptr inbounds i32, i32* %15, i64 %17
%22 = icmp eq i64 %20, 0
br i1 %22, label %23, label %14
23: ; preds = %19, %14
%24 = phi i32 [ 1, %14 ], [ 0, %19 ]
ret i32 %24
}