#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 dummy;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
struct sockaddr_in *creerSock(char *, char *, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sockfd;
  char sendline[100];
  char recvline[100];
  int taille;
  struct sockaddr_in *servaddr;
  if (argc == 1) {
    servaddr = creerSock("127.0.0.1", "2023", SOCK_STREAM, &sockfd);
  } else if (argc == 2) {
    servaddr = creerSock(argv[1], "2023", SOCK_STREAM, &sockfd);
  } else {
    servaddr = creerSock(argv[1], argv[2], SOCK_STREAM, &sockfd);
  }
  connect(sockfd, (struct sockaddr *)servaddr, sizeof(struct sockaddr_in));
  do {
    taille = read(0, sendline, 100);
    sendline[taille] = 0;
    write(sockfd, sendline, taille + 1);
    taille = read(sockfd, recvline, 100);
    recvline[taille] = 0;
    printf("[INFO] Nous avons reçu %s", recvline);
  } while (recvline[0] != '.');
  close(sockfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11af <main+0x4f>
mov    0x2e56(%rip),%rax
mov    (%rax),%edx
lea    0xe6d(%rip),%rdi
lea    0xe70(%rip),%rsi
lea    -0x14(%rbp),%rcx
call   1080 <creerSock@plt>
mov    %rax,-0x100(%rbp)
jmp    1214 <main+0xb4>
cmpl   $0x2,-0x8(%rbp)
jne    11e6 <main+0x86>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
lea    0xe39(%rip),%rsi
lea    -0x14(%rbp),%rcx
call   1080 <creerSock@plt>
mov    %rax,-0x100(%rbp)
jmp    120f <main+0xaf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0x2de3(%rip),%rax
mov    (%rax),%edx
lea    -0x14(%rbp),%rcx
call   1080 <creerSock@plt>
mov    %rax,-0x100(%rbp)
jmp    1214 <main+0xb4>
mov    -0x14(%rbp),%edi
mov    -0x100(%rbp),%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
lea    -0x80(%rbp),%rsi
xor    %edi,%edi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0xf4(%rbp)
movslq -0xf4(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    -0xf4(%rbp),%edx
add    $0x1,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0xf4(%rbp)
movslq -0xf4(%rbp),%rax
movb   $0x0,-0xf0(%rbp,%rax,1)
lea    -0xf0(%rbp),%rsi
lea    0xd79(%rip),%rdi
call   1040 <printf@plt>
movsbl -0xf0(%rbp),%eax
cmp    $0x2e,%eax
jne    1228 <main+0xc8>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xf0,%rsp
cmp    $0x2,%edi
je     118f <main+0x2f>
cmp    $0x1,%edi
jne    11a5 <main+0x45>
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    0xe7a(%rip),%rdi
lea    0xe7d(%rip),%rsi
jmp    11b6 <main+0x56>
mov    0x8(%rsi),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%edx
lea    0xe67(%rip),%rsi
jmp    11b6 <main+0x56>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
call   1080 <creerSock@plt>
mov    0xc(%rsp),%edi
mov    %rax,%rsi
mov    $0x4,%edx
call   1070 <connect@plt>
lea    0x80(%rsp),%r14
lea    0x10(%rsp),%rbx
lea    0xe2a(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
movslq %eax,%rdx
movb   $0x0,0x80(%rsp,%rdx,1)
mov    0xc(%rsp),%edi
add    $0x1,%edx
mov    %r14,%rsi
call   1030 <write@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
cmpb   $0x2e,0x10(%rsp)
jne    11f0 <main+0x90>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"2023\00"
@SOCK_STREAM = global i32 0
@.str.2 = [27 x i8] c"[INFO] Nous avons re\C3\A7u %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [100 x i8]
%8 = alloca [100 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @SOCK_STREAM
%15 = call %struct.sockaddr_in* @creerSock(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32* %6)
store %struct.sockaddr_in* %15, %struct.sockaddr_in** %10
br label %35
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @SOCK_STREAM
%24 = call %struct.sockaddr_in* @creerSock(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32* %6)
store %struct.sockaddr_in* %24, %struct.sockaddr_in** %10
br label %34
25: ; preds = %16
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = load i32, i32* @SOCK_STREAM
%33 = call %struct.sockaddr_in* @creerSock(i8* %28, i8* %31, i32 %32, i32* %6)
store %struct.sockaddr_in* %33, %struct.sockaddr_in** %10
br label %34
34: ; preds = %25, %19
br label %35
35: ; preds = %34, %13
%36 = load i32, i32* %6
%37 = load %struct.sockaddr_in*, %struct.sockaddr_in** %10
%38 = bitcast %struct.sockaddr_in* %37 to %struct.sockaddr*
%39 = call i32 @connect(i32 %36, %struct.sockaddr* %38, i32 4)
br label %40
40: ; preds = %59, %35
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%42 = call i32 @read(i32 0, i8* %41, i32 100)
store i32 %42, i32* %9
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 %44
store i8 0, i8* %45
%46 = load i32, i32* %6
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
%50 = call i32 @write(i32 %46, i8* %47, i32 %49)
%51 = load i32, i32* %6
%52 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%53 = call i32 @read(i32 %51, i8* %52, i32 100)
store i32 %53, i32* %9
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 %55
store i8 0, i8* %56
%57 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%58 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %57)
br label %59
59: ; preds = %40
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 46
br i1 %63, label %40, label %64
64: ; preds = %59
%65 = load i32, i32* %6
%66 = call i32 @close(i32 %65)
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [5 x i8] c"2023\00"
@SOCK_STREAM = global i32 0
@.str.2 = [27 x i8] c"[INFO] Nous avons re\C3\A7u %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = bitcast i32* %3 to i8*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
switch i32 %0, label %17 [
i32 1, label %9
i32 2, label %12
]
9: ; preds = %2
%10 = load i32, i32* @SOCK_STREAM
%11 = call %struct.sockaddr_in* @creerSock(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32* %3)
br label %24
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @SOCK_STREAM
%16 = call %struct.sockaddr_in* @creerSock(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32* %3)
br label %24
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = getelementptr inbounds i8*, i8** %1, i64 2
%21 = load i8*, i8** %20
%22 = load i32, i32* @SOCK_STREAM
%23 = call %struct.sockaddr_in* @creerSock(i8* %19, i8* %21, i32 %22, i32* %3)
br label %24
24: ; preds = %12, %17, %9
%25 = phi %struct.sockaddr_in* [ %11, %9 ], [ %16, %12 ], [ %23, %17 ]
%26 = load i32, i32* %3
%27 = bitcast %struct.sockaddr_in* %25 to %struct.sockaddr*
%28 = call i32 @connect(i32 %26, %struct.sockaddr* %27, i32 4)
br label %29
29: ; preds = %29, %24
%30 = call i32 @read(i32 0, i8* %7, i32 100)
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %3
%34 = add nsw i32 %30, 1
%35 = call i32 @write(i32 %33, i8* %7, i32 %34)
%36 = load i32, i32* %3
%37 = call i32 @read(i32 %36, i8* %8, i32 100)
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %38
store i8 0, i8* %39
%40 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%41 = load i8, i8* %8
%42 = icmp eq i8 %41, 46
br i1 %42, label %43, label %29
43: ; preds = %29
%44 = load i32, i32* %3
%45 = call i32 @close(i32 %44)
ret i32 0
}