#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ val;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_LOOPBACK;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ do_accept(int /*<<< orphan*/ *);
scalar_t__ do_shutdown(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ ns_set_non_blocking_mode(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ *setup_ctx(char const *, char const *, char const *,
                              char const *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int /*<<< orphan*/ test_content(int /*<<< orphan*/ *);
int do_test(const char *cert_file, const char *key_file, const char *ca_file,
            const char *cipher) {
  struct sockaddr_in sa;
  socklen_t slen;
  SSL_CTX *ctx;
  SSL *ssl;
  int ret = 0;
  int fd, cfd;
  ctx = setup_ctx(cert_file, key_file, ca_file, cipher);
  if (NULL == ctx)
    goto out;
  ssl = SSL_new(ctx);
  if (NULL == ssl)
    goto out_ctx;
  fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (fd < 0) {
    fprintf(stderr, "socket: %s\n", strerror(errno));
    goto out_ssl;
  }
  do {
    int val = 1;
    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
  } while (0);
  sa.sin_family = AF_INET;
  sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
  sa.sin_port = htons(4343);
  if (bind(fd, (struct sockaddr *)&sa, sizeof(sa))) {
    fprintf(stderr, "bind: %s\n", strerror(errno));
    goto out_close;
  }
  if (listen(fd, 128)) {
    fprintf(stderr, "bind: %s\n", strerror(errno));
    goto out_close;
  }
  slen = sizeof(sa);
  printf("Waiting for a connection...\n");
  cfd = accept(fd, (struct sockaddr *)&sa, &slen);
  if (cfd < 0) {
    fprintf(stderr, "accept: %s\n", strerror(errno));
    goto out_close;
  }
  ns_set_non_blocking_mode(cfd);
  if (!SSL_set_fd(ssl, cfd))
    goto out_close_cl;
  printf("Got connection\n");
  if (do_accept(ssl) <= 0) {
    goto shutdown;
  }
  if (!test_content(ssl)) {
    goto shutdown;
  }
  ret = 1;
shutdown:
  if (do_shutdown(ssl) > 0 && ret) {
    printf("SUCCESS\n");
  } else {
    printf("shutdown failed\n");
    ret = 0;
  }
out_close_cl:
  close(cfd);
out_close:
  close(fd);
out_ssl:
  SSL_free(ssl);
out_ctx:
  SSL_CTX_free(ctx);
out:
  return ret;
}


x86 assembly (clang, -O0):
<do_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1040 <setup_ctx@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
jne    1289 <do_test+0x49>
jmp    1520 <do_test+0x2e0>
mov    -0x40(%rbp),%rdi
call   10c0 <SSL_new@plt>
mov    %rax,-0x48(%rbp)
xor    %eax,%eax
cmp    -0x48(%rbp),%rax
jne    12a7 <do_test+0x67>
jmp    1517 <do_test+0x2d7>
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
mov    0x2d18(%rip),%rax
mov    (%rax),%edx
call   1160 <socket@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    1305 <do_test+0xc5>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    %rax,%rdx
lea    0xd05(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    150e <do_test+0x2ce>
jmp    130a <do_test+0xca>
movl   $0x1,-0x58(%rbp)
mov    -0x50(%rbp),%edi
mov    0x2ccd(%rip),%rax
mov    (%rax),%esi
mov    0x2c7c(%rip),%rax
mov    (%rax),%edx
lea    -0x58(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
mov    0x2ca4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2c88(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x10f7,%edi
call   1080 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
je     13ab <do_test+0x16b>
mov    0x2c3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2c23(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xc6b(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1506 <do_test+0x2c6>
mov    -0x50(%rbp),%edi
mov    $0x80,%esi
call   10f0 <listen@plt>
cmp    $0x0,%rax
je     13f3 <do_test+0x1b3>
mov    0x2bf7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xc23(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1506 <do_test+0x2c6>
movl   $0xc,-0x34(%rbp)
lea    0xc15(%rip),%rdi
call   1090 <printf@plt>
mov    -0x50(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1130 <accept@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1454 <do_test+0x214>
mov    0x2b96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xbe9(%rip),%rsi
call   10d0 <fprintf@plt>
jmp    1506 <do_test+0x2c6>
mov    -0x54(%rbp),%edi
call   1030 <ns_set_non_blocking_mode@plt>
mov    -0x48(%rbp),%rdi
mov    -0x54(%rbp),%esi
call   1070 <SSL_set_fd@plt>
cmp    $0x0,%eax
jne    1476 <do_test+0x236>
jmp    14fe <do_test+0x2be>
lea    0xbc2(%rip),%rdi
call   1090 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1120 <do_accept@plt>
cmp    $0x0,%rax
jg     149a <do_test+0x25a>
jmp    14b8 <do_test+0x278>
mov    -0x48(%rbp),%rdi
call   1150 <test_content@plt>
cmp    $0x0,%eax
jne    14b1 <do_test+0x271>
jmp    14b8 <do_test+0x278>
movl   $0x1,-0x4c(%rbp)
mov    -0x48(%rbp),%rdi
call   10e0 <do_shutdown@plt>
cmp    $0x0,%rax
jle    14e6 <do_test+0x2a6>
cmpl   $0x0,-0x4c(%rbp)
je     14e6 <do_test+0x2a6>
lea    0xb73(%rip),%rdi
call   1090 <printf@plt>
jmp    14f9 <do_test+0x2b9>
lea    0xb6b(%rip),%rdi
call   1090 <printf@plt>
movl   $0x0,-0x4c(%rbp)
jmp    14fe <do_test+0x2be>
mov    -0x54(%rbp),%edi
call   10b0 <close@plt>
mov    -0x50(%rbp),%edi
call   10b0 <close@plt>
mov    -0x48(%rbp),%rdi
call   1060 <SSL_free@plt>
mov    -0x40(%rbp),%rdi
call   1110 <SSL_CTX_free@plt>
mov    -0x4c(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
call   1040 <setup_ctx@plt>
test   %rax,%rax
je     1351 <do_test+0x111>
mov    %rax,%rbx
mov    %rax,%rdi
call   10c0 <SSL_new@plt>
test   %rax,%rax
je     1355 <do_test+0x115>
mov    %rax,%r14
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    0x2d4e(%rip),%rax
mov    (%rax),%edx
call   1160 <socket@plt>
test   %eax,%eax
js     1359 <do_test+0x119>
mov    %eax,%r12d
movl   $0x1,(%rsp)
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
mov    0x2ced(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
mov    0x2d13(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x10f7,%edi
call   1090 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   1100 <bind@plt>
test   %rax,%rax
jne    131d <do_test+0xdd>
mov    %r12d,%edi
mov    $0x80,%esi
call   10f0 <listen@plt>
test   %rax,%rax
je     13a2 <do_test+0x162>
mov    0x2c9c(%rip),%rax
mov    (%rax),%ebp
mov    0x2c83(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xcd1(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10d0 <fprintf@plt>
xor    %ebp,%ebp
mov    %r12d,%edi
call   10b0 <close@plt>
jmp    1383 <do_test+0x143>
xor    %ebp,%ebp
jmp    1393 <do_test+0x153>
xor    %ebp,%ebp
jmp    138b <do_test+0x14b>
mov    0x2c60(%rip),%rax
mov    (%rax),%ebp
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xc89(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   10d0 <fprintf@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
call   1070 <SSL_free@plt>
mov    %rbx,%rdi
call   1110 <SSL_CTX_free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movl   $0xc,0xc(%rsp)
lea    0xc71(%rip),%rdi
call   1050 <puts@plt>
mov    %rsp,%rsi
lea    0xc(%rsp),%rdx
mov    %r12d,%edi
call   1130 <accept@plt>
test   %eax,%eax
js     1425 <do_test+0x1e5>
mov    %eax,%r15d
mov    %eax,%edi
call   1030 <ns_set_non_blocking_mode@plt>
mov    %r14,%rdi
mov    %r15d,%esi
call   1080 <SSL_set_fd@plt>
test   %eax,%eax
je     1448 <do_test+0x208>
lea    0xc54(%rip),%rdi
call   1050 <puts@plt>
mov    %r14,%rdi
call   1120 <do_accept@plt>
mov    %r14,%rdi
test   %rax,%rax
jle    144c <do_test+0x20c>
call   1150 <test_content@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   10e0 <do_shutdown@plt>
test   %ebp,%ebp
je     1451 <do_test+0x211>
test   %rax,%rax
jle    1451 <do_test+0x211>
mov    $0x1,%ebp
lea    0xc3a(%rip),%rdi
jmp    145a <do_test+0x21a>
mov    0x2b94(%rip),%rax
mov    (%rax),%ebp
mov    0x2b7b(%rip),%rax
mov    (%rax),%edi
call   1140 <strerror@plt>
lea    0xbd3(%rip),%rsi
jmp    133b <do_test+0xfb>
xor    %ebp,%ebp
jmp    145f <do_test+0x21f>
call   10e0 <do_shutdown@plt>
xor    %ebp,%ebp
lea    0xbf3(%rip),%rdi
call   1050 <puts@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
jmp    1347 <do_test+0x107>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@.str.1 = [10 x i8] c"bind: %s\0A\00"
@.str.2 = [29 x i8] c"Waiting for a connection...\0A\00"
@.str.3 = [12 x i8] c"accept: %s\0A\00"
@.str.4 = [16 x i8] c"Got connection\0A\00"
@.str.5 = [9 x i8] c"SUCCESS\0A\00"
@.str.6 = [17 x i8] c"shutdown failed\0A\00"
define i32 @do_test(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
store i32 0, i32* %13
%17 = load i8*, i8** %5
%18 = load i8*, i8** %6
%19 = load i8*, i8** %7
%20 = load i8*, i8** %8
%21 = call i32* @setup_ctx(i8* %17, i8* %18, i8* %19, i8* %20)
store i32* %21, i32** %11
%22 = load i32*, i32** %11
%23 = icmp eq i32* null, %22
br i1 %23, label %24, label %25
24: ; preds = %4
br label %132
25: ; preds = %4
%26 = load i32*, i32** %11
%27 = call i32* @SSL_new(i32* %26)
store i32* %27, i32** %12
%28 = load i32*, i32** %12
%29 = icmp eq i32* null, %28
br i1 %29, label %30, label %31
30: ; preds = %25
br label %129
31: ; preds = %25
%32 = load i32, i32* @PF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = load i32, i32* @IPPROTO_TCP
%35 = call i32 @socket(i32 %32, i32 %33, i32 %34)
store i32 %35, i32* %14
%36 = load i32, i32* %14
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %41)
br label %126
43: ; preds = %31
br label %44
44: ; preds = %43
store i32 1, i32* %16
%45 = load i32, i32* %14
%46 = load i32, i32* @SOL_SOCKET
%47 = load i32, i32* @SO_REUSEADDR
%48 = call i32 @setsockopt(i32 %45, i32 %46, i32 %47, i32* %16, i32 4)
br label %49
49: ; preds = %44
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* @INADDR_LOOPBACK
%53 = call i32 @htonl(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
store i32 %53, i32* %55
%56 = call i32 @htons(i32 4343)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %56, i32* %57
%58 = load i32, i32* %14
%59 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%60 = call i64 @bind(i32 %58, %struct.sockaddr* %59, i32 12)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %49
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %65)
br label %123
67: ; preds = %49
%68 = load i32, i32* %14
%69 = call i64 @listen(i32 %68, i32 128)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %76
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = load i32, i32* @errno
%74 = call i8* @strerror(i32 %73)
%75 = call i32 @fprintf(i32 %72, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %74)
br label %123
76: ; preds = %67
store i32 12, i32* %10
%77 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%78 = load i32, i32* %14
%79 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%80 = call i32 @accept(i32 %78, %struct.sockaddr* %79, i32* %10)
store i32 %80, i32* %15
%81 = load i32, i32* %15
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %88
83: ; preds = %76
%84 = load i32, i32* @stderr
%85 = load i32, i32* @errno
%86 = call i8* @strerror(i32 %85)
%87 = call i32 @fprintf(i32 %84, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %86)
br label %123
88: ; preds = %76
%89 = load i32, i32* %15
%90 = call i32 @ns_set_non_blocking_mode(i32 %89)
%91 = load i32*, i32** %12
%92 = load i32, i32* %15
%93 = call i32 @SSL_set_fd(i32* %91, i32 %92)
%94 = icmp ne i32 %93, 0
br i1 %94, label %96, label %95
95: ; preds = %88
br label %120
96: ; preds = %88
%97 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%98 = load i32*, i32** %12
%99 = call i64 @do_accept(i32* %98)
%100 = icmp sle i64 %99, 0
br i1 %100, label %101, label %102
101: ; preds = %96
br label %108
102: ; preds = %96
%103 = load i32*, i32** %12
%104 = call i32 @test_content(i32* %103)
%105 = icmp ne i32 %104, 0
br i1 %105, label %107, label %106
106: ; preds = %102
br label %108
107: ; preds = %102
store i32 1, i32* %13
br label %108
108: ; preds = %107, %106, %101
%109 = load i32*, i32** %12
%110 = call i64 @do_shutdown(i32* %109)
%111 = icmp sgt i64 %110, 0
br i1 %111, label %112, label %117
112: ; preds = %108
%113 = load i32, i32* %13
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %112
%116 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
br label %119
117: ; preds = %112, %108
%118 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %13
br label %119
119: ; preds = %117, %115
br label %120
120: ; preds = %119, %95
%121 = load i32, i32* %15
%122 = call i32 @close(i32 %121)
br label %123
123: ; preds = %120, %83, %71, %62
%124 = load i32, i32* %14
%125 = call i32 @close(i32 %124)
br label %126
126: ; preds = %123, %38
%127 = load i32*, i32** %12
%128 = call i32 @SSL_free(i32* %127)
br label %129
129: ; preds = %126, %30
%130 = load i32*, i32** %11
%131 = call i32 @SSL_CTX_free(i32* %130)
br label %132
132: ; preds = %129, %24
%133 = load i32, i32* %13
ret i32 %133
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [12 x i8] c"socket: %s\0A\00"
@errno = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@AF_INET = global i32 0
@INADDR_LOOPBACK = global i32 0
@.str.1 = [10 x i8] c"bind: %s\0A\00"
@.str.3 = [12 x i8] c"accept: %s\0A\00"
@str = [28 x i8] c"Waiting for a connection...\00"
@str.7 = [15 x i8] c"Got connection\00"
@str.8 = [16 x i8] c"shutdown failed\00"
@str.9 = [8 x i8] c"SUCCESS\00"
define i32 @do_test(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = tail call i32* @setup_ctx(i8* %0, i8* %1, i8* %2, i8* %3)
%11 = icmp eq i32* %10, null
br i1 %11, label %96, label %12
12: ; preds = %4
%13 = tail call i32* @SSL_new(i32* %10)
%14 = icmp eq i32* %13, null
br i1 %14, label %93, label %15
15: ; preds = %12
%16 = load i32, i32* @PF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = load i32, i32* @IPPROTO_TCP
%19 = tail call i32 @socket(i32 %16, i32 %17, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = load i32, i32* @errno
%24 = tail call i8* @strerror(i32 %23)
%25 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %24)
br label %90
26: ; preds = %15
%27 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%28 = load i32, i32* @SOL_SOCKET
%29 = load i32, i32* @SO_REUSEADDR
%30 = call i32 @setsockopt(i32 %19, i32 %28, i32 %29, i32* %7, i32 4)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_LOOPBACK
%34 = call i32 @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %34, i32* %35
%36 = call i32 @htons(i32 4343)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %36, i32* %37
%38 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%39 = call i64 @bind(i32 %19, %struct.sockaddr* %38, i32 12)
%40 = icmp eq i64 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %26
%42 = load i32, i32* @stderr
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %87
46: ; preds = %26
%47 = call i64 @listen(i32 %19, i32 128)
%48 = icmp eq i64 %47, 0
br i1 %48, label %54, label %49
49: ; preds = %46
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %52)
br label %87
54: ; preds = %46
store i32 12, i32* %6
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%56 = call i32 @accept(i32 %19, %struct.sockaddr* %38, i32* %6)
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i32, i32* @errno
%61 = call i8* @strerror(i32 %60)
%62 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %61)
br label %87
63: ; preds = %54
%64 = call i32 @ns_set_non_blocking_mode(i32 %56)
%65 = call i32 @SSL_set_fd(i32* %13, i32 %56)
%66 = icmp eq i32 %65, 0
br i1 %66, label %84, label %67
67: ; preds = %63
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0))
%69 = call i64 @do_accept(i32* %13)
%70 = icmp slt i64 %69, 1
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i64 @do_shutdown(i32* %13)
br label %79
73: ; preds = %67
%74 = call i32 @test_content(i32* %13)
%75 = icmp ne i32 %74, 0
%76 = call i64 @do_shutdown(i32* %13)
%77 = icmp sgt i64 %76, 0
%78 = and i1 %75, %77
br i1 %78, label %80, label %79
79: ; preds = %71, %73
br label %80
80: ; preds = %73, %79
%81 = phi i8* [ getelementptr inbounds ([16 x i8], [16 x i8]* @str.8, i64 0, i64 0), %79 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.9, i64 0, i64 0), %73 ]
%82 = phi i32 [ 0, %79 ], [ 1, %73 ]
%83 = call i32 @puts(i8* dereferenceable(1) %81)
br label %84
84: ; preds = %80, %63
%85 = phi i32 [ 0, %63 ], [ %82, %80 ]
%86 = call i32 @close(i32 %56)
br label %87
87: ; preds = %84, %58, %49, %41
%88 = phi i32 [ 0, %41 ], [ 0, %49 ], [ 0, %58 ], [ %85, %84 ]
%89 = call i32 @close(i32 %19)
br label %90
90: ; preds = %87, %21
%91 = phi i32 [ 0, %21 ], [ %88, %87 ]
%92 = call i32 @SSL_free(i32* %13)
br label %93
93: ; preds = %12, %90
%94 = phi i32 [ 0, %12 ], [ %91, %90 ]
%95 = call i32 @SSL_CTX_free(i32* %10)
br label %96
96: ; preds = %4, %93
%97 = phi i32 [ 0, %4 ], [ %94, %93 ]
ret i32 %97
}