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

/* Variables and functions */
scalar_t__ BIO_do_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_ssl_connect(int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_set_conn_hostname(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ BIO_should_retry(int /*<<< orphan*/ *);
scalar_t__ BIO_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSLv23_client_method();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strlen(char *);
int main() {
  BIO *bio;
  SSL *ssl;
  SSL_CTX *ctx;
  SSL_library_init();
  ctx = SSL_CTX_new(SSLv23_client_method());
  if (ctx == NULL) {
    printf("Ctx is null\n");
  }
  bio = BIO_new_ssl_connect(ctx);
  BIO_set_conn_hostname(bio, "YOUR_SERVER_URL"
                             ":"
                             "443");
  if (BIO_do_connect(bio) <= 0) {
    printf("Failed connection\n");
    return 1;
  } else {
    printf("Connected\n");
  }
  char *write_buf = "POST / HTTP/1.1\r\n"
                    "Host: "
                    "YOUR_SERVER_URL"
                    "\r\n"
                    "Authorization: Basic "
                    "YOUR_FANCY_KEY"
                    "\r\n"
                    "Connection: close\r\n"
                    "\r\n";
  if (BIO_write(bio, write_buf, strlen(write_buf)) <= 0) {
    if (!BIO_should_retry(bio)) {
    }
    printf("Failed write\n");
  }
  int size;
  char buf[1024];
  for (;;) {
    size = BIO_read(bio, buf, 1023);
    if (size <= 0) {
      break;
    }
    buf[size] = 0;
    printf("%s", buf);
  }
  BIO_free_all(bio);
  SSL_CTX_free(ctx);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1080 <SSL_library_init@plt>
mov    $0x0,%al
call   1040 <SSLv23_client_method@plt>
mov    %eax,%edi
call   10a0 <SSL_CTX_new@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1214 <main+0x44>
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10f0 <BIO_new_ssl_connect@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1090 <BIO_set_conn_hostname@plt>
mov    -0x10(%rbp),%rdi
call   1030 <BIO_do_connect@plt>
cmp    $0x0,%rax
jg     125e <main+0x8e>
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1345 <main+0x175>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdcc(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x440(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x440(%rbp),%rdi
mov    -0x438(%rbp),%rsi
mov    %eax,%edx
call   10e0 <BIO_write@plt>
cmp    $0x0,%rax
jg     12da <main+0x10a>
mov    -0x10(%rbp),%rdi
call   10d0 <BIO_should_retry@plt>
cmp    $0x0,%eax
jne    12cc <main+0xfc>
jmp    12cc <main+0xfc>
lea    0xdcf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12df <main+0x10f>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <BIO_read@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jg     1306 <main+0x136>
jmp    132c <main+0x15c>
movslq -0x2c(%rbp),%rax
movb   $0x0,-0x430(%rbp,%rax,1)
lea    -0x430(%rbp),%rsi
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12df <main+0x10f>
mov    -0x10(%rbp),%rdi
call   10c0 <BIO_free_all@plt>
mov    -0x20(%rbp),%rdi
call   10b0 <SSL_CTX_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x408,%rsp
xor    %eax,%eax
call   1090 <SSL_library_init@plt>
xor    %eax,%eax
call   1040 <SSLv23_client_method@plt>
mov    %eax,%edi
call   10b0 <SSL_CTX_new@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1217 <main+0x37>
lea    0xe91(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1100 <BIO_new_ssl_connect@plt>
mov    %rax,%r12
lea    0xdd7(%rip),%rsi
mov    %rax,%rdi
call   10a0 <BIO_set_conn_hostname@plt>
mov    %r12,%rdi
call   1030 <BIO_do_connect@plt>
test   %rax,%rax
jle    12eb <main+0x10b>
lea    0xe31(%rip),%rdi
call   1050 <puts@plt>
lea    0xdbf(%rip),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   10f0 <BIO_write@plt>
test   %rax,%rax
jg     1283 <main+0xa3>
mov    %r12,%rdi
call   10e0 <BIO_should_retry@plt>
lea    0xe06(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rsi
mov    %r12,%rdi
mov    $0x3ff,%edx
call   1060 <BIO_read@plt>
test   %eax,%eax
jle    12d7 <main+0xf7>
lea    0xdd9(%rip),%r15
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1060 <BIO_read@plt>
test   %eax,%eax
jg     12b0 <main+0xd0>
mov    %r12,%rdi
call   10d0 <BIO_free_all@plt>
mov    %r14,%rdi
call   10c0 <SSL_CTX_free@plt>
xor    %eax,%eax
jmp    12fc <main+0x11c>
lea    0xd9f(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Ctx is null\0A\00"
@.str.1 = [20 x i8] c"YOUR_SERVER_URL:443\00"
@.str.2 = [19 x i8] c"Failed connection\0A\00"
@.str.3 = [11 x i8] c"Connected\0A\00"
@.str.4 = [99 x i8] c"POST / HTTP/1.1\0D\0AHost: YOUR_SERVER_URL\0D\0AAuthorization: Basic YOUR_FANCY_KEY\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.5 = [14 x i8] c"Failed write\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1024 x i8]
store i32 0, i32* %1
%8 = call i32 (...) @SSL_library_init()
%9 = call i32 (...) @SSLv23_client_method()
%10 = call i32* @SSL_CTX_new(i32 %9)
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %0
%16 = load i32*, i32** %4
%17 = call i32* @BIO_new_ssl_connect(i32* %16)
store i32* %17, i32** %2
%18 = load i32*, i32** %2
%19 = call i32 @BIO_set_conn_hostname(i32* %18, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%20 = load i32*, i32** %2
%21 = call i64 @BIO_do_connect(i32* %20)
%22 = icmp sle i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %1
br label %60
25: ; preds = %15
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %25
store i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.4, i64 0, i64 0), i8** %5
%28 = load i32*, i32** %2
%29 = load i8*, i8** %5
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
%32 = call i64 @BIO_write(i32* %28, i8* %29, i32 %31)
%33 = icmp sle i64 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %27
%35 = load i32*, i32** %2
%36 = call i32 @BIO_should_retry(i32* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %34
br label %39
39: ; preds = %38, %34
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %41
41: ; preds = %39, %27
br label %42
42: ; preds = %49, %41
%43 = load i32*, i32** %2
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%45 = call i32 @BIO_read(i32* %43, i8* %44, i32 1023)
store i32 %45, i32* %6
%46 = load i32, i32* %6
%47 = icmp sle i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %42
br label %55
49: ; preds = %42
%50 = load i32, i32* %6
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %51
store i8 0, i8* %52
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %53)
br label %42
55: ; preds = %48
%56 = load i32*, i32** %2
%57 = call i32 @BIO_free_all(i32* %56)
%58 = load i32*, i32** %4
%59 = call i32 @SSL_CTX_free(i32* %58)
store i32 0, i32* %1
br label %60
60: ; preds = %55, %23
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str.1 = [20 x i8] c"YOUR_SERVER_URL:443\00"
@.str.4 = [99 x i8] c"POST / HTTP/1.1\0D\0AHost: YOUR_SERVER_URL\0D\0AAuthorization: Basic YOUR_FANCY_KEY\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@str = [10 x i8] c"Connected\00"
@str.7 = [13 x i8] c"Failed write\00"
@str.8 = [18 x i8] c"Failed connection\00"
@str.9 = [12 x i8] c"Ctx is null\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = tail call i32 (...) @SSL_library_init()
%3 = tail call i32 (...) @SSLv23_client_method()
%4 = tail call i32* @SSL_CTX_new(i32 %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.9, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = tail call i32* @BIO_new_ssl_connect(i32* %4)
%10 = tail call i32 @BIO_set_conn_hostname(i32* %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i64 @BIO_do_connect(i32* %9)
%12 = icmp slt i64 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.8, i64 0, i64 0))
br label %37
15: ; preds = %8
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @strlen(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.4, i64 0, i64 0))
%18 = tail call i64 @BIO_write(i32* %9, i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.4, i64 0, i64 0), i32 %17)
%19 = icmp slt i64 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = tail call i32 @BIO_should_retry(i32* %9)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0))
br label %23
23: ; preds = %20, %15
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%25 = call i32 @BIO_read(i32* %9, i8* %24, i32 1023)
%26 = icmp slt i32 %25, 1
br i1 %26, label %34, label %27
27: ; preds = %23, %27
%28 = phi i32 [ %32, %27 ], [ %25, %23 ]
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %29
store i8 0, i8* %30
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %24)
%32 = call i32 @BIO_read(i32* %9, i8* %24, i32 1023)
%33 = icmp slt i32 %32, 1
br i1 %33, label %34, label %27
34: ; preds = %27, %23
%35 = call i32 @BIO_free_all(i32* %9)
%36 = call i32 @SSL_CTX_free(i32* %4)
br label %37
37: ; preds = %34, %13
%38 = phi i32 [ 1, %13 ], [ 0, %34 ]
ret i32 %38
}