#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 /*<<< orphan*/ remoteaddr;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int new_connection(int fd, fd_set *master_fds) {
  int newfd, addrlen;
  struct sockaddr_in remoteaddr;
  addrlen = sizeof(remoteaddr);
  if ((newfd = accept(fd, (struct sockaddr *)&remoteaddr, &addrlen)) == -1) {
    perror("Server: accept");
    return -1;
  }
  FD_SET(newfd, master_fds);
  printf("Server(%d): New connection\n", newfd);
  return newfd;
}


x86 assembly (clang, -O0):
<new_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1050 <accept@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    118a <new_connection+0x4a>
lea    0xe87(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <new_connection+0x6b>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x14(%rbp),%esi
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_connection>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
movl   $0x4,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     118a <new_connection+0x4a>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
lea    0xe96(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6f(%rip),%rdi
call   1040 <perror@plt>
jmp    1180 <new_connection+0x40>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"Server: accept\00"
@.str.1 = [28 x i8] c"Server(%d): New connection\0A\00"
define i32 @new_connection(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 4, i32* %7
%9 = load i32, i32* %4
%10 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %7)
store i32 %11, i32* %6
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %22
15: ; preds = %2
%16 = load i32, i32* %6
%17 = load i32*, i32** %5
%18 = call i32 @FD_SET(i32 %16, i32* %17)
%19 = load i32, i32* %6
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%21 = load i32, i32* %6
store i32 %21, i32* %3
br label %22
22: ; preds = %15, %13
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [15 x i8] c"Server: accept\00"
@.str.1 = [28 x i8] c"Server(%d): New connection\0A\00"
define i32 @new_connection(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.sockaddr_in* %4 to i8*
store i32 4, i32* %3
%7 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%8 = call i32 @accept(i32 %0, %struct.sockaddr* %7, i32* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %15
12: ; preds = %2
%13 = call i32 @FD_SET(i32 %8, i32* %1)
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %15
15: ; preds = %12, %10
ret i32 %8
}