#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*/ uint8_t;
struct initialPacket {
  int dummy;
};
struct SXConnection {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ MSG_WAITALL;
scalar_t__ loopWrite(int, int /*<<< orphan*/ *, int);
scalar_t__ memcmp(char *, char *, int);
int /*<<< orphan*/ prepareInitialPacket(struct initialPacket *,
                                        struct SXConnection *);
int recv(int, char *, int, int /*<<< orphan*/);
int connectionInit(int sock, struct SXConnection *conn) {
  char sendBuf[1292];
  char recvBuf[1292];
  prepareInitialPacket((struct initialPacket *)sendBuf, conn);
  if (loopWrite(sock, (uint8_t *)sendBuf, 1292) < 0)
    return -1;
  if (recv(sock, recvBuf, 1292, MSG_WAITALL) != 1292)
    return -2;
  if (0 != memcmp(sendBuf, recvBuf, 1292))
    return -3;
  return 0;
}


x86 assembly (clang, -O0):
<connectionInit>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x520(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <prepareInitialPacket@plt>
mov    -0x8(%rbp),%edi
lea    -0x520(%rbp),%rsi
mov    $0x50c,%edx
call   1060 <loopWrite@plt>
cmp    $0x0,%rax
jge    118c <connectionInit+0x4c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <connectionInit+0xb9>
mov    -0x8(%rbp),%edi
lea    -0xa30(%rbp),%rsi
mov    0x2e3b(%rip),%rax
mov    (%rax),%ecx
mov    $0x50c,%edx
call   1030 <recv@plt>
cmp    $0x50c,%eax
je     11c0 <connectionInit+0x80>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11f9 <connectionInit+0xb9>
lea    -0x520(%rbp),%rdi
lea    -0xa30(%rbp),%rsi
mov    $0x50c,%edx
call   1040 <memcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11f2 <connectionInit+0xb2>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11f9 <connectionInit+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connectionInit>:
push   %r14
push   %rbx
sub    $0xa28,%rsp
mov    %edi,%ebx
lea    0x510(%rsp),%r14
mov    %r14,%rdi
call   1050 <prepareInitialPacket@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x50c,%edx
call   1060 <loopWrite@plt>
test   %rax,%rax
js     11bc <connectionInit+0x7c>
mov    0x2e61(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x50c,%edx
call   1030 <recv@plt>
mov    %eax,%ecx
mov    $0xfffffffe,%eax
cmp    $0x50c,%ecx
jne    11c1 <connectionInit+0x81>
lea    0x510(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x50c,%edx
call   1040 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,2),%eax
add    $0xfffffffd,%eax
jmp    11c1 <connectionInit+0x81>
mov    $0xffffffff,%eax
add    $0xa28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.SXConnection = type { i32 }
%struct.initialPacket = type { i32 }
@MSG_WAITALL = global i32 0
define i32 @connectionInit(i32 %0, %struct.SXConnection* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.SXConnection*
%6 = alloca [1292 x i8]
%7 = alloca [1292 x i8]
store i32 %0, i32* %4
store %struct.SXConnection* %1, %struct.SXConnection** %5
%8 = getelementptr inbounds [1292 x i8], [1292 x i8]* %6, i64 0, i64 0
%9 = bitcast i8* %8 to %struct.initialPacket*
%10 = load %struct.SXConnection*, %struct.SXConnection** %5
%11 = call i32 @prepareInitialPacket(%struct.initialPacket* %9, %struct.SXConnection* %10)
%12 = load i32, i32* %4
%13 = getelementptr inbounds [1292 x i8], [1292 x i8]* %6, i64 0, i64 0
%14 = bitcast i8* %13 to i32*
%15 = call i64 @loopWrite(i32 %12, i32* %14, i32 1292)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 -1, i32* %3
br label %32
18: ; preds = %2
%19 = load i32, i32* %4
%20 = getelementptr inbounds [1292 x i8], [1292 x i8]* %7, i64 0, i64 0
%21 = load i32, i32* @MSG_WAITALL
%22 = call i32 @recv(i32 %19, i8* %20, i32 1292, i32 %21)
%23 = icmp ne i32 %22, 1292
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 -2, i32* %3
br label %32
25: ; preds = %18
%26 = getelementptr inbounds [1292 x i8], [1292 x i8]* %6, i64 0, i64 0
%27 = getelementptr inbounds [1292 x i8], [1292 x i8]* %7, i64 0, i64 0
%28 = call i64 @memcmp(i8* %26, i8* %27, i32 1292)
%29 = icmp ne i64 0, %28
br i1 %29, label %30, label %31
30: ; preds = %25
store i32 -3, i32* %3
br label %32
31: ; preds = %25
store i32 0, i32* %3
br label %32
32: ; preds = %31, %30, %24, %17
%33 = load i32, i32* %3
ret i32 %33
}

LLVM IR (-O2):
%struct.SXConnection = type { i32 }
%struct.initialPacket = type { i32 }
@MSG_WAITALL = global i32 0
define i32 @connectionInit(i32 %0, %struct.SXConnection* %1) {
%3 = alloca [1292 x i8]
%4 = alloca [1292 x i8]
%5 = getelementptr inbounds [1292 x i8], [1292 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1292 x i8], [1292 x i8]* %4, i64 0, i64 0
%7 = bitcast [1292 x i8]* %3 to %struct.initialPacket*
%8 = call i32 @prepareInitialPacket(%struct.initialPacket* %7, %struct.SXConnection* %1)
%9 = bitcast [1292 x i8]* %3 to i32*
%10 = call i64 @loopWrite(i32 %0, i32* %9, i32 1292)
%11 = icmp slt i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %2
%13 = load i32, i32* @MSG_WAITALL
%14 = call i32 @recv(i32 %0, i8* %6, i32 1292, i32 %13)
%15 = icmp eq i32 %14, 1292
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = call i64 @memcmp(i8* %5, i8* %6, i32 1292)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i32 0, i32 -3
br label %20
20: ; preds = %16, %12, %2
%21 = phi i32 [ -1, %2 ], [ -2, %12 ], [ %19, %16 ]
ret i32 %21
}