#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 *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main() {
  int socketdesc = socket(AF_INET, SOCK_STREAM, 0);
  char *message, server_reply[2000];
  struct sockaddr_in server;
  server.sin_addr.s_addr = inet_addr("127.0.0.1");
  server.sin_family = AF_INET;
  server.sin_port = htons(8888);
  puts("Connecting...");
  if (connect(socketdesc, (struct sockaddr *)&server, sizeof(server)) < 0) {
    puts("Connect failed!");
    return 1;
  }
  puts("Connected");
  puts("Sending Data, YOLO!");
  message = "GET / HTTP/1.1\r\n\r\n";
  if (send(socketdesc, message, strlen(message), 0) < 0) {
    puts("Oh no! Something went wrong sending the data D:. Quiting!");
    return 1;
  }
  printf("Now it's time to listen and recieve some data! %d array, YOLO!\n",
         2000);
  if (recv(socketdesc, server_reply, 2000, 0) < 0) {
    printf("Okay, umm... this isn't good. It appears that the recieve command "
           "failed for some reason. Bye... :(");
  }
  close(socketdesc);
  puts("Reply recieved, YOLO :D");
  puts(server_reply);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    0xe2b(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x7e8(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7ec(%rbp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,-0x7f0(%rbp)
lea    0xe04(%rip),%rdi
call   1040 <puts@plt>
mov    -0x8(%rbp),%edi
lea    -0x7f0(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0x0,%rax
jge    1241 <main+0xa1>
lea    0xde8(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1321 <main+0x181>
lea    0xde0(%rip),%rdi
call   1040 <puts@plt>
lea    0xdde(%rip),%rdi
call   1040 <puts@plt>
lea    0xde6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x7fc(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x7f8(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x7fc(%rbp),%edi
mov    -0x7f8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    12b9 <main+0x119>
lea    0xdb1(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1321 <main+0x181>
lea    0xdd3(%rip),%rdi
mov    $0x7d0,%esi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x7e0(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    12fa <main+0x15a>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
lea    -0x7e0(%rbp),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x7e8,%rsp
mov    0x2e38(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
lea    0xe34(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    $0x22b8,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     12a1 <main+0x101>
lea    0xe14(%rip),%rdi
call   1040 <puts@plt>
lea    0xe12(%rip),%rdi
call   1040 <puts@plt>
lea    0xe1a(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     12aa <main+0x10a>
lea    0xe45(%rip),%rdi
xor    %ebp,%ebp
mov    $0x7d0,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jns    1282 <main+0xe2>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xea7(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
jmp    12bb <main+0x11b>
lea    0xd70(%rip),%rdi
jmp    12b1 <main+0x111>
lea    0xda8(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [14 x i8] c"Connecting...\00"
@.str.2 = [16 x i8] c"Connect failed!\00"
@.str.3 = [10 x i8] c"Connected\00"
@.str.4 = [20 x i8] c"Sending Data, YOLO!\00"
@.str.5 = [19 x i8] c"GET / HTTP/1.1\0D\0A\0D\0A\00"
@.str.6 = [58 x i8] c"Oh no! Something went wrong sending the data D:. Quiting!\00"
@.str.7 = [64 x i8] c"Now it's time to listen and recieve some data! %d array, YOLO!\0A\00"
@.str.8 = [100 x i8] c"Okay, umm... this isn't good. It appears that the recieve command failed for some reason. Bye... :(\00"
@.str.9 = [24 x i8] c"Reply recieved, YOLO :D\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [2000 x i8]
%5 = alloca %struct.sockaddr_in
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %2
%9 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @htons(i32 8888)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
store i32 %14, i32* %15
%16 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* %2
%18 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%19 = call i64 @connect(i32 %17, %struct.sockaddr* %18, i32 12)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @puts(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %48
23: ; preds = %0
%24 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8** %3
%26 = load i32, i32* %2
%27 = load i8*, i8** %3
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
%30 = call i64 @send(i32 %26, i8* %27, i32 %29, i32 0)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %23
%33 = call i32 @puts(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %48
34: ; preds = %23
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0), i32 2000)
%36 = load i32, i32* %2
%37 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%38 = call i64 @recv(i32 %36, i8* %37, i32 2000, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.8, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
%43 = load i32, i32* %2
%44 = call i32 @close(i32 %43)
%45 = call i32 @puts(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%46 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%47 = call i32 @puts(i8* %46)
store i32 0, i32* %1
br label %48
48: ; preds = %42, %32, %21
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [14 x i8] c"Connecting...\00"
@.str.2 = [16 x i8] c"Connect failed!\00"
@.str.3 = [10 x i8] c"Connected\00"
@.str.4 = [20 x i8] c"Sending Data, YOLO!\00"
@.str.5 = [19 x i8] c"GET / HTTP/1.1\0D\0A\0D\0A\00"
@.str.6 = [58 x i8] c"Oh no! Something went wrong sending the data D:. Quiting!\00"
@.str.7 = [64 x i8] c"Now it's time to listen and recieve some data! %d array, YOLO!\0A\00"
@.str.8 = [100 x i8] c"Okay, umm... this isn't good. It appears that the recieve command failed for some reason. Bye... :(\00"
@.str.9 = [24 x i8] c"Reply recieved, YOLO :D\00"
define i32 @main() {
%1 = alloca [2000 x i8]
%2 = alloca %struct.sockaddr_in
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_STREAM
%5 = tail call i32 @socket(i32 %3, i32 %4, i32 0)
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%7 = bitcast %struct.sockaddr_in* %2 to i8*
%8 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 8888)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%15 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%16 = call i64 @connect(i32 %5, %struct.sockaddr* %15, i32 12)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %0
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %38
20: ; preds = %0
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%23 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%24 = call i64 @send(i32 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %23, i32 0)
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @.str.6, i64 0, i64 0))
br label %38
28: ; preds = %20
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.7, i64 0, i64 0), i32 2000)
%30 = call i64 @recv(i32 %5, i8* %6, i32 2000, i32 0)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @.str.8, i64 0, i64 0))
br label %34
34: ; preds = %32, %28
%35 = call i32 @close(i32 %5)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%37 = call i32 @puts(i8* %6)
br label %38
38: ; preds = %34, %26, %18
%39 = phi i32 [ 1, %18 ], [ 1, %26 ], [ 0, %34 ]
ret i32 %39
}