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

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ imprime_extremo_conexion(struct sockaddr *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int acepta_cliente(int s_escucha) {
  struct sockaddr dir_cliente;
  socklen_t len_dir = sizeof(dir_cliente);
  int s_nuevo;
  s_nuevo = accept(s_escucha, &dir_cliente, &len_dir);
  if (s_nuevo < 0)
    perror("accept");
  else {
    printf("Nueva conexion: ");
    imprime_extremo_conexion(&dir_cliente, len_dir, 1);
    printf("\n");
  }
  return s_nuevo;
}


x86 assembly (clang, -O0):
<acepta_cliente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
call   1060 <accept@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1180 <acepta_cliente+0x40>
lea    0xe8a(%rip),%rdi
call   1050 <perror@plt>
jmp    11a9 <acepta_cliente+0x69>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    -0x8(%rbp),%rdi
mov    $0x1,%edx
call   1030 <imprime_extremo_conexion@plt>
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<acepta_cliente>:
push   %rbx
sub    $0x10,%rsp
movl   $0x4,0x4(%rsp)
lea    0x8(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   1070 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11a3 <acepta_cliente+0x53>
lea    0xe8e(%rip),%rdi
call   1050 <printf@plt>
mov    0x4(%rsp),%esi
lea    0x8(%rsp),%rdi
mov    $0x1,%edx
call   1030 <imprime_extremo_conexion@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe56(%rip),%rdi
call   1060 <perror@plt>
jmp    119b <acepta_cliente+0x4b>

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@.str.1 = [17 x i8] c"Nueva conexion: \00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @acepta_cliente(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 4, i32* %4
%6 = load i32, i32* %2
%7 = call i32 @accept(i32 %6, %struct.sockaddr* %3, i32* %4)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = call i32 @imprime_extremo_conexion(%struct.sockaddr* %3, i32 %14, i32 1)
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %17
17: ; preds = %12, %10
%18 = load i32, i32* %5
ret i32 %18
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [7 x i8] c"accept\00"
@.str.1 = [17 x i8] c"Nueva conexion: \00"
define i32 @acepta_cliente(i32 %0) {
%2 = alloca %struct.sockaddr
%3 = alloca i32
%4 = bitcast %struct.sockaddr* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%6 = call i32 @accept(i32 %0, %struct.sockaddr* %2, i32* %3)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
10: ; preds = %1
%11 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* %3
%13 = call i32 @imprime_extremo_conexion(%struct.sockaddr* %2, i32 %12, i32 1)
%14 = call i32 @putchar(i32 10)
br label %15
15: ; preds = %10, %8
ret i32 %6
}