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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ afficherEnTete();
int atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ gets(char *);
int htons(int);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ menu(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int main(int argc, char **argv) {
  int sock;
  struct sockaddr_in sin;
  afficherEnTete();
  char addr_serveur[15];
  int port_serveur;
  if (argc > 2) {
    sprintf(addr_serveur, "%s", argv[1]);
    port_serveur = atoi(argv[2]);
  } else {
    printf("Adresse IP du serveur : ");
    gets(addr_serveur);
    printf("Port du serveur : ");
    scanf("%d", &port_serveur);
  }
  sock = socket(AF_INET, SOCK_STREAM, 0);
  sin.sin_addr.s_addr = inet_addr(addr_serveur);
  sin.sin_family = AF_INET;
  sin.sin_port = htons(port_serveur);
  if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) != -1) {
    printf("Connexion à %s sur le port %d\n", inet_ntoa(sin.sin_addr),
           htons(sin.sin_port));
    menu(sock);
  } else
    perror("Impossible de se connecter\n");
  close(sock);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   10f0 <afficherEnTete@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1234 <main+0x54>
lea    -0x2f(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xde6(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x34(%rbp)
jmp    1269 <main+0x89>
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x2f(%rbp),%rdi
call   1090 <gets@plt>
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xdcf(%rip),%rdi
lea    -0x34(%rbp),%rsi
call   10a0 <scanf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x2f(%rbp),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x34(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     12f7 <main+0x117>
mov    -0x1c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%edi
call   1050 <htons@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    0xd4f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <menu@plt>
jmp    1303 <main+0x123>
lea    0xd54(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   10f0 <afficherEnTete@plt>
cmp    $0x3,%ebp
jl     1214 <main+0x34>
mov    0x8(%rbx),%rsi
lea    0x19(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x10(%rbx),%rdi
call   10d0 <atoi@plt>
mov    %eax,0x4(%rsp)
jmp    124b <main+0x6b>
lea    0xde5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x19(%rsp),%rdi
call   10a0 <gets@plt>
lea    0xde6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdeb(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10b0 <scanf@plt>
mov    0x2d96(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%ebx
lea    0x19(%rsp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x10(%rsp)
mov    0x4(%rsp),%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     12e5 <main+0x105>
mov    0xc(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%edi
call   1060 <htons@plt>
lea    0xd74(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1050 <menu@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd63(%rip),%rdi
call   10c0 <perror@plt>
jmp    12ce <main+0xee>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [25 x i8] c"Adresse IP du serveur : \00"
@.str.2 = [19 x i8] c"Port du serveur : \00"
@.str.3 = [3 x i8] c"%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [32 x i8] c"Connexion \C3\A0 %s sur le port %d\0A\00"
@.str.5 = [28 x i8] c"Impossible de se connecter\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca [15 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32 (...) @afficherEnTete()
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 2
br i1 %12, label %13, label %23
13: ; preds = %2
%14 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
store i32 %22, i32* %9
br label %29
23: ; preds = %2
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%25 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%26 = call i32 @gets(i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %9)
br label %29
29: ; preds = %23, %13
%30 = load i32, i32* @AF_INET
%31 = load i32, i32* @SOCK_STREAM
%32 = call i32 @socket(i32 %30, i32 %31, i32 0)
store i32 %32, i32* %6
%33 = getelementptr inbounds [15 x i8], [15 x i8]* %8, i64 0, i64 0
%34 = call i32 @inet_addr(i8* %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* %9
%40 = call i32 @htons(i32 %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %40, i32* %41
%42 = load i32, i32* %6
%43 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%44 = call i32 @connect(i32 %42, %struct.sockaddr* %43, i32 12)
%45 = icmp ne i32 %44, -1
br i1 %45, label %46, label %57
46: ; preds = %29
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i8* @inet_ntoa(i32 %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i32 @htons(i32 %52)
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %50, i32 %53)
%55 = load i32, i32* %6
%56 = call i32 @menu(i32 %55)
br label %59
57: ; preds = %29
%58 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %59
59: ; preds = %57, %46
%60 = load i32, i32* %6
%61 = call i32 @close(i32 %60)
%62 = load i32, i32* @EXIT_SUCCESS
ret i32 %62
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [25 x i8] c"Adresse IP du serveur : \00"
@.str.2 = [19 x i8] c"Port du serveur : \00"
@.str.3 = [3 x i8] c"%d\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [32 x i8] c"Connexion \C3\A0 %s sur le port %d\0A\00"
@.str.5 = [28 x i8] c"Impossible de se connecter\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [15 x i8]
%5 = alloca i32
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = tail call i32 (...) @afficherEnTete()
%8 = getelementptr inbounds [15 x i8], [15 x i8]* %4, i64 0, i64 0
%9 = bitcast i32* %5 to i8*
%10 = icmp sgt i32 %0, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i8* @strcpy(i8* %8, i8* dereferenceable(1) %13)
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %5
br label %23
18: ; preds = %2
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @gets(i8* %8)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
br label %23
23: ; preds = %18, %11
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
%27 = call i32 @inet_addr(i8* %8)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %27, i32* %28
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %29, i32* %30
%31 = load i32, i32* %5
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = call i32 @connect(i32 %26, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %44, label %37
37: ; preds = %23
%38 = load i32, i32* %28
%39 = call i8* @inet_ntoa(i32 %38)
%40 = load i32, i32* %33
%41 = call i32 @htons(i32 %40)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i8* %39, i32 %41)
%43 = call i32 @menu(i32 %26)
br label %46
44: ; preds = %23
%45 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %46
46: ; preds = %44, %37
%47 = call i32 @close(i32 %26)
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}