#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 */
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;
typedef int /*<<< orphan*/ SSL_CTX;
typedef int /*<<< orphan*/ SSL;

/* Variables and functions */
int /*<<< orphan*/ *InitServerCTX();
int /*<<< orphan*/ LoadCertificates(int /*<<< orphan*/ *, char *, char *);
int OpenListener(int /*<<< orphan*/);
int /*<<< orphan*/ SSL_CTX_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *SSL_new(int /*<<< orphan*/ *);
int /*<<< orphan*/ SSL_set_fd(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ Servlet(int /*<<< orphan*/ *);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, ...);
int main(int count, char *strings[]) {
  SSL_CTX *ctx;
  int server;
  char *portnum;
  if (count != 2) {
    printf("Usage: %s <portnum>\n", strings[0]);
    exit(0);
  }
  portnum = strings[1];
  ctx = InitServerCTX();
  LoadCertificates(ctx, "newreq.pem", "newreq.pem");
  server = OpenListener(atoi(portnum));
  while (1) {
    struct sockaddr_in addr;
    int len = sizeof(addr);
    SSL *ssl;
    int client = accept(server, (struct sockaddr *)&addr, &len);
    printf("Connection: %s:%d\n", inet_ntoa(addr.sin_addr),
           ntohs(addr.sin_port));
    ssl = SSL_new(ctx);
    SSL_set_fd(ssl, client);
    Servlet(ssl);
  }
  close(server);
  SSL_CTX_free(ctx);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11fc <main+0x3c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   1080 <InitServerCTX@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdf7(%rip),%rdx
mov    %rdx,%rsi
call   10e0 <LoadCertificates@plt>
mov    -0x28(%rbp),%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1090 <OpenListener@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x8,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   10b0 <accept@plt>
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%edi
call   10a0 <ntohs@plt>
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <SSL_new@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1050 <SSL_set_fd@plt>
mov    -0x40(%rbp),%rdi
call   1030 <Servlet@plt>
jmp    1239 <main+0x79>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    126f <main+0xaf>
mov    0x8(%rsi),%rbp
xor    %eax,%eax
call   1080 <InitServerCTX@plt>
mov    %rax,%r13
lea    0xe29(%rip),%rdx
mov    %rax,%rdi
mov    %rdx,%rsi
call   10e0 <LoadCertificates@plt>
mov    %rbp,%rdi
call   10c0 <atoi@plt>
mov    %eax,%edi
call   1090 <OpenListener@plt>
mov    %eax,%r15d
lea    0xe10(%rip),%r12
movl   $0x8,0xc(%rsp)
mov    %r15d,%edi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   10b0 <accept@plt>
mov    %eax,%ebx
mov    0x14(%rsp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%r14
mov    0x10(%rsp),%edi
call   10a0 <ntohs@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1070 <SSL_new@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %ebx,%esi
call   1050 <SSL_set_fd@plt>
mov    %rbp,%rdi
call   1030 <Servlet@plt>
jmp    1210 <main+0x50>
mov    (%rsi),%rsi
lea    0xd87(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s <portnum>\0A\00"
@.str.1 = [11 x i8] c"newreq.pem\00"
@.str.2 = [19 x i8] c"Connection: %s:%d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca %struct.sockaddr_in
%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 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 0)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %8
%25 = call i32* (...) @InitServerCTX()
store i32* %25, i32** %6
%26 = load i32*, i32** %6
%27 = call i32 @LoadCertificates(i32* %26, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%28 = load i8*, i8** %8
%29 = call i32 @atoi(i8* %28)
%30 = call i32 @OpenListener(i32 %29)
store i32 %30, i32* %7
br label %31
31: ; preds = %21, %31
store i32 8, i32* %10
%32 = load i32, i32* %7
%33 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%34 = call i32 @accept(i32 %32, %struct.sockaddr* %33, i32* %10)
store i32 %34, i32* %12
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%36 = load i32, i32* %35
%37 = call i8* @inet_ntoa(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @ntohs(i32 %39)
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %37, i32 %40)
%42 = load i32*, i32** %6
%43 = call i32* @SSL_new(i32* %42)
store i32* %43, i32** %11
%44 = load i32*, i32** %11
%45 = load i32, i32* %12
%46 = call i32 @SSL_set_fd(i32* %44, i32 %45)
%47 = load i32*, i32** %11
%48 = call i32 @Servlet(i32* %47)
br label %31
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [21 x i8] c"Usage: %s <portnum>\0A\00"
@.str.1 = [11 x i8] c"newreq.pem\00"
@.str.2 = [19 x i8] c"Connection: %s:%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = icmp eq i32 %0, 2
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* (...) @InitServerCTX()
%14 = tail call i32 @LoadCertificates(i32* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @atoi(i8* %12)
%16 = tail call i32 @OpenListener(i32 %15)
%17 = bitcast %struct.sockaddr_in* %3 to i8*
%18 = bitcast i32* %4 to i8*
%19 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
br label %22
22: ; preds = %22, %10
store i32 8, i32* %4
%23 = call i32 @accept(i32 %16, %struct.sockaddr* %19, i32* %4)
%24 = load i32, i32* %20
%25 = call i8* @inet_ntoa(i32 %24)
%26 = load i32, i32* %21
%27 = call i32 @ntohs(i32 %26)
%28 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 %27)
%29 = call i32* @SSL_new(i32* %13)
%30 = call i32 @SSL_set_fd(i32* %29, i32 %23)
%31 = call i32 @Servlet(i32* %29)
br label %22
}