#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*/);
scalar_t__ SSL_CTX_config(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ TLS_server_method();
int /*<<< orphan*/ exit(int);
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 = 1, 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 = 0;
err:
  if (ret) {
    ERR_print_errors_fp(stderr);
  }
  BIO_free(in);
  exit(ret);
  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    0xdb0(%rip),%rax
mov    %rax,-0x218(%rbp)
movq   $0x0,-0x220(%rbp)
movl   $0x1,-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    0xd7f(%rip),%rdi
lea    0xd81(%rip),%rsi
xor    %edx,%edx
call   1030 <CONF_modules_load_file@plt>
cmp    $0x0,%rax
jg     12ba <main+0x8a>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    1416 <main+0x1e6>
mov    -0x238(%rbp),%rdi
lea    0xd6e(%rip),%rsi
call   10a0 <SSL_CTX_config@plt>
cmp    $0x0,%rax
jne    12f1 <main+0xc1>
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    1416 <main+0x1e6>
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    1328 <main+0xf8>
jmp    1416 <main+0x1e6>
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     1356 <main+0x126>
jmp    1416 <main+0x1e6>
jmp    135b <main+0x12b>
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    13b6 <main+0x186>
lea    0xccb(%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    133b <main+0x10b>
cmpl   $0x0,-0x240(%rbp)
jge    13e3 <main+0x1b3>
mov    -0x220(%rbp),%rdi
call   1140 <BIO_should_retry@plt>
cmp    $0x0,%rax
je     13de <main+0x1ae>
jmp    135b <main+0x12b>
jmp    1416 <main+0x1e6>
lea    -0x210(%rbp),%rdi
mov    -0x240(%rbp),%edx
mov    0x2be1(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    0x2bce(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
jmp    135b <main+0x12b>
cmpl   $0x0,-0x23c(%rbp)
je     1431 <main+0x201>
mov    0x2bb6(%rip),%rax
mov    (%rax),%edi
call   1150 <ERR_print_errors_fp@plt>
mov    -0x220(%rbp),%rdi
call   10f0 <BIO_free@plt>
mov    -0x23c(%rbp),%edi
call   1120 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
xor    %eax,%eax
call   1040 <TLS_server_method@plt>
mov    %eax,%edi
call   10d0 <SSL_CTX_new@plt>
mov    %rax,%rbx
lea    0xdb1(%rip),%rdi
lea    0xdb3(%rip),%rsi
xor    %edx,%edx
call   1030 <CONF_modules_load_file@plt>
test   %rax,%rax
jg     1272 <main+0x42>
lea    0xda8(%rip),%rsi
jmp    128d <main+0x5d>
lea    0xdbd(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <SSL_CTX_config@plt>
test   %rax,%rax
jne    12bd <main+0x8d>
lea    0xdb0(%rip),%rsi
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
call   10c0 <fprintf@plt>
xor    %ebx,%ebx
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   1150 <ERR_print_errors_fp@plt>
mov    %rbx,%rdi
call   10f0 <BIO_free@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <BIO_new_ssl@plt>
mov    %rax,%r14
lea    0xd2f(%rip),%rdi
call   1060 <BIO_new_accept@plt>
test   %rax,%rax
je     129b <main+0x6b>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1070 <BIO_set_accept_bios@plt>
mov    %rbx,%rdi
call   1100 <BIO_do_accept@plt>
test   %rax,%rax
jle    129d <main+0x6d>
mov    %rsp,%r14
lea    0xd58(%rip),%r15
mov    0x2cd1(%rip),%r12
jmp    132c <main+0xfc>
nopl   0x0(%rax)
mov    (%r12),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
call   1130 <fwrite@plt>
mov    (%r12),%edi
call   10e0 <fflush@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x200,%edx
call   1080 <BIO_read@plt>
test   %eax,%eax
je     1356 <main+0x126>
test   %eax,%eax
jns    1310 <main+0xe0>
mov    %rbx,%rdi
call   1140 <BIO_should_retry@plt>
test   %rax,%rax
jne    132c <main+0xfc>
jmp    129d <main+0x6d>
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     132c <main+0xfc>
jmp    129d <main+0x6d>

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

LLVM IR (-O2):
@.str = [7 x i8] c"*:4433\00"
@.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
@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 = tail call i32 (...) @TLS_server_method()
%6 = tail call i32* @SSL_CTX_new(i32 %5)
%7 = 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)
%8 = icmp slt i64 %7, 1
br i1 %8, label %43, label %9
9: ; preds = %2
%10 = tail call i64 @SSL_CTX_config(i32* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %43, label %12
12: ; preds = %9
%13 = tail call i32* @BIO_new_ssl(i32* %6, i32 0)
%14 = tail call i32* @BIO_new_accept(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %47, label %16
16: ; preds = %12
%17 = tail call i32 @BIO_set_accept_bios(i32* %14, i32* %13)
%18 = call i64 @BIO_do_accept(i32* %14)
%19 = icmp slt i64 %18, 1
br i1 %19, label %47, label %20
20: ; preds = %16, %23
%21 = call i32 @BIO_read(i32* %14, i8* %4, i32 512)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %40, %20
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%25 = call i32* @BIO_pop(i32* %14)
%26 = call i32 @BIO_free_all(i32* %25)
%27 = call i64 @BIO_do_accept(i32* %14)
%28 = icmp slt i64 %27, 1
br i1 %28, label %47, label %20
29: ; preds = %20, %40
%30 = phi i32 [ %41, %40 ], [ %21, %20 ]
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = call i64 @BIO_should_retry(i32* %14)
%34 = icmp eq i64 %33, 0
br i1 %34, label %47, label %40
35: ; preds = %29
%36 = load i32, i32* @stdout
%37 = call i32 @fwrite(i8* %4, i32 1, i32 %30, i32 %36)
%38 = load i32, i32* @stdout
%39 = call i32 @fflush(i32 %38)
br label %40
40: ; preds = %35, %32
%41 = call i32 @BIO_read(i32* %14, i8* %4, i32 512)
%42 = icmp eq i32 %41, 0
br i1 %42, label %23, label %29
43: ; preds = %9, %2
%44 = 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), %9 ]
%45 = load i32, i32* @stderr
%46 = tail call i32 @fprintf(i32 %45, i8* %44)
br label %47
47: ; preds = %23, %32, %43, %16, %12
%48 = phi i32* [ null, %12 ], [ %14, %16 ], [ null, %43 ], [ %14, %32 ], [ %14, %23 ]
%49 = load i32, i32* @stderr
%50 = call i32 @ERR_print_errors_fp(i32 %49)
%51 = call i32 @BIO_free(i32* %48)
%52 = call i32 @exit(i32 1)
unreachable
}