#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;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ clieAddr;

/* Variables and functions */
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int connectClient(int mainSocket) {
  int clieLen, incomingConn;
  struct sockaddr_in clieAddr;
  clieLen = sizeof(clieAddr);
  incomingConn =
      accept(mainSocket, (struct sockaddr *)&clieAddr, (socklen_t *)&clieLen);
  if (incomingConn < 0) {
    return -1;
  }
  printf("Got incoming Connection with ID: %d\n", incomingConn);
  return incomingConn;
}


x86 assembly (clang, -O0):
<connectClient>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    115b <connectClient+0x3b>
movl   $0xffffffff,-0x4(%rbp)
jmp    1170 <connectClient+0x50>
mov    -0x10(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connectClient>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1040 <accept@plt>
test   %eax,%eax
js     1152 <connectClient+0x32>
mov    %eax,%ebx
lea    0xeb7(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
jmp    1157 <connectClient+0x37>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [37 x i8] c"Got incoming Connection with ID: %d\0A\00"
define i32 @connectClient(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
store i32 4, i32* %4
%7 = load i32, i32* %3
%8 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%9 = call i32 @accept(i32 %7, %struct.sockaddr* %8, i32* %4)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %17
13: ; preds = %1
%14 = load i32, i32* %5
%15 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %5
store i32 %16, i32* %2
br label %17
17: ; preds = %13, %12
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [37 x i8] c"Got incoming Connection with ID: %d\0A\00"
define i32 @connectClient(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sockaddr_in* %3 to i8*
store i32 4, i32* %2
%6 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%7 = call i32 @accept(i32 %0, %struct.sockaddr* %6, i32* %2)
%8 = icmp slt i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %11
11: ; preds = %1, %9
%12 = phi i32 [ %7, %9 ], [ -1, %1 ]
ret i32 %12
}