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

/* Variables and functions */
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ ERR_load_BIO_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_do_handshake(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ SSL_load_error_strings();
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_accept_state(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_bio(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *);
int /*<<< orphan*/ TLSv1_method();
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  unsigned char buf[4096];
  FILE *f;
  int r;
  SSL_CTX *sctx;
  SSL *server;
  BIO *sinbio, *soutbio;
  SSL_library_init();
  SSL_load_error_strings();
  ERR_load_BIO_strings();
  OpenSSL_add_all_algorithms();
  if (!(sctx = SSL_CTX_new(TLSv1_method())))
    return 1;
  if (!(server = SSL_new(sctx)))
    return 1;
  sinbio = BIO_new(BIO_s_mem());
  soutbio = BIO_new(BIO_s_mem());
  SSL_set_bio(server, sinbio, soutbio);
  SSL_set_accept_state(server);
  f = fopen("ssl3-packet", "rb");
  r = fread(buf, 1, 4096, f);
  BIO_write(sinbio, buf, r);
  SSL_do_handshake(server);
  ERR_print_errors_fp(stderr);
  SSL_do_handshake(server);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <SSL_library_init@plt>
mov    $0x0,%al
call   10c0 <SSL_load_error_strings@plt>
mov    $0x0,%al
call   1100 <ERR_load_BIO_strings@plt>
mov    $0x0,%al
call   1060 <OpenSSL_add_all_algorithms@plt>
mov    $0x0,%al
call   1070 <TLSv1_method@plt>
mov    %eax,%edi
call   1080 <SSL_CTX_new@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    1260 <main+0x60>
movl   $0x1,-0x4(%rbp)
jmp    135c <main+0x15c>
mov    -0x1028(%rbp),%rdi
call   1050 <SSL_new@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
jne    1289 <main+0x89>
movl   $0x1,-0x4(%rbp)
jmp    135c <main+0x15c>
mov    $0x0,%al
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,-0x1038(%rbp)
mov    $0x0,%al
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,-0x1040(%rbp)
mov    -0x1030(%rbp),%rdi
mov    -0x1038(%rbp),%rsi
mov    -0x1040(%rbp),%rdx
call   1120 <SSL_set_bio@plt>
mov    -0x1030(%rbp),%rdi
call   1090 <SSL_set_accept_state@plt>
lea    0xd20(%rip),%rdi
lea    0xd25(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x1018(%rbp)
lea    -0x1010(%rbp),%rdi
mov    -0x1018(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x101c(%rbp)
mov    -0x1038(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    -0x101c(%rbp),%edx
call   10d0 <BIO_write@plt>
mov    -0x1030(%rbp),%rdi
call   10f0 <SSL_do_handshake@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   10e0 <ERR_print_errors_fp@plt>
mov    -0x1030(%rbp),%rdi
call   10f0 <SSL_do_handshake@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
xor    %eax,%eax
call   1040 <SSL_library_init@plt>
xor    %eax,%eax
call   10c0 <SSL_load_error_strings@plt>
xor    %eax,%eax
call   1100 <ERR_load_BIO_strings@plt>
xor    %eax,%eax
call   1060 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
call   1070 <TLSv1_method@plt>
mov    %eax,%edi
call   1080 <SSL_CTX_new@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     12e6 <main+0xe6>
mov    %rax,%rdi
call   1050 <SSL_new@plt>
test   %rax,%rax
je     12e6 <main+0xe6>
mov    %rax,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1110 <BIO_s_mem@plt>
mov    %eax,%edi
call   10a0 <BIO_new@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rax,%rdx
call   1120 <SSL_set_bio@plt>
mov    %rbx,%rdi
call   1090 <SSL_set_accept_state@plt>
lea    0xd69(%rip),%rdi
lea    0xd6e(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   10d0 <BIO_write@plt>
mov    %rbx,%rdi
call   10f0 <SSL_do_handshake@plt>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
call   10e0 <ERR_print_errors_fp@plt>
mov    %rbx,%rdi
call   10f0 <SSL_do_handshake@plt>
mov    %ebp,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"ssl3-packet\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (...) @SSL_library_init()
%14 = call i32 (...) @SSL_load_error_strings()
%15 = call i32 (...) @ERR_load_BIO_strings()
%16 = call i32 (...) @OpenSSL_add_all_algorithms()
%17 = call i32 (...) @TLSv1_method()
%18 = call i32* @SSL_CTX_new(i32 %17)
store i32* %18, i32** %9
%19 = icmp ne i32* %18, null
br i1 %19, label %21, label %20
20: ; preds = %2
store i32 1, i32* %3
br label %51
21: ; preds = %2
%22 = load i32*, i32** %9
%23 = call i32* @SSL_new(i32* %22)
store i32* %23, i32** %10
%24 = icmp ne i32* %23, null
br i1 %24, label %26, label %25
25: ; preds = %21
store i32 1, i32* %3
br label %51
26: ; preds = %21
%27 = call i32 (...) @BIO_s_mem()
%28 = call i32* @BIO_new(i32 %27)
store i32* %28, i32** %11
%29 = call i32 (...) @BIO_s_mem()
%30 = call i32* @BIO_new(i32 %29)
store i32* %30, i32** %12
%31 = load i32*, i32** %10
%32 = load i32*, i32** %11
%33 = load i32*, i32** %12
%34 = call i32 @SSL_set_bio(i32* %31, i32* %32, i32* %33)
%35 = load i32*, i32** %10
%36 = call i32 @SSL_set_accept_state(i32* %35)
%37 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %7
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%39 = load i32*, i32** %7
%40 = call i32 @fread(i8* %38, i32 1, i32 4096, i32* %39)
store i32 %40, i32* %8
%41 = load i32*, i32** %11
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%43 = load i32, i32* %8
%44 = call i32 @BIO_write(i32* %41, i8* %42, i32 %43)
%45 = load i32*, i32** %10
%46 = call i32 @SSL_do_handshake(i32* %45)
%47 = load i32, i32* @stderr
%48 = call i32 @ERR_print_errors_fp(i32 %47)
%49 = load i32*, i32** %10
%50 = call i32 @SSL_do_handshake(i32* %49)
store i32 0, i32* %3
br label %51
51: ; preds = %26, %25, %20
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [12 x i8] c"ssl3-packet\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (...) @SSL_library_init()
%6 = tail call i32 (...) @SSL_load_error_strings()
%7 = tail call i32 (...) @ERR_load_BIO_strings()
%8 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%9 = tail call i32 (...) @TLSv1_method()
%10 = tail call i32* @SSL_CTX_new(i32 %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %29, label %12
12: ; preds = %2
%13 = tail call i32* @SSL_new(i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %29, label %15
15: ; preds = %12
%16 = tail call i32 (...) @BIO_s_mem()
%17 = tail call i32* @BIO_new(i32 %16)
%18 = tail call i32 (...) @BIO_s_mem()
%19 = tail call i32* @BIO_new(i32 %18)
%20 = tail call i32 @SSL_set_bio(i32* %13, i32* %17, i32* %19)
%21 = tail call i32 @SSL_set_accept_state(i32* %13)
%22 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @fread(i8* %4, i32 1, i32 4096, i32* %22)
%24 = call i32 @BIO_write(i32* %17, i8* %4, i32 %23)
%25 = call i32 @SSL_do_handshake(i32* %13)
%26 = load i32, i32* @stderr
%27 = call i32 @ERR_print_errors_fp(i32 %26)
%28 = call i32 @SSL_do_handshake(i32* %13)
br label %29
29: ; preds = %12, %2, %15
%30 = phi i32 [ 0, %15 ], [ 1, %2 ], [ 1, %12 ]
ret i32 %30
}