#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 {
  int dummy;
};
typedef int /*<<< orphan*/ clientAddr;

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int accept_connection(int sockid) {
  int s, addrLen;
  struct sockaddr clientAddr;
  addrLen = sizeof(clientAddr);
  s = accept(sockid, &clientAddr, &addrLen);
  if (s == -1) {
    fprintf(stderr, "Error: cannot accept new connections.\n");
    return -1;
  }
  fprintf(stderr, "Accepted a new connection.\n");
  return s;
}


x86 assembly (clang, -O0):
<accept_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1170 <accept_connection+0x50>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <accept_connection+0x6b>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_connection>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1040 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
lea    0xeaf(%rip),%rax
lea    0xecf(%rip),%rsi
cmove  %rax,%rsi
call   1030 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Error: cannot accept new connections.\0A\00"
@.str.1 = [28 x i8] c"Accepted a new connection.\0A\00"
define i32 @accept_connection(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr
store i32 %0, i32* %3
store i32 4, i32* %5
%7 = load i32, i32* %3
%8 = call i32 @accept(i32 %7, %struct.sockaddr* %6, i32* %5)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %4
store i32 %17, i32* %2
br label %18
18: ; preds = %14, %11
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Error: cannot accept new connections.\0A\00"
@.str.1 = [28 x i8] c"Accepted a new connection.\0A\00"
define i32 @accept_connection(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sockaddr* %3 to i8*
store i32 4, i32* %2
%6 = call i32 @accept(i32 %0, %struct.sockaddr* %3, i32* %2)
%7 = icmp eq i32 %6, -1
%8 = load i32, i32* @stderr
%9 = select i1 %7, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0)
%10 = call i32 @fprintf(i32 %8, i8* %9)
ret i32 %6
}