#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 /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ exit(int);
char *gettext(char *);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int connection_accept(fd_set *master, int *fdmax, int sockfd,
                      struct sockaddr_in *client_addr) {
  socklen_t addrlen;
  int newsockfd;
  addrlen = sizeof(struct sockaddr_in);
  if ((newsockfd = accept(sockfd, (struct sockaddr *)client_addr, &addrlen)) ==
      -1) {
    perror(gettext("Aceptar"));
    exit(1);
  } else {
    FD_SET(newsockfd, master);
    if (newsockfd > *fdmax) {
      *fdmax = newsockfd;
    }
    printf(gettext("Nueva conexión de %s en el puerto %d \n"),
           inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port));
    return newsockfd;
  }
}


x86 assembly (clang, -O0):
<connection_accept>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x8,-0x24(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1080 <accept@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xffffffff,%eax
jne    11d8 <connection_accept+0x58>
lea    0xe3f(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   10a0 <FD_SET@plt>
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jle    11fc <connection_accept+0x7c>
mov    -0x28(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
lea    0xe05(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1050 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connection_accept>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%eax
mov    %rsi,%r14
mov    %rdi,%r15
movl   $0x8,0x4(%rsp)
lea    0x4(%rsp),%rdx
mov    %eax,%edi
mov    %rcx,%rsi
call   1080 <accept@plt>
cmp    $0xffffffff,%eax
je     11fd <connection_accept+0x7d>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r15,%rsi
call   10a0 <FD_SET@plt>
cmp    (%r14),%ebp
jle    11c2 <connection_accept+0x42>
mov    %ebp,(%r14)
lea    0xe3f(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%r14
mov    0x4(%rbx),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r15
mov    (%rbx),%edi
call   1060 <ntohs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <printf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdfc(%rip),%rdi
call   1040 <gettext@plt>
mov    %rax,%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"Aceptar\00"
@.str.1 = [40 x i8] c"Nueva conexi\C3\B3n de %s en el puerto %d \0A\00"
define i32 @connection_accept(i32* %0, i32* %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
store i32 8, i32* %9
%11 = load i32, i32* %7
%12 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%13 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%14 = call i32 @accept(i32 %11, %struct.sockaddr* %13, i32* %9)
store i32 %14, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %20
16: ; preds = %4
%17 = call i8* @gettext(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @perror(i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = load i32, i32* %10
%22 = load i32*, i32** %5
%23 = call i32 @FD_SET(i32 %21, i32* %22)
%24 = load i32, i32* %10
%25 = load i32*, i32** %6
%26 = load i32, i32* %25
%27 = icmp sgt i32 %24, %26
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = load i32, i32* %10
%30 = load i32*, i32** %6
store i32 %29, i32* %30
br label %31
31: ; preds = %28, %20
%32 = call i8* @gettext(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%33 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i8* @inet_ntoa(i32 %35)
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @ntohs(i32 %39)
%41 = call i32 @printf(i8* %32, i8* %36, i32 %40)
%42 = load i32, i32* %10
ret i32 %42
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"Aceptar\00"
@.str.1 = [40 x i8] c"Nueva conexi\C3\B3n de %s en el puerto %d \0A\00"
define i32 @connection_accept(i32* %0, i32* nocapture %1, i32 %2, %struct.sockaddr_in* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 8, i32* %5
%7 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%8 = call i32 @accept(i32 %2, %struct.sockaddr* %7, i32* %5)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %4
%11 = call i8* @gettext(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @perror(i8* %11)
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = call i32 @FD_SET(i32 %8, i32* %0)
%16 = load i32, i32* %1
%17 = icmp sgt i32 %8, %16
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 %8, i32* %1
br label %19
19: ; preds = %18, %14
%20 = call i8* @gettext(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%22 = load i32, i32* %21
%23 = call i8* @inet_ntoa(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @ntohs(i32 %25)
%27 = call i32 @printf(i8* %20, i8* %23, i32 %26)
ret i32 %8
}