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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_CTX_new(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_FILETYPE_PEM;
int /*<<< orphan*/ SSL_accept(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_library_init();
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ SSL_shutdown(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_use_PrivateKey_file(int /*<<< orphan*/ *, char *,
                                           int /*<<< orphan*/);
int /*<<< orphan*/ SSL_use_certificate_file(int /*<<< orphan*/ *, char *,
                                            int /*<<< orphan*/);
int /*<<< orphan*/ SSL_write(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ SSLv23_server_method();
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main() {
  char buf[256];
  struct sockaddr_in sock_addr;
  sock_addr.sin_family = AF_INET;
  sock_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  sock_addr.sin_port = htons(31337);
  int listen_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  bind(listen_sock, (struct sockaddr *)&sock_addr, sizeof(sock_addr));
  while (1) {
    listen(listen_sock, SOMAXCONN);
    int data_sock = accept(listen_sock, NULL, NULL);
    SSL_library_init();
    SSL_CTX *ctx = SSL_CTX_new(SSLv23_server_method());
    SSL *ssl = SSL_new(ctx);
    SSL_set_fd(ssl, data_sock);
    SSL_use_certificate_file(ssl, "public.key", SSL_FILETYPE_PEM);
    SSL_use_PrivateKey_file(ssl, "private.crt", SSL_FILETYPE_PEM);
    SSL_accept(ssl);
    while (1) {
      SSL_read(ssl, buf, sizeof(buf));
      buf[sizeof(buf) - 1] = '\0';
      printf("%s\n", buf);
      SSL_write(ssl, buf, strlen(buf));
    }
    SSL_shutdown(ssl);
    SSL_free(ssl);
    SSL_CTX_free(ctx);
    close(data_sock);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,-0x11c(%rbp)
mov    $0x7a69,%edi
call   1080 <htons@plt>
mov    %eax,-0x120(%rbp)
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    0x2d52(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%edi
lea    -0x120(%rbp),%rsi
mov    $0xc,%edx
call   1120 <bind@plt>
mov    -0x124(%rbp),%edi
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
call   1110 <listen@plt>
mov    -0x124(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1130 <accept@plt>
mov    %eax,-0x128(%rbp)
mov    $0x0,%al
call   10b0 <SSL_library_init@plt>
mov    $0x0,%al
call   1050 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1100 <SSL_CTX_new@plt>
mov    %rax,-0x130(%rbp)
mov    -0x130(%rbp),%rdi
call   10d0 <SSL_new@plt>
mov    %rax,-0x138(%rbp)
mov    -0x138(%rbp),%rdi
mov    -0x128(%rbp),%esi
call   1060 <SSL_set_fd@plt>
mov    -0x138(%rbp),%rdi
mov    0x2cc3(%rip),%rax
mov    (%rax),%edx
lea    0xcda(%rip),%rsi
call   1030 <SSL_use_certificate_file@plt>
mov    -0x138(%rbp),%rdi
mov    0x2ca7(%rip),%rax
mov    (%rax),%edx
lea    0xcc9(%rip),%rsi
call   10e0 <SSL_use_PrivateKey_file@plt>
mov    -0x138(%rbp),%rdi
call   10f0 <SSL_accept@plt>
mov    -0x138(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   10c0 <SSL_read@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x110(%rbp),%rsi
lea    0xc9a(%rip),%rdi
call   1090 <printf@plt>
mov    -0x138(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x110(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    -0x140(%rbp),%rsi
mov    %eax,%edx
call   1040 <SSL_write@plt>
jmp    1353 <main+0x133>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    0x2db5(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
call   10a0 <htonl@plt>
mov    %eax,0x4(%rsp)
mov    $0x7a69,%edi
call   1080 <htons@plt>
mov    %eax,(%rsp)
mov    (%rbx),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
mov    0x2d66(%rip),%rax
mov    (%rax),%edx
call   1140 <socket@plt>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0xc,%edx
call   1120 <bind@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1110 <listen@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1130 <accept@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10b0 <SSL_library_init@plt>
xor    %eax,%eax
call   1050 <SSLv23_server_method@plt>
mov    %eax,%edi
call   1100 <SSL_CTX_new@plt>
mov    %rax,%rdi
call   10d0 <SSL_new@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %ebx,%esi
call   1060 <SSL_set_fd@plt>
mov    0x2d10(%rip),%rbx
mov    (%rbx),%edx
lea    0xd27(%rip),%rsi
mov    %r14,%rdi
call   1030 <SSL_use_certificate_file@plt>
mov    (%rbx),%edx
lea    0xd21(%rip),%rsi
mov    %r14,%rdi
call   10e0 <SSL_use_PrivateKey_file@plt>
mov    %r14,%rdi
call   10f0 <SSL_accept@plt>
lea    0x10(%rsp),%rbx
lea    0xd11(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   10c0 <SSL_read@plt>
movb   $0x0,0x10f(%rsp)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <printf@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <SSL_write@plt>
jmp    1310 <main+0xf0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@SOMAXCONN = global i32 0
@.str = [11 x i8] c"public.key\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.1 = [12 x i8] c"private.crt\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %8, i32* %9
%10 = load i32, i32* @INADDR_ANY
%11 = call i32 @htonl(i32 %10)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = call i32 @htons(i32 31337)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = load i32, i32* @IPPROTO_TCP
%19 = call i32 @socket(i32 %16, i32 %17, i32 %18)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
br label %23
23: ; preds = %0
%24 = load i32, i32* %4
%25 = load i32, i32* @SOMAXCONN
%26 = call i32 @listen(i32 %24, i32 %25)
%27 = load i32, i32* %4
%28 = call i32 @accept(i32 %27, i32* null, i32* null)
store i32 %28, i32* %5
%29 = call i32 (...) @SSL_library_init()
%30 = call i32 (...) @SSLv23_server_method()
%31 = call i32* @SSL_CTX_new(i32 %30)
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = call i32* @SSL_new(i32* %32)
store i32* %33, i32** %7
%34 = load i32*, i32** %7
%35 = load i32, i32* %5
%36 = call i32 @SSL_set_fd(i32* %34, i32 %35)
%37 = load i32*, i32** %7
%38 = load i32, i32* @SSL_FILETYPE_PEM
%39 = call i32 @SSL_use_certificate_file(i32* %37, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %38)
%40 = load i32*, i32** %7
%41 = load i32, i32* @SSL_FILETYPE_PEM
%42 = call i32 @SSL_use_PrivateKey_file(i32* %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %41)
%43 = load i32*, i32** %7
%44 = call i32 @SSL_accept(i32* %43)
br label %45
45: ; preds = %23, %45
%46 = load i32*, i32** %7
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%48 = call i32 @SSL_read(i32* %46, i8* %47, i32 256)
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 255
store i8 0, i8* %49
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %50)
%52 = load i32*, i32** %7
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%54 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%55 = call i32 @strlen(i8* %54)
%56 = call i32 @SSL_write(i32* %52, i8* %53, i32 %55)
br label %45
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@SOMAXCONN = global i32 0
@.str = [11 x i8] c"public.key\00"
@SSL_FILETYPE_PEM = global i32 0
@.str.1 = [12 x i8] c"private.crt\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca %struct.sockaddr_in
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %5, i32* %6
%7 = load i32, i32* @INADDR_ANY
%8 = tail call i32 @htonl(i32 %7)
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1, i32 0
store i32 %8, i32* %9
%10 = tail call i32 @htons(i32 31337)
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = load i32, i32* @IPPROTO_TCP
%15 = tail call i32 @socket(i32 %12, i32 %13, i32 %14)
%16 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%17 = call i32 @bind(i32 %15, %struct.sockaddr* %16, i32 12)
%18 = load i32, i32* @SOMAXCONN
%19 = call i32 @listen(i32 %15, i32 %18)
%20 = call i32 @accept(i32 %15, i32* null, i32* null)
%21 = call i32 (...) @SSL_library_init()
%22 = call i32 (...) @SSLv23_server_method()
%23 = call i32* @SSL_CTX_new(i32 %22)
%24 = call i32* @SSL_new(i32* %23)
%25 = call i32 @SSL_set_fd(i32* %24, i32 %20)
%26 = load i32, i32* @SSL_FILETYPE_PEM
%27 = call i32 @SSL_use_certificate_file(i32* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = load i32, i32* @SSL_FILETYPE_PEM
%29 = call i32 @SSL_use_PrivateKey_file(i32* %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 @SSL_accept(i32* %24)
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 255
br label %32
32: ; preds = %32, %0
%33 = call i32 @SSL_read(i32* %24, i8* %3, i32 256)
store i8 0, i8* %31
%34 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%35 = call i32 @strlen(i8* %3)
%36 = call i32 @SSL_write(i32* %24, i8* %3, i32 %35)
br label %32
}