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

/* Variables and functions */
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int waitConexion(int serverSock, int *psockConnection) {
  struct sockaddr_in cAddr;
  socklen_t sockLen;
  char str[30];
  sockLen = sizeof(cAddr);
  if ((*psockConnection =
           accept(serverSock, (struct sockaddr *)&cAddr, &sockLen)) == -1)
    return -1;
  printf("I have been connected from:\n");
  strcpy(str, inet_ntoa(cAddr.sin_addr));
  printf("\tIP address: %s\n", str);
  printf("\tport: %u\n", (unsigned int)cAddr.sin_port);
  return 0;
}


x86 assembly (clang, -O0):
<waitConexion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x10,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x24(%rbp),%rdx
call   1060 <accept@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    1181 <waitConexion+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <waitConexion+0x97>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    -0x58(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x50(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitConexion>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
movl   $0x10,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1070 <accept@plt>
mov    %eax,(%rbx)
cmp    $0xffffffff,%eax
je     11c3 <waitConexion+0x73>
lea    0xe9d(%rip),%rdi
call   1040 <puts@plt>
mov    0x18(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    0xe5d(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%esi
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11c8 <waitConexion+0x78>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i64, i32 }
%struct.sockaddr = type { i32 }
@.str = [29 x i8] c"I have been connected from:\0A\00"
@.str.1 = [17 x i8] c"\09IP address: %s\0A\00"
@.str.2 = [11 x i8] c"\09port: %u\0A\00"
define i32 @waitConexion(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca [30 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32 16, i32* %7
%9 = load i32, i32* %4
%10 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%11 = call i32 @accept(i32 %9, %struct.sockaddr* %10, i32* %7)
%12 = load i32*, i32** %5
store i32 %11, i32* %12
%13 = icmp eq i32 %11, -1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %28
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%19 = load i32, i32* %18
%20 = call i32 @inet_ntoa(i32 %19)
%21 = call i32 @strcpy(i8* %17, i32 %20)
%22 = getelementptr inbounds [30 x i8], [30 x i8]* %8, i64 0, i64 0
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%25 = load i64, i64* %24
%26 = trunc i64 %25 to i32
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %26)
store i32 0, i32* %3
br label %28
28: ; preds = %15, %14
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i64, i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [17 x i8] c"\09IP address: %s\0A\00"
@.str.2 = [11 x i8] c"\09port: %u\0A\00"
@str = [28 x i8] c"I have been connected from:\00"
define i32 @waitConexion(i32 %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [30 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
store i32 16, i32* %4
%9 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%10 = call i32 @accept(i32 %0, %struct.sockaddr* %9, i32* %4)
store i32 %10, i32* %1
%11 = icmp eq i32 %10, -1
br i1 %11, label %23, label %12
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%15 = load i32, i32* %14
%16 = call i32 @inet_ntoa(i32 %15)
%17 = call i32 @strcpy(i8* %8, i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %2, %12
%24 = phi i32 [ 0, %12 ], [ -1, %2 ]
ret i32 %24
}