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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int ma_socket;
  struct sockaddr_in server;
  char *message, reponse_server[2000];
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  server.sin_family = AF_INET;
  server.sin_port = htons(2080);
  ma_socket = socket(AF_INET, SOCK_STREAM, 0);
  if (ma_socket == -1) {
    printf("impossible de creer ton socket de merde");
  }
  if (connect(ma_socket, (struct sockaddr *)&server, sizeof(server)) < 0) {
    puts("erreur de connexion");
    return 1;
  }
  puts("connexion active");
  message = "GET / HTTP 1.1 \r\n\r\n";
  if (send(ma_socket, message, strlen(message), 0) < 0) {
    puts("echec envoie");
    return 1;
  }
  puts("envoie reussi\n");
  int n;
  while ((n = read(ma_socket, reponse_server, 2000)) > 0) {
    write(1, reponse_server, n);
  }
  close(ma_socket);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x820,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1223 <main+0x73>
lea    0xdec(%rip),%rdi
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    1256 <main+0xa6>
lea    0xded(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x16c>
lea    0xde9(%rip),%rdi
call   1030 <puts@plt>
lea    0xdee(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x814(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x810(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x814(%rbp),%edi
mov    -0x810(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    12c2 <main+0x112>
lea    0xdba(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    131c <main+0x16c>
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
mov    -0x14(%rbp),%edi
lea    -0x800(%rbp),%rsi
mov    $0x7d0,%edx
call   10a0 <read@plt>
mov    %eax,-0x804(%rbp)
cmp    $0x0,%eax
jle    130d <main+0x15d>
lea    -0x800(%rbp),%rsi
mov    -0x804(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
jmp    12ce <main+0x11e>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x7e8,%rsp
lea    0xe40(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x2e18(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    $0x820,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1208 <main+0x58>
lea    0xe07(%rip),%rdi
call   1080 <printf@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12ad <main+0xfd>
lea    0xe1f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe24(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     12b6 <main+0x106>
lea    0xe23(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x7d0,%edx
call   10a0 <read@plt>
test   %eax,%eax
jle    12a2 <main+0xf2>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x7d0,%edx
call   10a0 <read@plt>
test   %eax,%eax
jg     1280 <main+0xd0>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
jmp    12c7 <main+0x117>
lea    0xd7e(%rip),%rdi
jmp    12bd <main+0x10d>
lea    0xdae(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [40 x i8] c"impossible de creer ton socket de merde\00"
@.str.2 = [20 x i8] c"erreur de connexion\00"
@.str.3 = [17 x i8] c"connexion active\00"
@.str.4 = [20 x i8] c"GET / HTTP 1.1 \0D\0A\0D\0A\00"
@.str.5 = [13 x i8] c"echec envoie\00"
@.str.6 = [15 x i8] c"envoie reussi\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 i8*
%9 = alloca [2000 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %14, i32* %15
%16 = call i32 @htons(i32 2080)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @AF_INET
%19 = load i32, i32* @SOCK_STREAM
%20 = call i32 @socket(i32 %18, i32 %19, i32 0)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %2
%24 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %2
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%28 = call i64 @connect(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %56
32: ; preds = %25
%33 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8** %8
%34 = load i32, i32* %6
%35 = load i8*, i8** %8
%36 = load i8*, i8** %8
%37 = call i32 @strlen(i8* %36)
%38 = call i64 @send(i32 %34, i8* %35, i32 %37, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %56
42: ; preds = %32
%43 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %44
44: ; preds = %49, %42
%45 = load i32, i32* %6
%46 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 2000)
store i32 %47, i32* %10
%48 = icmp sgt i32 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %44
%50 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%51 = load i32, i32* %10
%52 = call i32 @write(i32 1, i8* %50, i32 %51)
br label %44
53: ; preds = %44
%54 = load i32, i32* %6
%55 = call i32 @close(i32 %54)
store i32 0, i32* %3
br label %56
56: ; preds = %53, %40, %30
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [10 x i8] c"127.0.0.1\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [40 x i8] c"impossible de creer ton socket de merde\00"
@.str.2 = [20 x i8] c"erreur de connexion\00"
@.str.3 = [17 x i8] c"connexion active\00"
@.str.4 = [20 x i8] c"GET / HTTP 1.1 \0D\0A\0D\0A\00"
@.str.5 = [13 x i8] c"echec envoie\00"
@.str.6 = [15 x i8] c"envoie reussi\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2000 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %7, i32* %8
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 2080)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %11, i32* %12
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* @SOCK_STREAM
%15 = tail call i32 @socket(i32 %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @connect(i32 %15, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %43
25: ; preds = %19
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @strlen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%28 = call i64 @send(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 0)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %43
32: ; preds = %25
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @read(i32 %15, i8* %6, i32 2000)
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %32, %36
%37 = phi i32 [ %39, %36 ], [ %34, %32 ]
%38 = call i32 @write(i32 1, i8* %6, i32 %37)
%39 = call i32 @read(i32 %15, i8* %6, i32 2000)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %36, label %41
41: ; preds = %36, %32
%42 = call i32 @close(i32 %15)
br label %43
43: ; preds = %41, %30, %23
%44 = phi i32 [ 1, %23 ], [ 1, %30 ], [ 0, %41 ]
ret i32 %44
}