#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*/ cli_addr;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int connect_client(int sockfd) {
  int listenfd = 0, connfd = 0, newsockfd, clilen;
  struct sockaddr_in cli_addr;
  listen(sockfd, 5);
  clilen = sizeof(cli_addr);
  newsockfd = accept(sockfd, (struct sockaddr *)&cli_addr, &clilen);
  if (newsockfd < 0) {
    perror("ERROR on accept");
    return -1;
  }
  return newsockfd;
}


x86 assembly (clang, -O0):
<connect_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1030 <listen@plt>
movl   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1192 <connect_client+0x62>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <connect_client+0x68>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_client>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
mov    $0x5,%esi
call   1030 <listen@plt>
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1050 <accept@plt>
test   %eax,%eax
js     1164 <connect_client+0x34>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe95(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    115e <connect_client+0x2e>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"ERROR on accept\00"
define i32 @connect_client(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%9 = load i32, i32* %3
%10 = call i32 @listen(i32 %9, i32 5)
store i32 4, i32* %7
%11 = load i32, i32* %3
%12 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%13 = call i32 @accept(i32 %11, %struct.sockaddr* %12, i32* %7)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %20
18: ; preds = %1
%19 = load i32, i32* %6
store i32 %19, i32* %2
br label %20
20: ; preds = %18, %16
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [16 x i8] c"ERROR on accept\00"
define i32 @connect_client(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = tail call i32 @listen(i32 %0, i32 5)
store i32 4, i32* %2
%7 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %1, %10
%13 = phi i32 [ -1, %10 ], [ %8, %1 ]
ret i32 %13
}