#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 pid_t;

/* Variables and functions */
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ forward_traffic(int, char *, int);
int /*<<< orphan*/ perror(char *);
void accept_connection(int server_socket, char *forward_name,
                       int forward_port) {
  int client_socket;
  pid_t up_pid;
  client_socket = accept(server_socket, NULL, NULL);
  if (client_socket == -1) {
    perror("accept");
    exit(1);
    ;
  }
  up_pid = fork();
  if (up_pid == -1) {
    perror("fork");
    exit(1);
    ;
  }
  if (up_pid == 0) {
    forward_traffic(client_socket, forward_name, forward_port);
    exit(1);
  }
  close(client_socket);
}


x86 assembly (clang, -O0):
<accept_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1060 <accept@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11a4 <accept_connection+0x44>
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11ce <accept_connection+0x6e>
lea    0xe48(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11f1 <accept_connection+0x91>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <forward_traffic@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%edi
call   1030 <close@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<accept_connection>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
xor    %esi,%esi
xor    %edx,%edx
call   1060 <accept@plt>
cmp    $0xffffffff,%eax
je     1195 <accept_connection+0x35>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     119e <accept_connection+0x3e>
cmp    $0xffffffff,%eax
je     11b5 <accept_connection+0x55>
mov    %ebp,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <close@plt>
lea    0xe64(%rip),%rdi
jmp    11bc <accept_connection+0x5c>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <forward_traffic@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    0xe4b(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"accept\00"
@.str.1 = [5 x i8] c"fork\00"
define void @accept_connection(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i32, i32* %4
%10 = call i32 @accept(i32 %9, i32* null, i32* null)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = call i32 (...) @fork()
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %16
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %7
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = call i32 @forward_traffic(i32 %27, i8* %28, i32 %29)
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %23
%33 = load i32, i32* %7
%34 = call i32 @close(i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"accept\00"
@.str.1 = [5 x i8] c"fork\00"
define void @accept_connection(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @accept(i32 %0, i32* null, i32* null)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %3
%10 = tail call i32 (...) @fork()
switch i32 %10, label %17 [
i32 -1, label %11
i32 0, label %14
]
11: ; preds = %9
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %9
%15 = tail call i32 @forward_traffic(i32 %4, i8* %1, i32 %2)
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %9
%18 = tail call i32 @close(i32 %4)
ret void
}