#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;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *connect_encrypted(char *, char *, int /*<<< orphan*/ **,
                                      int /*<<< orphan*/ **);
int /*<<< orphan*/ init_openssl();
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read_from_stream(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write_to_stream(int /*<<< orphan*/ *, char *, int);
int main() {
  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 *store_path = "root.pem";
  char buffer[4096];
  buffer[0] = 0;
  BIO *bio;
  SSL_CTX *ctx = NULL;
  SSL *ssl = NULL;
  char server_request[5000];
  memset(server_request, 0, sizeof(server_request));
  while (strlen(server_request) < 2500) {
    strcat(server_request, server_request_template);
  }
  init_openssl();
  if ((bio = connect_encrypted(host_and_port, store_path, &ctx, &ssl)) == NULL)
    return (EXIT_FAILURE);
  write_to_stream(bio, server_request, strlen(server_request));
  while (read_from_stream(bio, buffer, 4096) > 0) {
    printf("%s", buffer);
  }
  SSL_CTX_free(ctx);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x23d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe5b(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe86(%rip),%rax
mov    %rax,-0x20(%rbp)
movb   $0x0,-0x1020(%rbp)
movq   $0x0,-0x1030(%rbp)
movq   $0x0,-0x1038(%rbp)
lea    -0x23c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1080 <memset@plt>
lea    -0x23c0(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x9c4,%eax
jge    121f <main+0x8f>
lea    -0x23c0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10b0 <strcat@plt>
jmp    11f3 <main+0x63>
mov    $0x0,%al
call   1050 <init_openssl@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x1030(%rbp),%rdx
lea    -0x1038(%rbp),%rcx
call   1090 <connect_encrypted@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    1263 <main+0xd3>
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12f2 <main+0x162>
mov    -0x1028(%rbp),%rax
mov    %rax,-0x23d0(%rbp)
lea    -0x23c0(%rbp),%rax
mov    %rax,-0x23c8(%rbp)
lea    -0x23c0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x23d0(%rbp),%rdi
mov    -0x23c8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write_to_stream@plt>
mov    -0x1028(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <read_from_stream@plt>
cmp    $0x0,%rax
jle    12da <main+0x14a>
lea    -0x1020(%rbp),%rsi
lea    0xd7e(%rip),%rdi
call   1070 <printf@plt>
jmp    12a0 <main+0x110>
mov    -0x1030(%rbp),%rdi
call   10a0 <SSL_CTX_free@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x23d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x23a0,%rsp
movb   $0x0,0x10(%rsp)
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x1010(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1388,%edx
call   1080 <memset@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x9c3,%eax
jg     120a <main+0x7a>
lea    0xe30(%rip),%r14
lea    0x1010(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmp    $0x9c4,%eax
jl     11f0 <main+0x60>
xor    %eax,%eax
call   1050 <init_openssl@plt>
lea    0xde8(%rip),%rdi
lea    0xe26(%rip),%rsi
mov    %rsp,%rdx
lea    0x8(%rsp),%rcx
call   1090 <connect_encrypted@plt>
test   %rax,%rax
je     12b2 <main+0x122>
mov    %rax,%r15
lea    0x1010(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write_to_stream@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    $0x1000,%edx
call   1030 <read_from_stream@plt>
test   %rax,%rax
jle    12a0 <main+0x110>
lea    0xddb(%rip),%r14
lea    0x10(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1030 <read_from_stream@plt>
test   %rax,%rax
jg     1280 <main+0xf0>
mov    (%rsp),%rdi
call   10a0 <SSL_CTX_free@plt>
mov    0x2d28(%rip),%rax
jmp    12b9 <main+0x129>
mov    0x2d27(%rip),%rax
mov    (%rax),%eax
add    $0x23a0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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"
@.str.2 = [9 x i8] c"root.pem\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca [5000 x i8]
store i32 0, i32* %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8** %4
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
store i8 0, i8* %10
store i32* null, i32** %7
store i32* null, i32** %8
%11 = getelementptr inbounds [5000 x i8], [5000 x i8]* %9, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 5000)
br label %13
13: ; preds = %17, %0
%14 = getelementptr inbounds [5000 x i8], [5000 x i8]* %9, i64 0, i64 0
%15 = call i32 @strlen(i8* %14)
%16 = icmp slt i32 %15, 2500
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = getelementptr inbounds [5000 x i8], [5000 x i8]* %9, i64 0, i64 0
%19 = load i8*, i8** %3
%20 = call i32 @strcat(i8* %18, i8* %19)
br label %13
21: ; preds = %13
%22 = call i32 (...) @init_openssl()
%23 = load i8*, i8** %2
%24 = load i8*, i8** %4
%25 = call i32* @connect_encrypted(i8* %23, i8* %24, i32** %7, i32** %8)
store i32* %25, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %21
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %1
br label %47
29: ; preds = %21
%30 = load i32*, i32** %6
%31 = getelementptr inbounds [5000 x i8], [5000 x i8]* %9, i64 0, i64 0
%32 = getelementptr inbounds [5000 x i8], [5000 x i8]* %9, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @write_to_stream(i32* %30, i8* %31, i32 %33)
br label %35
35: ; preds = %40, %29
%36 = load i32*, i32** %6
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%38 = call i64 @read_from_stream(i32* %36, i8* %37, i32 4096)
%39 = icmp sgt i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%42 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %41)
br label %35
43: ; preds = %35
%44 = load i32*, i32** %7
%45 = call i32 @SSL_CTX_free(i32* %44)
%46 = load i32, i32* @EXIT_SUCCESS
store i32 %46, i32* %1
br label %47
47: ; preds = %43, %27
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.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"
@.str.2 = [9 x i8] c"root.pem\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [5000 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
store i8 0, i8* %5
%6 = bitcast i32** %2 to i8*
store i32* null, i32** %2
%7 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%8 = getelementptr inbounds [5000 x i8], [5000 x i8]* %4, i64 0, i64 0
%9 = call i32 @memset(i8* %8, i32 0, i32 5000)
%10 = call i32 @strlen(i8* %8)
%11 = icmp slt i32 %10, 2500
br i1 %11, label %12, label %16
12: ; preds = %0, %12
%13 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @strlen(i8* %8)
%15 = icmp slt i32 %14, 2500
br i1 %15, label %12, label %16
16: ; preds = %12, %0
%17 = call i32 (...) @init_openssl()
%18 = call i32* @connect_encrypted(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32** %2, i32** %3)
%19 = icmp eq i32* %18, null
br i1 %19, label %32, label %20
20: ; preds = %16
%21 = call i32 @strlen(i8* %8)
%22 = call i32 @write_to_stream(i32* %18, i8* %8, i32 %21)
%23 = call i64 @read_from_stream(i32* %18, i8* %5, i32 4096)
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20, %25
%26 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%27 = call i64 @read_from_stream(i32* %18, i8* %5, i32 4096)
%28 = icmp sgt i64 %27, 0
br i1 %28, label %25, label %29
29: ; preds = %25, %20
%30 = load i32*, i32** %2
%31 = call i32 @SSL_CTX_free(i32* %30)
br label %32
32: ; preds = %16, %29
%33 = phi i32* [ @EXIT_SUCCESS, %29 ], [ @EXIT_FAILURE, %16 ]
%34 = load i32, i32* %33
ret i32 %34
}