#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*/ SSL_CTX;

/* Variables and functions */
int accept_and(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ ssl_sock_read(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ tcp_sock_read(int);
ssl_or_tcp_fork(int listen_socket, SSL_CTX *ctx) {
  int pid;
  int sock;
  sock = accept_and(listen_socket);
  pid = fork();
  if (pid == 0) {
    close(listen_socket);
    if (ctx) {
      ssl_sock_read(sock, ctx);
    } else {
      tcp_sock_read(sock);
    }
    exit(0);
  }
  close(sock);
}


x86 assembly (clang, -O0):
<ssl_or_tcp_fork>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <accept_and@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11c1 <ssl_or_tcp_fork+0x61>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
cmpq   $0x0,-0x10(%rbp)
je     11b2 <ssl_or_tcp_fork+0x52>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <ssl_sock_read@plt>
jmp    11ba <ssl_or_tcp_fork+0x5a>
mov    -0x18(%rbp),%edi
call   1050 <tcp_sock_read@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ssl_or_tcp_fork>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebx
call   1070 <accept_and@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1186 <ssl_or_tcp_fork+0x26>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <close@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%edi
test   %r14,%r14
jne    11a0 <ssl_or_tcp_fork+0x40>
call   1050 <tcp_sock_read@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %r14,%rsi
call   1030 <ssl_sock_read@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
define i32 @ssl_or_tcp_fork(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%8 = load i32, i32* %4
%9 = call i32 @accept_and(i32 %8)
store i32 %9, i32* %7
%10 = call i32 (...) @fork()
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %2
%14 = load i32, i32* %4
%15 = call i32 @close(i32 %14)
%16 = load i32*, i32** %5
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %7
%20 = load i32*, i32** %5
%21 = call i32 @ssl_sock_read(i32 %19, i32* %20)
br label %25
22: ; preds = %13
%23 = load i32, i32* %7
%24 = call i32 @tcp_sock_read(i32 %23)
br label %25
25: ; preds = %22, %18
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %2
%28 = load i32, i32* %7
%29 = call i32 @close(i32 %28)
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
define i32 @ssl_or_tcp_fork(i32 %0, i32* %1) {
%3 = tail call i32 @accept_and(i32 %0)
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = tail call i32 @close(i32 %0)
%8 = icmp eq i32* %1, null
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @ssl_sock_read(i32 %3, i32* %1)
br label %13
11: ; preds = %6
%12 = tail call i32 @tcp_sock_read(i32 %3)
br label %13
13: ; preds = %11, %9
%14 = tail call i32 @exit(i32 0)
unreachable
15: ; preds = %2
%16 = tail call i32 @close(i32 %3)
ret i32 undef
}