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

/* Variables and functions */
int /*<<< orphan*/ FIONBIO;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int accept_conn(int fd) {
  int on = 1;
  int new_fd;
  struct sockaddr_in from;
  socklen_t fromlen = sizeof(from);
  new_fd = accept(fd, (struct sockaddr *)&from, &fromlen);
  if (new_fd < 0)
    perror("accept");
  ioctl(new_fd, FIONBIO, &on);
  fprintf(stderr, "Accepted connection on %d\n", new_fd);
  return new_fd;
}


x86 assembly (clang, -O0):
<accept_conn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1182 <accept_conn+0x42>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    -0xc(%rbp),%edi
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    -0x8(%rbp),%rdx
call   1030 <ioctl@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_conn>:
push   %rbx
sub    $0x10,%rsp
movl   $0x1,0x4(%rsp)
movl   $0x4,(%rsp)
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
js     119b <accept_conn+0x5b>
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    %ebx,%edx
call   1040 <fprintf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe5e(%rip),%rdi
call   1050 <perror@plt>
jmp    1167 <accept_conn+0x27>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@FIONBIO = global i32 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Accepted connection on %d\0A\00"
define i32 @accept_conn(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%8 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%9 = call i32 @accept(i32 %0, %struct.sockaddr* %8, i32* %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i32, i32* @FIONBIO
%15 = call i32 @ioctl(i32 %9, i32 %14, i32* %2)
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %9)
ret i32 %9
}