#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*/ BIO;

/* Variables and functions */
scalar_t__ BIO_do_connect(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_connect(char *);
int BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int main(void) {
  BIO *bio = NULL;
  char request_str[1024] = {0};
  int request_len = 0;
  char response_buf[1024] = {0};
  int response_len = 0;
  bio = BIO_new_connect("bgstation0.com:80");
  if (bio == NULL) {
    printf("BIO_new_connect error!\n");
    return -1;
  }
  if (BIO_do_connect(bio) <= 0) {
    printf("BIO_do_connect error!\n");
    BIO_free_all(bio);
    return -2;
  }
  strcat(request_str, "PUT /share/test.txt HTTP/1.1\r\n");
  strcat(request_str, "Host: bgstation0.com:80\r\n");
  strcat(request_str, "Content-Length: 9\r\n");
  strcat(request_str, "Content-Type: text/plain\r\n");
  strcat(request_str, "\r\n");
  strcat(request_str, "ABCDE\nXYZ");
  request_len = strlen(request_str);
  BIO_write(bio, request_str, request_len);
  while ((response_len = BIO_read(bio, response_buf, 1024 - 1)) > 0) {
    printf("%s", response_buf);
    memset(response_buf, 0, sizeof(char) * 1024);
  }
  BIO_free_all(bio);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movl   $0x0,-0x414(%rbp)
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movl   $0x0,-0x824(%rbp)
lea    0xe15(%rip),%rdi
call   1080 <BIO_new_connect@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1219 <main+0x89>
lea    0xe0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    134a <main+0x1ba>
mov    -0x10(%rbp),%rdi
call   1030 <BIO_do_connect@plt>
cmp    $0x0,%rax
jg     124f <main+0xbf>
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <BIO_free_all@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    134a <main+0x1ba>
lea    -0x410(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
lea    0xded(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x414(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
call   10b0 <BIO_write@plt>
mov    -0x10(%rbp),%rdi
lea    -0x820(%rbp),%rsi
mov    $0x3ff,%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x824(%rbp)
cmp    $0x0,%eax
jle    133a <main+0x1aa>
lea    -0x820(%rbp),%rsi
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
jmp    12e9 <main+0x159>
mov    -0x10(%rbp),%rdi
call   1090 <BIO_free_all@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
lea    0x400(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe2a(%rip),%rdi
call   1090 <BIO_new_connect@plt>
test   %rax,%rax
je     12cc <main+0x12c>
mov    %rax,%r15
mov    %rax,%rdi
call   1030 <BIO_do_connect@plt>
test   %rax,%rax
jle    12df <main+0x13f>
lea    0xe13(%rip),%rsi
lea    0x400(%rsp),%r14
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe1b(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe26(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe2b(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe05(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
call   10b0 <strcat@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   10c0 <BIO_write@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
mov    $0x3ff,%edx
call   1050 <BIO_read@plt>
test   %eax,%eax
jle    12c0 <main+0x120>
lea    0xdfa(%rip),%r14
mov    %rsp,%rbx
nopl   (%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3ff,%edx
call   1050 <BIO_read@plt>
test   %eax,%eax
jg     1290 <main+0xf0>
mov    %r15,%rdi
call   10a0 <BIO_free_all@plt>
xor    %eax,%eax
jmp    12f8 <main+0x158>
lea    0xdca(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%eax
jmp    12f8 <main+0x158>
lea    0xda1(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   10a0 <BIO_free_all@plt>
mov    $0xfffffffe,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [18 x i8] c"bgstation0.com:80\00"
@.str.1 = [24 x i8] c"BIO_new_connect error!\0A\00"
@.str.2 = [23 x i8] c"BIO_do_connect error!\0A\00"
@.str.3 = [31 x i8] c"PUT /share/test.txt HTTP/1.1\0D\0A\00"
@.str.4 = [26 x i8] c"Host: bgstation0.com:80\0D\0A\00"
@.str.5 = [20 x i8] c"Content-Length: 9\0D\0A\00"
@.str.6 = [27 x i8] c"Content-Type: text/plain\0D\0A\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [10 x i8] c"ABCDE\0AXYZ\00"
@.str.9 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
store i32 0, i32* %1
store i32* null, i32** %2
%7 = bitcast [1024 x i8]* %3 to i8*
store i32 0, i32* %4
%8 = bitcast [1024 x i8]* %5 to i8*
store i32 0, i32* %6
%9 = call i32* @BIO_new_connect(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %54
14: ; preds = %0
%15 = load i32*, i32** %2
%16 = call i64 @BIO_do_connect(i32* %15)
%17 = icmp sle i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32*, i32** %2
%21 = call i32 @BIO_free_all(i32* %20)
store i32 -2, i32* %1
br label %54
22: ; preds = %14
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%26 = call i32 @strcat(i8* %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %4
%37 = load i32*, i32** %2
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%39 = load i32, i32* %4
%40 = call i32 @BIO_write(i32* %37, i8* %38, i32 %39)
br label %41
41: ; preds = %46, %22
%42 = load i32*, i32** %2
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%44 = call i32 @BIO_read(i32* %42, i8* %43, i32 1023)
store i32 %44, i32* %6
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %41
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %47)
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%50 = call i32 @memset(i8* %49, i32 0, i32 1024)
br label %41
51: ; preds = %41
%52 = load i32*, i32** %2
%53 = call i32 @BIO_free_all(i32* %52)
store i32 0, i32* %1
br label %54
54: ; preds = %51, %18, %12
%55 = load i32, i32* %1
ret i32 %55
}

LLVM IR (-O2):
@.str = [18 x i8] c"bgstation0.com:80\00"
@.str.3 = [31 x i8] c"PUT /share/test.txt HTTP/1.1\0D\0A\00"
@.str.4 = [26 x i8] c"Host: bgstation0.com:80\0D\0A\00"
@.str.5 = [20 x i8] c"Content-Length: 9\0D\0A\00"
@.str.6 = [27 x i8] c"Content-Type: text/plain\0D\0A\00"
@.str.7 = [3 x i8] c"\0D\0A\00"
@.str.8 = [10 x i8] c"ABCDE\0AXYZ\00"
@.str.9 = [3 x i8] c"%s\00"
@str = [22 x i8] c"BIO_do_connect error!\00"
@str.10 = [23 x i8] c"BIO_new_connect error!\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @BIO_new_connect(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.10, i64 0, i64 0))
br label %33
9: ; preds = %0
%10 = tail call i64 @BIO_do_connect(i32* %5)
%11 = icmp slt i64 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @BIO_free_all(i32* %5)
br label %33
15: ; preds = %9
%16 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%18 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 @strcat(i8* %3, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%22 = call i32 @strlen(i8* %3)
%23 = call i32 @BIO_write(i32* %5, i8* %3, i32 %22)
%24 = call i32 @BIO_read(i32* %5, i8* %4, i32 1023)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %15, %26
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* %4)
%28 = call i32 @memset(i8* %4, i32 0, i32 1024)
%29 = call i32 @BIO_read(i32* %5, i8* %4, i32 1023)
%30 = icmp sgt i32 %29, 0
br i1 %30, label %26, label %31
31: ; preds = %26, %15
%32 = call i32 @BIO_free_all(i32* %5)
br label %33
33: ; preds = %31, %12, %7
%34 = phi i32 [ -1, %7 ], [ -2, %12 ], [ 0, %31 ]
ret i32 %34
}