#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 read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sockfd;
  struct sockaddr_in *srvaddr;
  char buff[2049];
  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 ");
  }
  write(sockfd, argv[3], strlen(argv[3]));
  slen = read(sockfd, buff, 2048);
  buff[slen] = 0;
  write(1, buff, slen + 1);
  close(sockfd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    11da <main+0x4a>
lea    0xe2b(%rip),%rdi
call   1080 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x840(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    -0x840(%rbp),%rdi
mov    %eax,%esi
call   1070 <creerSockAddr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    122f <main+0x9f>
lea    0xde2(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x84c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x848(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <strlen@plt>
mov    -0x84c(%rbp),%edi
mov    -0x848(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x830(%rbp),%rsi
mov    $0x800,%edx
call   1060 <read@plt>
mov    %eax,-0x834(%rbp)
movslq -0x834(%rbp),%rax
movb   $0x0,-0x830(%rbp,%rax,1)
lea    -0x830(%rbp),%rsi
mov    -0x834(%rbp),%edx
add    $0x1,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x810,%rsp
mov    %rsi,%r14
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e2a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1242 <main+0xb2>
mov    0x8(%r14),%rbx
mov    0x10(%r14),%rdi
call   1090 <atoi@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1070 <creerSockAddr@plt>
mov    %ebp,%edi
mov    %rax,%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     1253 <main+0xc3>
mov    0x18(%r14),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1060 <read@plt>
movslq %eax,%rdx
movb   $0x0,(%rsp,%rdx,1)
add    $0x1,%edx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdb7(%rip),%rdi
call   1080 <perror@plt>
jmp    11c1 <main+0x31>
lea    0xdb2(%rip),%rdi
call   1080 <perror@plt>
jmp    11ec <main+0x5c>

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"
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 [2049 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 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @write(i32 %33, i8* %36, i32 %40)
%42 = load i32, i32* %6
%43 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 0
%44 = call i32 @read(i32 %42, i8* %43, i32 2048)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 %46
store i8 0, i8* %47
%48 = getelementptr inbounds [2049 x i8], [2049 x i8]* %8, i64 0, i64 0
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
%51 = call i32 @write(i32 1, i8* %48, i32 %50)
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %3
ret i32 %54
}

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"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2049 x i8]
%4 = getelementptr inbounds [2049 x i8], [2049 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 = getelementptr inbounds i8*, i8** %1, i64 3
%25 = load i8*, i8** %24
%26 = tail call i32 @strlen(i8* %25)
%27 = tail call i32 @write(i32 %7, i8* %25, i32 %26)
%28 = call i32 @read(i32 %7, i8* %4, i32 2048)
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [2049 x i8], [2049 x i8]* %3, i64 0, i64 %29
store i8 0, i8* %30
%31 = add nsw i32 %28, 1
%32 = call i32 @write(i32 1, i8* %4, i32 %31)
%33 = tail call i32 @close(i32 %7)
ret i32 0
}