#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 */
typedef int /*<<< orphan*/ server_request;

/* Variables and functions */
int create_socket();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ getc(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
scalar_t__ write(int, char *, int);
int main() {
  int sock = create_socket();
  char *host_and_port = "127.0.0.1:4443";
  char *server_request_template =
      "GET /mini_template.html HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n";
  char server_request[5000];
  memset(server_request, 0, sizeof(server_request));
  while (strlen(server_request) < 2500) {
    strcat(server_request, server_request_template);
  }
  int single_write = 0;
  int enters = 0;
  if (single_write == 1) {
    write(sock, server_request, strlen(server_request));
  } else {
    int off = 0;
    while (off < strlen(server_request)) {
      off += write(sock, &server_request[off], 65);
      getc(stdin);
      enters++;
      printf("enters: %d\n", enters);
      fflush(stdout);
    }
  }
  sleep(1000);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <create_socket@plt>
mov    %eax,-0x8(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe41(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x13a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1060 <memset@plt>
lea    -0x13a0(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x9c4,%eax
jge    1211 <main+0x71>
lea    -0x13a0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strcat@plt>
jmp    11e5 <main+0x45>
movl   $0x0,-0x13a4(%rbp)
movl   $0x0,-0x13a8(%rbp)
cmpl   $0x1,-0x13a4(%rbp)
jne    126e <main+0xce>
mov    -0x8(%rbp),%eax
mov    %eax,-0x13bc(%rbp)
lea    -0x13a0(%rbp),%rax
mov    %rax,-0x13b8(%rbp)
lea    -0x13a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x13bc(%rbp),%edi
mov    -0x13b8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1318 <main+0x178>
movl   $0x0,-0x13ac(%rbp)
mov    -0x13ac(%rbp),%eax
mov    %eax,-0x13c0(%rbp)
lea    -0x13a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x13c0(%rbp),%eax
cmp    %ecx,%eax
jge    1313 <main+0x173>
mov    -0x8(%rbp),%edi
movslq -0x13ac(%rbp),%rax
lea    -0x13a0(%rbp),%rsi
add    %rax,%rsi
mov    $0x41,%edx
call   1030 <write@plt>
mov    %rax,%rcx
movslq -0x13ac(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x13ac(%rbp)
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
call   10c0 <getc@plt>
mov    -0x13a8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x13a8(%rbp)
mov    -0x13a8(%rbp),%esi
lea    0xd4a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
jmp    1278 <main+0xd8>
jmp    1318 <main+0x178>
mov    $0x3e8,%edi
call   10b0 <sleep@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1388,%rsp
xor    %eax,%eax
call   1080 <create_socket@plt>
mov    %eax,%r12d
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1060 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x9c3,%eax
jg     120a <main+0x6a>
lea    0xe1d(%rip),%rbp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x9c4,%eax
jl     11f0 <main+0x50>
mov    %rsp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1276 <main+0xd6>
xor    %ebx,%ebx
mov    $0x1,%ebp
lea    0xe12(%rip),%r14
mov    0x2dad(%rip),%r13
mov    %rsp,%r15
xchg   %ax,%ax
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rsi
mov    %r12d,%edi
mov    $0x41,%edx
call   1030 <write@plt>
add    %eax,%ebx
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10c0 <getc@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
mov    %r15,%rdi
call   1040 <strlen@plt>
add    $0x1,%ebp
cmp    %eax,%ebx
jl     1230 <main+0x90>
mov    $0x3e8,%edi
call   10b0 <sleep@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"127.0.0.1:4443\00"
@.str.1 = [54 x i8] c"GET /mini_template.html HTTP/1.1\0D\0AHost: 127.0.0.1\0D\0A\0D\0A\00"
@stdin = global i32 0
@.str.2 = [12 x i8] c"enters: %d\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [5000 x i8]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
%9 = call i32 (...) @create_socket()
store i32 %9, i32* %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8** %4
%10 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 5000)
br label %12
12: ; preds = %16, %0
%13 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %14, 2500
br i1 %15, label %16, label %20
16: ; preds = %12
%17 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%18 = load i8*, i8** %4
%19 = call i32 @strcat(i8* %17, i8* %18)
br label %12
20: ; preds = %12
store i32 0, i32* %6
store i32 0, i32* %7
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = load i32, i32* %2
%25 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%26 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = call i64 @write(i32 %24, i8* %25, i32 %27)
br label %54
29: ; preds = %20
store i32 0, i32* %8
br label %30
30: ; preds = %35, %29
%31 = load i32, i32* %8
%32 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = icmp slt i32 %31, %33
br i1 %34, label %35, label %53
35: ; preds = %30
%36 = load i32, i32* %2
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [5000 x i8], [5000 x i8]* %5, i64 0, i64 %38
%40 = call i64 @write(i32 %36, i8* %39, i32 65)
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %8
%45 = load i32, i32* @stdin
%46 = call i32 @getc(i32 %45)
%47 = load i32, i32* %7
%48 = add nsw i32 %47, 1
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load i32, i32* @stdout
%52 = call i32 @fflush(i32 %51)
br label %30
53: ; preds = %30
br label %54
54: ; preds = %53, %23
%55 = call i32 @sleep(i32 1000)
%56 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [54 x i8] c"GET /mini_template.html HTTP/1.1\0D\0AHost: 127.0.0.1\0D\0A\0D\0A\00"
@stdin = global i32 0
@.str.2 = [12 x i8] c"enters: %d\0A\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca [5000 x i8]
%2 = tail call i32 (...) @create_socket()
%3 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 0
%4 = call i32 @memset(i8* %3, i32 0, i32 5000)
%5 = call i32 @strlen(i8* %3)
%6 = icmp slt i32 %5, 2500
br i1 %6, label %10, label %7
7: ; preds = %10, %0
%8 = call i32 @strlen(i8* %3)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %14, label %30
10: ; preds = %0, %10
%11 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @strlen(i8* %3)
%13 = icmp slt i32 %12, 2500
br i1 %13, label %10, label %7
14: ; preds = %7, %14
%15 = phi i32 [ %21, %14 ], [ 0, %7 ]
%16 = phi i32 [ %24, %14 ], [ 0, %7 ]
%17 = sext i32 %15 to i64
%18 = getelementptr inbounds [5000 x i8], [5000 x i8]* %1, i64 0, i64 %17
%19 = call i64 @write(i32 %2, i8* %18, i32 65)
%20 = trunc i64 %19 to i32
%21 = add i32 %15, %20
%22 = load i32, i32* @stdin
%23 = call i32 @getc(i32 %22)
%24 = add nuw nsw i32 %16, 1
%25 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @stdout
%27 = call i32 @fflush(i32 %26)
%28 = call i32 @strlen(i8* %3)
%29 = icmp slt i32 %21, %28
br i1 %29, label %14, label %30
30: ; preds = %14, %7
%31 = call i32 @sleep(i32 1000)
%32 = call i32 @exit(i32 0)
unreachable
}