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

/* Variables and functions */
int accept(int, struct sockaddr_in *, int *);
int /*<<< orphan*/ getsockname(int, struct sockaddr_in *, int *);
int /*<<< orphan*/ nonblock(int);
int /*<<< orphan*/ perror(char *);
int new_connection(int s) {
  struct sockaddr_in isa;
  int i;
  int t;
  char buf[100];
  i = sizeof(isa);
  getsockname(s, &isa, &i);
  if ((t = accept(s, &isa, &i)) < 0) {
    perror("Accept");
    return (-1);
  }
  nonblock(t);
  return (t);
}


x86 assembly (clang, -O0):
<new_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <getsockname@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1199 <new_connection+0x59>
lea    0xe78(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <new_connection+0x67>
mov    -0x18(%rbp),%edi
call   1030 <nonblock@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_connection>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%r14
lea    0x4(%rsp),%r15
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <getsockname@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1050 <accept@plt>
test   %eax,%eax
js     118e <new_connection+0x4e>
mov    %eax,%ebx
mov    %eax,%edi
call   1030 <nonblock@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6b(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1182 <new_connection+0x42>

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

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