#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 */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int accept(int, struct sockaddr *, unsigned int *);
int read(int, char *, int);
int WaitForClient(int sfd, char *buffer) {
  int cfd, retval, addrlen;
  struct sockaddr_in addr;
  addrlen = sizeof(struct sockaddr_in);
  cfd = accept(sfd, (struct sockaddr *)&addr, (unsigned *)&addrlen);
  if (cfd >= 0) {
    retval = read(cfd, buffer, 512);
    retval = cfd;
  } else
    retval = cfd;
  return (retval);
}


x86 assembly (clang, -O0):
<WaitForClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     1172 <WaitForClient+0x52>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x200,%edx
call   1030 <read@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1178 <WaitForClient+0x58>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WaitForClient>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1040 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1155 <WaitForClient+0x35>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
call   1030 <read@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @WaitForClient(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
store i8* %1, i8** %4
store i32 4, i32* %7
%9 = load i32, i32* %3
%10 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %7)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* %5
%16 = load i8*, i8** %4
%17 = call i32 @read(i32 %15, i8* %16, i32 512)
store i32 %17, i32* %6
%18 = load i32, i32* %5
store i32 %18, i32* %6
br label %21
19: ; preds = %2
%20 = load i32, i32* %5
store i32 %20, i32* %6
br label %21
21: ; preds = %19, %14
%22 = load i32, i32* %6
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
define i32 @WaitForClient(i32 %0, i8* nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
store i32 4, i32* %3
%7 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %3)
%9 = icmp sgt i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @read(i32 %8, i8* %1, i32 512)
br label %12
12: ; preds = %2, %10
ret i32 %8
}