#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 socklen_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EWOULDBLOCK;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int NI_MAXSERV;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int accept(int, struct sockaddr *, int *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int, int);
int make_socket_non_blocking(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *, char *);
int accept_new_client(int sfd) {
  struct sockaddr in_addr;
  socklen_t in_len;
  int infd, s;
  char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
  in_len = sizeof in_addr;
  infd = accept(sfd, &in_addr, &in_len);
  if (infd == -1) {
    if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
      return -1;
    } else
      do {
        perror("accept");
        return -1;
      } while (0);
  }
  s = getnameinfo(&in_addr, in_len, hbuf, sizeof hbuf, sbuf, sizeof sbuf,
                  NI_NUMERICHOST | NI_NUMERICSERV);
  if (s == 0) {
    printf("Accepted connection on descriptor %d "
           " ( host=%s, port=%s )\n",
           infd, hbuf, sbuf);
  }
  s = make_socket_non_blocking(infd);
  if (s == -1)
    do {
      perror("Could not make socket non-blocking\n");
      exit(EXIT_FAILURE);
    } while (0);
  return infd;
}


x86 assembly (clang, -O0):
<accept_new_client>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x60(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x4,-0x14(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1253 <accept_new_client+0xf3>
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    0x2da7(%rip),%rcx
cmp    (%rcx),%rax
je     121c <accept_new_client+0xbc>
mov    0x2dbf(%rip),%rax
mov    (%rax),%rax
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%rax
jne    122f <accept_new_client+0xcf>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12f4 <accept_new_client+0x194>
jmp    1234 <accept_new_client+0xd4>
lea    0xdc5(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    12f4 <accept_new_client+0x194>
mov    -0x48(%rbp),%r8
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rax
mov    -0x60(%rbp),%rcx
mov    -0x14(%rbp),%esi
mov    %eax,%r9d
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
mov    0x2d6f(%rip),%rdi
or     (%rdi),%eax
lea    -0x10(%rbp),%rdi
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    12b3 <accept_new_client+0x153>
mov    -0x48(%rbp),%rcx
mov    -0x58(%rbp),%rdx
mov    -0x18(%rbp),%esi
lea    0xd59(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1030 <make_socket_non_blocking@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12e7 <accept_new_client+0x187>
jmp    12cd <accept_new_client+0x16d>
lea    0xd6f(%rip),%rdi
call   1060 <perror@plt>
mov    0x2cd8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_new_client>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,-0x38(%rbp)
mov    0x2e34(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r12
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2e49(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x4,-0x2c(%rbp)
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   1070 <accept@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     123a <accept_new_client+0xda>
mov    -0x2c(%rbp),%esi
mov    0x2dff(%rip),%rdx
mov    0x2e10(%rip),%rcx
mov    (%rcx),%eax
or     (%rdx),%eax
sub    $0x8,%rsp
lea    -0x30(%rbp),%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %rbx,%r8
mov    %r13d,%r9d
push   %rax
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    1213 <accept_new_client+0xb3>
lea    0xe02(%rip),%rdi
mov    %r14d,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1040 <printf@plt>
mov    %r14d,%edi
call   1030 <make_socket_non_blocking@plt>
cmp    $0xffffffff,%eax
jne    125c <accept_new_client+0xfc>
lea    0xe1c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%rax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%rax
je     125c <accept_new_client+0xfc>
mov    0x2d69(%rip),%rcx
cmp    (%rcx),%rax
jne    1272 <accept_new_client+0x112>
mov    -0x38(%rbp),%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd87(%rip),%rdi
call   1060 <perror@plt>
jmp    125c <accept_new_client+0xfc>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.1 = [60 x i8] c"Accepted connection on descriptor %d ( host=%s, port=%s )\0A\00"
@.str.2 = [36 x i8] c"Could not make socket non-blocking\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @accept_new_client(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32 %0, i32* %3
%12 = load i32, i32* @NI_MAXHOST
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* @NI_MAXSERV
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
store i64 %17, i64* %10
store i32 4, i32* %5
%19 = load i32, i32* %3
%20 = call i32 @accept(i32 %19, %struct.sockaddr* %4, i32* %5)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %38
23: ; preds = %1
%24 = load i64, i64* @errno
%25 = load i64, i64* @EAGAIN
%26 = icmp eq i64 %24, %25
br i1 %26, label %31, label %27
27: ; preds = %23
%28 = load i64, i64* @errno
%29 = load i64, i64* @EWOULDBLOCK
%30 = icmp eq i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %27, %23
store i32 -1, i32* %2
store i32 1, i32* %11
br label %65
32: ; preds = %27
br label %33
33: ; preds = %32
%34 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
store i32 1, i32* %11
br label %65
35: ; No predecessors!
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37, %1
%39 = load i32, i32* %5
%40 = trunc i64 %13 to i32
%41 = trunc i64 %17 to i32
%42 = load i32, i32* @NI_NUMERICHOST
%43 = load i32, i32* @NI_NUMERICSERV
%44 = or i32 %42, %43
%45 = call i32 @getnameinfo(%struct.sockaddr* %4, i32 %39, i8* %15, i32 %40, i8* %18, i32 %41, i32 %44)
store i32 %45, i32* %7
%46 = load i32, i32* %7
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %38
%49 = load i32, i32* %6
%50 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %49, i8* %15, i8* %18)
br label %51
51: ; preds = %48, %38
%52 = load i32, i32* %6
%53 = call i32 @make_socket_non_blocking(i32 %52)
store i32 %53, i32* %7
%54 = load i32, i32* %7
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %63
56: ; preds = %51
br label %57
57: ; preds = %56
%58 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; No predecessors!
br label %62
62: ; preds = %61
br label %63
63: ; preds = %62, %51
%64 = load i32, i32* %6
store i32 %64, i32* %2
store i32 1, i32* %11
br label %65
65: ; preds = %63, %33, %31
%66 = load i8*, i8** %8
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.1 = [60 x i8] c"Accepted connection on descriptor %d ( host=%s, port=%s )\0A\00"
@.str.2 = [36 x i8] c"Could not make socket non-blocking\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @accept_new_client(i32 %0) {
%2 = alloca %struct.sockaddr
%3 = alloca i32
%4 = bitcast %struct.sockaddr* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @NI_MAXHOST
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = load i32, i32* @NI_MAXSERV
%11 = zext i32 %10 to i64
%12 = alloca i8, i64 %11
store i32 4, i32* %3
%13 = call i32 @accept(i32 %0, %struct.sockaddr* %2, i32* %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %24
15: ; preds = %1
%16 = load i64, i64* @errno
%17 = load i64, i64* @EAGAIN
%18 = icmp eq i64 %16, %17
%19 = load i64, i64* @EWOULDBLOCK
%20 = icmp eq i64 %16, %19
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %40, label %22
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %40
24: ; preds = %1
%25 = load i32, i32* %3
%26 = load i32, i32* @NI_NUMERICHOST
%27 = load i32, i32* @NI_NUMERICSERV
%28 = or i32 %27, %26
%29 = call i32 @getnameinfo(%struct.sockaddr* %2, i32 %25, i8* %9, i32 %6, i8* %12, i32 %10, i32 %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.1, i64 0, i64 0), i32 %13, i8* %9, i8* %12)
br label %33
33: ; preds = %31, %24
%34 = call i32 @make_socket_non_blocking(i32 %13)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %33, %15, %22
ret i32 %13
}