#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*/ printf(char *, ...);
int recv(int, char **, int, int /*<<< orphan*/);
void server_conn(int socketfd) {
  printf("Client connected\n");
  char buf[100];
  int len;
  while (len = recv(socketfd, &buf, 100, 0), len > 0) {
    if (len == -1) {
      printf("Client dropped off\n");
      break;
    }
    printf("Received message |%s|\n", buf);
  }
  printf("Closing socket\n");
}


x86 assembly (clang, -O0):
<server_conn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
jle    1190 <server_conn+0x70>
cmpl   $0xffffffff,-0x74(%rbp)
jne    1179 <server_conn+0x59>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1190 <server_conn+0x70>
lea    -0x70(%rbp),%rsi
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    113c <server_conn+0x1c>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_conn>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
mov    %edi,%ebp
lea    0xed6(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1192 <server_conn+0x62>
lea    0xe9e(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     1170 <server_conn+0x40>
lea    0xe8f(%rip),%rdi
call   1040 <puts@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Client connected\0A\00"
@.str.1 = [20 x i8] c"Client dropped off\0A\00"
@.str.2 = [23 x i8] c"Received message |%s|\0A\00"
@.str.3 = [16 x i8] c"Closing socket\0A\00"
define void @server_conn(i32 %0) {
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %17, %1
%7 = load i32, i32* %2
%8 = bitcast [100 x i8]* %3 to i8**
%9 = call i32 @recv(i32 %7, i8** %8, i32 100, i32 0)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %6
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %20
17: ; preds = %12
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %18)
br label %6
20: ; preds = %15, %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.2 = [23 x i8] c"Received message |%s|\0A\00"
@str = [17 x i8] c"Client connected\00"
@str.4 = [15 x i8] c"Closing socket\00"
define void @server_conn(i32 %0) {
%2 = alloca [100 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = bitcast [100 x i8]* %2 to i8**
%6 = call i32 @recv(i32 %0, i8** %5, i32 100, i32 0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1, %8
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%10 = call i32 @recv(i32 %0, i8** %5, i32 100, i32 0)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %8, label %12
12: ; preds = %8, %1
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
ret void
}