#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *, int, int);
int /*<<< orphan*/ read(int, int **, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int openConnection(const char *host, int *id, int *nplayers, int *b) {
  struct hostent *server;
  struct sockaddr_in serv_addr;
  int t[3];
  int sock;
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("opening socket");
    exit(1);
  };
  server = gethostbyname(host);
  if (server == NULL) {
    perror("no such host");
    exit(1);
  };
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(2048);
  if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    perror("connecting");
    exit(1);
  };
  read(sock, &t, sizeof(int) * 3);
  *id = t[1];
  *nplayers = t[0];
  *b = t[2];
  printf("connecté au serveur %s, joueur %d/%d\n", host, *id, *nplayers);
  return sock;
}


x86 assembly (clang, -O0):
<openConnection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jge    11e4 <openConnection+0x54>
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1212 <openConnection+0x82>
lea    0xe0c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x38(%rbp),%rsi
add    $0x4,%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1070 <bcopy@plt>
mov    $0x800,%edi
call   1030 <htons@plt>
mov    %eax,-0x38(%rbp)
mov    -0x48(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    1277 <openConnection+0xe7>
lea    0xdb4(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x48(%rbp),%edi
lea    -0x44(%rbp),%rsi
mov    $0xc,%edx
call   1050 <read@plt>
mov    -0x40(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x44(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
lea    0xd6d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x48(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openConnection>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e37(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     1265 <openConnection+0xd5>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     126e <openConnection+0xde>
mov    0x0(%r13),%ecx
mov    %ecx,0x8(%rsp)
mov    0x8(%rax),%rsi
lea    0x4(%rsp),%rdi
mov    (%rax),%edx
call   1070 <memmove@plt>
mov    $0x800,%edi
call   1030 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     1277 <openConnection+0xe7>
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1050 <read@plt>
mov    0x10(%rsp),%eax
mov    %eax,(%rbx)
mov    0xc(%rsp),%eax
mov    %eax,(%r12)
mov    0x14(%rsp),%eax
mov    %eax,(%r15)
mov    (%rbx),%edx
mov    (%r12),%ecx
lea    0xddb(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd94(%rip),%rdi
jmp    127e <openConnection+0xee>
lea    0xd9a(%rip),%rdi
jmp    127e <openConnection+0xee>
lea    0xd9e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i64 }
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"opening socket\00"
@.str.1 = [13 x i8] c"no such host\00"
@.str.2 = [11 x i8] c"connecting\00"
@.str.3 = [39 x i8] c"connect\C3\A9 au serveur %s, joueur %d/%d\0A\00"
define i32 @openConnection(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca %struct.hostent*
%10 = alloca %struct.sockaddr_in
%11 = alloca [3 x i32]
%12 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
store i32* %3, i32** %8
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %12
%16 = load i32, i32* %12
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %4
%22 = load i8*, i8** %5
%23 = call %struct.hostent* @gethostbyname(i8* %22)
store %struct.hostent* %23, %struct.hostent** %9
%24 = load %struct.hostent*, %struct.hostent** %9
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %21
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %30, i32* %31
%32 = load %struct.hostent*, %struct.hostent** %9
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %32, i32 0, i32 1
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i8*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
%38 = bitcast i32* %37 to i8*
%39 = load %struct.hostent*, %struct.hostent** %9
%40 = getelementptr inbounds %struct.hostent, %struct.hostent* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i32 @bcopy(i8* %35, i8* %38, i32 %41)
%43 = call i32 @htons(i32 2048)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %43, i32* %44
%45 = load i32, i32* %12
%46 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%47 = call i64 @connect(i32 %45, %struct.sockaddr* %46, i32 12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %29
%50 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %29
%53 = load i32, i32* %12
%54 = bitcast [3 x i32]* %11 to i32**
%55 = call i32 @read(i32 %53, i32** %54, i32 12)
%56 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 1
%57 = load i32, i32* %56
%58 = load i32*, i32** %6
store i32 %57, i32* %58
%59 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 0
%60 = load i32, i32* %59
%61 = load i32*, i32** %7
store i32 %60, i32* %61
%62 = getelementptr inbounds [3 x i32], [3 x i32]* %11, i64 0, i64 2
%63 = load i32, i32* %62
%64 = load i32*, i32** %8
store i32 %63, i32* %64
%65 = load i8*, i8** %5
%66 = load i32*, i32** %6
%67 = load i32, i32* %66
%68 = load i32*, i32** %7
%69 = load i32, i32* %68
%70 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %65, i32 %67, i32 %69)
%71 = load i32, i32* %12
ret i32 %71
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"opening socket\00"
@.str.1 = [13 x i8] c"no such host\00"
@.str.2 = [11 x i8] c"connecting\00"
@.str.3 = [39 x i8] c"connect\C3\A9 au serveur %s, joueur %d/%d\0A\00"
define i32 @openConnection(i8* %0, i32* nocapture %1, i32* nocapture %2, i32* nocapture writeonly %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca [3 x i32]
%7 = bitcast %struct.sockaddr_in* %5 to i8*
%8 = bitcast [3 x i32]* %6 to i8*
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %4
%17 = tail call %struct.hostent* @gethostbyname(i8* %0)
%18 = icmp eq %struct.hostent* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %16
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 1
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to i8*
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
%29 = bitcast i32* %28 to i8*
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i64 0, i32 0
%31 = load i32, i32* %30
%32 = tail call i32 @htons(i32 2048)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%35 = call i64 @connect(i32 %11, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %22
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %22
%41 = bitcast [3 x i32]* %6 to i32**
%42 = call i32 @read(i32 %11, i32** %41, i32 12)
%43 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 1
%44 = load i32, i32* %43
store i32 %44, i32* %1
%45 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 0
%46 = load i32, i32* %45
store i32 %46, i32* %2
%47 = getelementptr inbounds [3 x i32], [3 x i32]* %6, i64 0, i64 2
%48 = load i32, i32* %47
store i32 %48, i32* %3
%49 = load i32, i32* %1
%50 = load i32, i32* %2
%51 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %49, i32 %50)
ret i32 %11
}