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

/* Variables and functions */
int /*<<< orphan*/ FIONBIO;
int accept(unsigned int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int /*<<< orphan*/ perror(char *);
unsigned _sys_accept(unsigned sock) {
  int new_sock = accept(sock, NULL, NULL), one = 1;
  if (new_sock == -1) {
    perror("accept");
    exit(1);
  }
  if (ioctl(new_sock, FIONBIO, &one)) {
    perror("ioctl");
    exit(1);
  }
  return new_sock;
}


x86 assembly (clang, -O0):
<_sys_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1050 <accept@plt>
mov    %eax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1184 <_sys_accept+0x44>
lea    0xe8b(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     11b9 <_sys_accept+0x79>
lea    0xe5d(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sys_accept>:
push   %rbx
sub    $0x10,%rsp
xor    %esi,%esi
xor    %edx,%edx
call   1050 <accept@plt>
movl   $0x1,0xc(%rsp)
cmp    $0xffffffff,%eax
je     117f <_sys_accept+0x3f>
mov    %eax,%ebx
mov    0x2e7c(%rip),%rax
mov    (%rax),%esi
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
jne    1188 <_sys_accept+0x48>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7a(%rip),%rdi
jmp    118f <_sys_accept+0x4f>
lea    0xe78(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"accept\00"
@FIONBIO = global i32 0
@.str.1 = [6 x i8] c"ioctl\00"
define i32 @_sys_accept(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @accept(i32 %5, i32* null, i32* null)
store i32 %6, i32* %3
store i32 1, i32* %4
%7 = load i32, i32* %3
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %1
%13 = load i32, i32* %3
%14 = load i32, i32* @FIONBIO
%15 = call i64 @ioctl(i32 %13, i32 %14, i32* %4)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [7 x i8] c"accept\00"
@FIONBIO = global i32 0
@.str.1 = [6 x i8] c"ioctl\00"
define i32 @_sys_accept(i32 %0) {
%2 = alloca i32
%3 = tail call i32 @accept(i32 %0, i32* null, i32* null)
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = icmp eq i32 %3, -1
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %1
%10 = load i32, i32* @FIONBIO
%11 = call i64 @ioctl(i32 %3, i32 %10, i32* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %9
ret i32 %3
}