#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 */
typedef scalar_t__ uint32_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server_in_addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ atoi(char *);
int /*<<< orphan*/ close(scalar_t__);
scalar_t__ connect(scalar_t__, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(scalar_t__, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(scalar_t__, char *, int /*<<< orphan*/,
                        int /*<<< orphan*/);
scalar_t__ socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  uint32_t iterations = 10;
  if (argc > 1)
    iterations = atoi(argv[1]);
  struct sockaddr_in server_in_addr = {.sin_family = AF_INET,
                                       .sin_port = htons(9393),
                                       .sin_addr.s_addr =
                                           htonl(INADDR_LOOPBACK)};
  for (uint32_t i = 0; i < iterations; ++i) {
    uint32_t server_socket = socket(AF_INET, SOCK_STREAM, 0);
    if (connect(server_socket, (struct sockaddr *)&server_in_addr,
                sizeof(server_in_addr))) {
      printf("failed to connect socket \n");
      exit(1);
    }
    char in[(1024 * 32)];
    char out[(1024 * 32)];
    strcpy(out, "GET http://localhost:9393/plan?12345 HTTP/1.1\n");
    send(server_socket, out, strlen(out), 0);
    printf("sent: %s \n", out);
    recv(server_socket, in, (1024 * 32) - 1, 0);
    in[(1024 * 32) - 1] = '\0';
    printf("received: %s \n", in);
    close(server_socket);
  }
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0xa,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11fc <main+0x3c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %rax,-0x18(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x28(%rbp)
mov    $0x24b1,%edi
call   1060 <htons@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    133b <main+0x17b>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
je     128d <main+0xcd>
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x10040(%rbp),%rdi
lea    0xd80(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x10050(%rbp)
lea    -0x10040(%rbp),%rax
mov    %rax,-0x10048(%rbp)
lea    -0x10040(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x10050(%rbp),%rdi
mov    -0x10048(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    -0x10040(%rbp),%rsi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x8040(%rbp),%rsi
mov    $0x7fff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movb   $0x0,-0x41(%rbp)
lea    -0x8040(%rbp),%rsi
lea    0xd3b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
call   10a0 <close@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    122e <main+0x6e>
xor    %eax,%eax
add    $0x10050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10018,%rsp
mov    $0xa,%r12d
cmp    $0x2,%edi
jl     11f8 <main+0x28>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
mov    %rax,%r12
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,(%rsp)
mov    $0x24b1,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
test   %r12,%r12
jle    1327 <main+0x157>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
jne    1311 <main+0x141>
lea    0x8010(%rsp),%r15
lea    0x10(%rsp),%rbp
lea    0xdcd(%rip),%r14
mov    %rsp,%r13
mov    %r15,%rdi
lea    0xd86(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
lea    0xd92(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x7fff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
movb   $0x0,0x800f(%rsp)
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbx,%rdi
call   10b0 <close@plt>
add    $0xffffffffffffffff,%r12
je     1327 <main+0x157>
mov    0x2d05(%rip),%rax
mov    (%rax),%edi
mov    0x2ce4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r13,%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
test   %rax,%rax
je     1270 <main+0xa0>
lea    0xd31(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
add    $0x10018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INADDR_LOOPBACK = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [27 x i8] c"failed to connect socket \0A\00"
@.str.1 = [47 x i8] c"GET http://localhost:9393/plan?12345 HTTP/1.1\0A\00"
@.str.2 = [11 x i8] c"sent: %s \0A\00"
@.str.3 = [15 x i8] c"received: %s \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca %struct.sockaddr_in
%8 = alloca i64
%9 = alloca i64
%10 = alloca [32768 x i8]
%11 = alloca [32768 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 10, i64* %6
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @atoi(i8* %17)
store i64 %18, i64* %6
br label %19
19: ; preds = %14, %2
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
%22 = load i32, i32* @INADDR_LOOPBACK
%23 = call i32 @htonl(i32 %22)
store i32 %23, i32* %21
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%25 = call i32 @htons(i32 9393)
store i32 %25, i32* %24
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%27 = load i32, i32* @AF_INET
store i32 %27, i32* %26
store i64 0, i64* %8
br label %28
28: ; preds = %61, %19
%29 = load i64, i64* %8
%30 = load i64, i64* %6
%31 = icmp slt i64 %29, %30
br i1 %31, label %32, label %64
32: ; preds = %28
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = call i64 @socket(i32 %33, i32 %34, i32 0)
store i64 %35, i64* %9
%36 = load i64, i64* %9
%37 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%38 = call i64 @connect(i64 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %32
%44 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%45 = call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%46 = load i64, i64* %9
%47 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%48 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 @send(i64 %46, i8* %47, i32 %49, i32 0)
%51 = getelementptr inbounds [32768 x i8], [32768 x i8]* %11, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = load i64, i64* %9
%54 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%55 = call i32 @recv(i64 %53, i8* %54, i32 32767, i32 0)
%56 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 32767
store i8 0, i8* %56
%57 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = load i64, i64* %9
%60 = call i32 @close(i64 %59)
br label %61
61: ; preds = %43
%62 = load i64, i64* %8
%63 = add nsw i64 %62, 1
store i64 %63, i64* %8
br label %28
64: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@INADDR_LOOPBACK = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [47 x i8] c"GET http://localhost:9393/plan?12345 HTTP/1.1\0A\00"
@.str.2 = [11 x i8] c"sent: %s \0A\00"
@.str.3 = [15 x i8] c"received: %s \0A\00"
@str = [26 x i8] c"failed to connect socket \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [32768 x i8]
%5 = alloca [32768 x i8]
%6 = icmp sgt i32 %0, 1
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @atoi(i8* %9)
br label %11
11: ; preds = %7, %2
%12 = phi i64 [ %10, %7 ], [ 10, %2 ]
%13 = bitcast %struct.sockaddr_in* %3 to i8*
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%15 = load i32, i32* @INADDR_LOOPBACK
%16 = tail call i32 @htonl(i32 %15)
store i32 %16, i32* %14
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%18 = tail call i32 @htons(i32 9393)
store i32 %18, i32* %17
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%20 = load i32, i32* @AF_INET
store i32 %20, i32* %19
%21 = icmp sgt i64 %12, 0
br i1 %21, label %22, label %31
22: ; preds = %11
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 0
%25 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [32768 x i8], [32768 x i8]* %4, i64 0, i64 32767
%27 = load i32, i32* @SOCK_STREAM
%28 = call i64 @socket(i32 %20, i32 %27, i32 0)
%29 = call i64 @connect(i64 %28, %struct.sockaddr* %23, i32 12)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %32
31: ; preds = %35, %11
ret i32 0
32: ; preds = %47, %22
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %22, %47
%36 = phi i64 [ %50, %47 ], [ %28, %22 ]
%37 = phi i64 [ %45, %47 ], [ 0, %22 ]
%38 = call i32 @strcpy(i8* %25, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @strlen(i8* %25)
%40 = call i32 @send(i64 %36, i8* %25, i32 %39, i32 0)
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%42 = call i32 @recv(i64 %36, i8* %24, i32 32767, i32 0)
store i8 0, i8* %26
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %24)
%44 = call i32 @close(i64 %36)
%45 = add nuw nsw i64 %37, 1
%46 = icmp eq i64 %45, %12
br i1 %46, label %31, label %47
47: ; preds = %35
%48 = load i32, i32* @AF_INET
%49 = load i32, i32* @SOCK_STREAM
%50 = call i64 @socket(i32 %48, i32 %49, i32 0)
%51 = call i64 @connect(i64 %50, %struct.sockaddr* %23, i32 12)
%52 = icmp eq i64 %51, 0
br i1 %52, label %35, label %32
}