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

/* Variables and functions */
scalar_t__ BIO_do_accept(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_accept(char *);
int /*<<< orphan*/ *BIO_new_ssl(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_pop(int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ BIO_set_accept_bios(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/ *);
scalar_t__ BIO_should_retry(int /*<<< orphan*/ *);
scalar_t__ CONF_modules_load_file(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ SSL_CTX_config(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ TLS_server_method();
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  unsigned char buf[512];
  char *port = "*:4433";
  BIO *in = NULL;
  BIO *ssl_bio, *tmp;
  SSL_CTX *ctx;
  int ret = EXIT_FAILURE, i;
  ctx = SSL_CTX_new(TLS_server_method());
  if (CONF_modules_load_file("cmod.cnf", "testapp", 0) <= 0) {
    fprintf(stderr, "Error processing config file\n");
    goto err;
  }
  if (SSL_CTX_config(ctx, "server") == 0) {
    fprintf(stderr, "Error configuring server.\n");
    goto err;
  }
  ssl_bio = BIO_new_ssl(ctx, 0);
  if ((in = BIO_new_accept(port)) == NULL)
    goto err;
  BIO_set_accept_bios(in, ssl_bio);
again:
  if (BIO_do_accept(in) <= 0)
    goto err;
  for (;;) {
    i = BIO_read(in, buf, sizeof(buf));
    if (i == 0) {
      printf("Done\n");
      tmp = BIO_pop(in);
      BIO_free_all(tmp);
      goto again;
    }
    if (i < 0) {
      if (BIO_should_retry(in))
        continue;
      goto err;
    }
    fwrite(buf, 1, i, stdout);
    fflush(stdout);
  }
  ret = EXIT_SUCCESS;
err:
  if (ret != EXIT_SUCCESS)
    ERR_print_errors_fp(stderr);
  BIO_free(in);
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdc0(%rip),%rax
mov    %rax,-0x218(%rbp)
movq   $0x0,-0x220(%rbp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x23c(%rbp)
mov    $0x0,%al
call   1040 <TLS_server_method@plt>
mov    %eax,%edi
call   10d0 <SSL_CTX_new@plt>
mov    %rax,-0x238(%rbp)
lea    0xd8a(%rip),%rdi
lea    0xd8c(%rip),%rsi
xor    %edx,%edx
call   1030 <CONF_modules_load_file@plt>
cmp    $0x0,%rax
jg     12af <main+0x8f>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
lea    0xd73(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    140b <main+0x1eb>
mov    -0x238(%rbp),%rdi
lea    0xd79(%rip),%rsi
call   10a0 <SSL_CTX_config@plt>
cmp    $0x0,%rax
jne    12e6 <main+0xc6>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    140b <main+0x1eb>
mov    -0x238(%rbp),%rdi
xor    %esi,%esi
call   1090 <BIO_new_ssl@plt>
mov    %rax,-0x228(%rbp)
mov    -0x218(%rbp),%rdi
call   1050 <BIO_new_accept@plt>
mov    %rax,-0x220(%rbp)
cmp    $0x0,%rax
jne    131d <main+0xfd>
jmp    140b <main+0x1eb>
mov    -0x220(%rbp),%rdi
mov    -0x228(%rbp),%rsi
call   1060 <BIO_set_accept_bios@plt>
mov    -0x220(%rbp),%rdi
call   1100 <BIO_do_accept@plt>
cmp    $0x0,%rax
jg     134b <main+0x12b>
jmp    140b <main+0x1eb>
jmp    1350 <main+0x130>
mov    -0x220(%rbp),%rdi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1070 <BIO_read@plt>
mov    %eax,-0x240(%rbp)
cmpl   $0x0,-0x240(%rbp)
jne    13ab <main+0x18b>
lea    0xcd6(%rip),%rdi
call   1080 <printf@plt>
mov    -0x220(%rbp),%rdi
call   10b0 <BIO_pop@plt>
mov    %rax,-0x230(%rbp)
mov    -0x230(%rbp),%rdi
call   1110 <BIO_free_all@plt>
jmp    1330 <main+0x110>
cmpl   $0x0,-0x240(%rbp)
jge    13d8 <main+0x1b8>
mov    -0x220(%rbp),%rdi
call   1130 <BIO_should_retry@plt>
cmp    $0x0,%rax
je     13d3 <main+0x1b3>
jmp    1350 <main+0x130>
jmp    140b <main+0x1eb>
lea    -0x210(%rbp),%rdi
mov    -0x240(%rbp),%edx
mov    0x2be4(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1120 <fwrite@plt>
mov    0x2bd1(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
jmp    1350 <main+0x130>
mov    -0x23c(%rbp),%eax
mov    0x2bb0(%rip),%rcx
cmp    (%rcx),%eax
je     142e <main+0x20e>
mov    0x2bb9(%rip),%rax
mov    (%rax),%edi
call   1140 <ERR_print_errors_fp@plt>
mov    -0x220(%rbp),%rdi
call   10f0 <BIO_free@plt>
mov    -0x23c(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    0x2da2(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1040 <TLS_server_method@plt>
mov    %eax,%edi
call   10d0 <SSL_CTX_new@plt>
mov    %rax,%rbx
lea    0xdb6(%rip),%rdi
lea    0xdb8(%rip),%rsi
xor    %edx,%edx
call   1030 <CONF_modules_load_file@plt>
test   %rax,%rax
jle    134a <main+0x12a>
lea    0xdc7(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <SSL_CTX_config@plt>
test   %rax,%rax
je     1353 <main+0x133>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <BIO_new_ssl@plt>
mov    %rax,%rbp
lea    0xd6c(%rip),%rdi
call   1060 <BIO_new_accept@plt>
test   %rax,%rax
je     1368 <main+0x148>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rbp,%rsi
call   1070 <BIO_set_accept_bios@plt>
mov    %rbx,%rdi
call   1100 <BIO_do_accept@plt>
test   %rax,%rax
jle    136a <main+0x14a>
mov    %rsp,%rbp
lea    0xd8d(%rip),%r15
mov    0x2cfe(%rip),%r12
jmp    12fc <main+0xdc>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r12),%ecx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1120 <fwrite@plt>
mov    (%r12),%edi
call   10e0 <fflush@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1080 <BIO_read@plt>
test   %eax,%eax
je     1323 <main+0x103>
test   %eax,%eax
jns    12e0 <main+0xc0>
mov    %rbx,%rdi
call   1130 <BIO_should_retry@plt>
test   %rax,%rax
jne    12fc <main+0xdc>
jmp    136a <main+0x14a>
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   10b0 <BIO_pop@plt>
mov    %rax,%rdi
call   1110 <BIO_free_all@plt>
mov    %rbx,%rdi
call   1100 <BIO_do_accept@plt>
test   %rax,%rax
jg     12fc <main+0xdc>
jmp    136a <main+0x14a>
lea    0xcc7(%rip),%rsi
jmp    135a <main+0x13a>
lea    0xce3(%rip),%rsi
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   10c0 <fprintf@plt>
xor    %ebx,%ebx
mov    0x2c57(%rip),%rax
cmp    (%rax),%r14d
je     1384 <main+0x164>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
call   1140 <ERR_print_errors_fp@plt>
mov    %rbx,%rdi
call   10f0 <BIO_free@plt>
mov    %r14d,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"*:4433\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"cmod.cnf\00"
@.str.2 = [8 x i8] c"testapp\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"Error processing config file\0A\00"
@.str.4 = [7 x i8] c"server\00"
@.str.5 = [27 x i8] c"Error configuring server.\0A\00"
@.str.6 = [6 x i8] c"Done\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %7
store i32* null, i32** %8
%14 = load i32, i32* @EXIT_FAILURE
store i32 %14, i32* %12
%15 = call i32 (...) @TLS_server_method()
%16 = call i32* @SSL_CTX_new(i32 %15)
store i32* %16, i32** %11
%17 = call i64 @CONF_modules_load_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 0)
%18 = icmp sle i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
br label %74
22: ; preds = %2
%23 = load i32*, i32** %11
%24 = call i64 @SSL_CTX_config(i32* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %74
29: ; preds = %22
%30 = load i32*, i32** %11
%31 = call i32* @BIO_new_ssl(i32* %30, i32 0)
store i32* %31, i32** %9
%32 = load i8*, i8** %7
%33 = call i32* @BIO_new_accept(i8* %32)
store i32* %33, i32** %8
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %36
35: ; preds = %29
br label %74
36: ; preds = %29
%37 = load i32*, i32** %8
%38 = load i32*, i32** %9
%39 = call i32 @BIO_set_accept_bios(i32* %37, i32* %38)
br label %40
40: ; preds = %52, %36
%41 = load i32*, i32** %8
%42 = call i64 @BIO_do_accept(i32* %41)
%43 = icmp sle i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %40
br label %74
45: ; preds = %40
br label %46
46: ; preds = %67, %65, %45
%47 = load i32*, i32** %8
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%49 = call i32 @BIO_read(i32* %47, i8* %48, i32 512)
store i32 %49, i32* %13
%50 = load i32, i32* %13
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %46
%53 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%54 = load i32*, i32** %8
%55 = call i32* @BIO_pop(i32* %54)
store i32* %55, i32** %10
%56 = load i32*, i32** %10
%57 = call i32 @BIO_free_all(i32* %56)
br label %40
58: ; preds = %46
%59 = load i32, i32* %13
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %67
61: ; preds = %58
%62 = load i32*, i32** %8
%63 = call i64 @BIO_should_retry(i32* %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %66
65: ; preds = %61
br label %46
66: ; preds = %61
br label %74
67: ; preds = %58
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%69 = load i32, i32* %13
%70 = load i32, i32* @stdout
%71 = call i32 @fwrite(i8* %68, i32 1, i32 %69, i32 %70)
%72 = load i32, i32* @stdout
%73 = call i32 @fflush(i32 %72)
br label %46
74: ; preds = %66, %44, %35, %26, %19
%75 = load i32, i32* %12
%76 = load i32, i32* @EXIT_SUCCESS
%77 = icmp ne i32 %75, %76
br i1 %77, label %78, label %81
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = call i32 @ERR_print_errors_fp(i32 %79)
br label %81
81: ; preds = %78, %74
%82 = load i32*, i32** %8
%83 = call i32 @BIO_free(i32* %82)
%84 = load i32, i32* %12
ret i32 %84
}

LLVM IR (-O2):
@.str = [7 x i8] c"*:4433\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"cmod.cnf\00"
@.str.2 = [8 x i8] c"testapp\00"
@stderr = global i32 0
@.str.3 = [30 x i8] c"Error processing config file\0A\00"
@.str.4 = [7 x i8] c"server\00"
@.str.5 = [27 x i8] c"Error configuring server.\0A\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [5 x i8] c"Done\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 (...) @TLS_server_method()
%7 = tail call i32* @SSL_CTX_new(i32 %6)
%8 = tail call i64 @CONF_modules_load_file(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 0)
%9 = icmp slt i64 %8, 1
br i1 %9, label %44, label %10
10: ; preds = %2
%11 = tail call i64 @SSL_CTX_config(i32* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %44, label %13
13: ; preds = %10
%14 = tail call i32* @BIO_new_ssl(i32* %7, i32 0)
%15 = tail call i32* @BIO_new_accept(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %48, label %17
17: ; preds = %13
%18 = tail call i32 @BIO_set_accept_bios(i32* %15, i32* %14)
%19 = call i64 @BIO_do_accept(i32* %15)
%20 = icmp slt i64 %19, 1
br i1 %20, label %48, label %21
21: ; preds = %17, %24
%22 = call i32 @BIO_read(i32* %15, i8* %4, i32 512)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %41, %21
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%26 = call i32* @BIO_pop(i32* %15)
%27 = call i32 @BIO_free_all(i32* %26)
%28 = call i64 @BIO_do_accept(i32* %15)
%29 = icmp slt i64 %28, 1
br i1 %29, label %48, label %21
30: ; preds = %21, %41
%31 = phi i32 [ %42, %41 ], [ %22, %21 ]
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = call i64 @BIO_should_retry(i32* %15)
%35 = icmp eq i64 %34, 0
br i1 %35, label %48, label %41
36: ; preds = %30
%37 = load i32, i32* @stdout
%38 = call i32 @fwrite(i8* %4, i32 1, i32 %31, i32 %37)
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
br label %41
41: ; preds = %36, %33
%42 = call i32 @BIO_read(i32* %15, i8* %4, i32 512)
%43 = icmp eq i32 %42, 0
br i1 %43, label %24, label %30
44: ; preds = %10, %2
%45 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), %2 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), %10 ]
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* %45)
br label %48
48: ; preds = %24, %33, %44, %17, %13
%49 = phi i32* [ null, %13 ], [ %15, %17 ], [ null, %44 ], [ %15, %33 ], [ %15, %24 ]
%50 = load i32, i32* @EXIT_SUCCESS
%51 = icmp eq i32 %5, %50
br i1 %51, label %55, label %52
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 @ERR_print_errors_fp(i32 %53)
br label %55
55: ; preds = %52, %48
%56 = call i32 @BIO_free(i32* %49)
ret i32 %5
}