#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 /*<<< orphan*/ Die(char *);
int /*<<< orphan*/ close(int);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int, int /*<<< orphan*/);
void HandleClient(int sock) {
  char buffer[32];
  int received = -1;
  if ((received = recv(sock, buffer, 32, 0)) < 0) {
    Die("Failed to receive initial bytes from client");
  }
  while (received > 0) {
    if (send(sock, buffer, received, 0) != received) {
      Die("Failed to send bytes to client");
    }
    if ((received = recv(sock, buffer, 32, 0)) < 0) {
      Die("Failed to receive additional bytes from client");
    }
  }
  close(sock);
}


x86 assembly (clang, -O0):
<HandleClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x34(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    117d <HandleClient+0x3d>
lea    0xe88(%rip),%rdi
call   1060 <Die@plt>
jmp    1182 <HandleClient+0x42>
cmpl   $0x0,-0x34(%rbp)
jle    11e2 <HandleClient+0xa2>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    -0x34(%rbp),%eax
je     11b2 <HandleClient+0x72>
lea    0xe7f(%rip),%rdi
call   1060 <Die@plt>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x34(%rbp)
cmp    $0x0,%eax
jge    11dd <HandleClient+0x9d>
lea    0xe73(%rip),%rdi
call   1060 <Die@plt>
jmp    1182 <HandleClient+0x42>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HandleClient>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    %rsp,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11b5 <HandleClient+0x75>
je     11c4 <HandleClient+0x84>
mov    %eax,%ebp
mov    %rsp,%r15
lea    0xedc(%rip),%r14
lea    0xeb6(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    %ebp,%eax
je     119a <HandleClient+0x5a>
mov    %r12,%rdi
call   1060 <Die@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
js     11bc <HandleClient+0x7c>
mov    %eax,%ebp
jne    1180 <HandleClient+0x40>
jmp    11c4 <HandleClient+0x84>
lea    0xe44(%rip),%r14
mov    %r14,%rdi
call   1060 <Die@plt>
mov    %ebx,%edi
call   1050 <close@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [44 x i8] c"Failed to receive initial bytes from client\00"
@.str.1 = [31 x i8] c"Failed to send bytes to client\00"
@.str.2 = [47 x i8] c"Failed to receive additional bytes from client\00"
define void @HandleClient(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i8]
%4 = alloca i32
store i32 %0, i32* %2
store i32 -1, i32* %4
%5 = load i32, i32* %2
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = call i32 @recv(i32 %5, i8* %6, i32 32, i32 0)
store i32 %7, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @Die(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %1
br label %12
12: ; preds = %31, %11
%13 = load i32, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %32
15: ; preds = %12
%16 = load i32, i32* %2
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%18 = load i32, i32* %4
%19 = call i32 @send(i32 %16, i8* %17, i32 %18, i32 0)
%20 = load i32, i32* %4
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %15
%23 = call i32 @Die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %15
%25 = load i32, i32* %2
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%27 = call i32 @recv(i32 %25, i8* %26, i32 32, i32 0)
store i32 %27, i32* %4
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @Die(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
br label %12
32: ; preds = %12
%33 = load i32, i32* %2
%34 = call i32 @close(i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [44 x i8] c"Failed to receive initial bytes from client\00"
@.str.1 = [31 x i8] c"Failed to send bytes to client\00"
@.str.2 = [47 x i8] c"Failed to receive additional bytes from client\00"
define void @HandleClient(i32 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @recv(i32 %0, i8* %3, i32 32, i32 0)
%5 = icmp slt i32 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %1
%7 = icmp eq i32 %4, 0
br i1 %7, label %22, label %8
8: ; preds = %6, %17
%9 = phi i32 [ %15, %17 ], [ %4, %6 ]
%10 = call i32 @send(i32 %0, i8* %3, i32 %9, i32 0)
%11 = icmp eq i32 %10, %9
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = call i32 @Die(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = call i32 @recv(i32 %0, i8* %3, i32 32, i32 0)
%16 = icmp slt i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = icmp eq i32 %15, 0
br i1 %18, label %22, label %8
19: ; preds = %14, %1
%20 = phi i8* [ getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), %14 ]
%21 = call i32 @Die(i8* %20)
br label %22
22: ; preds = %17, %19, %6
%23 = call i32 @close(i32 %0)
ret void
}