#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*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr const *, int);
struct sockaddr_in *creerSockAddr(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int reads(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in *srvaddr;
  char buff[80];
  int slen;
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Dans socket");
  }
  srvaddr = creerSockAddr(argv[1], atoi(argv[2]));
  if (connect(sockfd, (const struct sockaddr *)srvaddr, sizeof(*srvaddr)) < 0) {
    perror("Dasn connect ");
  }
  slen = reads(sockfd, buff, 80);
  buff[slen] = 0;
  printf("%s\n", buff);
  close(sockfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11ca <main+0x4a>
lea    0xe3b(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%esi
call   1050 <creerSockAddr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    1219 <main+0x99>
lea    0xdf8(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x50,%edx
call   1080 <reads@plt>
mov    %eax,-0x74(%rbp)
movslq -0x74(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
lea    -0x70(%rbp),%rsi
lea    0xdd9(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%rbx
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1212 <main+0x92>
mov    0x8(%rbx),%rbp
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %rbp,%rdi
mov    %eax,%esi
call   1050 <creerSockAddr@plt>
mov    %r14d,%edi
mov    %rax,%rsi
mov    $0x4,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     1220 <main+0xa0>
mov    %rsp,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1080 <reads@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe23(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %r14d,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde7(%rip),%rdi
call   1060 <perror@plt>
jmp    11ab <main+0x2b>
lea    0xde5(%rip),%rdi
call   1060 <perror@plt>
jmp    11d7 <main+0x57>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"Dans socket\00"
@.str.1 = [14 x i8] c"Dasn connect \00"
@.str.2 = [4 x i8] c"%s\0A\00"
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 [80 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @AF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
%24 = call %struct.sockaddr_in* @creerSockAddr(i8* %19, i32 %23)
store %struct.sockaddr_in* %24, %struct.sockaddr_in** %7
%25 = load i32, i32* %6
%26 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%27 = bitcast %struct.sockaddr_in* %26 to %struct.sockaddr*
%28 = call i64 @connect(i32 %25, %struct.sockaddr* %27, i32 4)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %16
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %30, %16
%33 = load i32, i32* %6
%34 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%35 = call i32 @reads(i32 %33, i8* %34, i32 80)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%40 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %39)
%41 = load i32, i32* %6
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [12 x i8] c"Dans socket\00"
@.str.1 = [14 x i8] c"Dasn connect \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [80 x i8]
%4 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = tail call %struct.sockaddr_in* @creerSockAddr(i8* %13, i32 %16)
%18 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%19 = tail call i64 @connect(i32 %7, %struct.sockaddr* %18, i32 4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %11
%24 = call i32 @reads(i32 %7, i8* %4, i32 80)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 %25
store i8 0, i8* %26
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%28 = call i32 @close(i32 %7)
ret i32 0
}