#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 /*<<< orphan*/ com(int, int);
int /*<<< orphan*/ exit(int);
int fork();
int open_forwarding_socket(char *, int);
int /*<<< orphan*/ perror(char *);
void forward_traffic(int client_socket, char *forward_name, int forward_port) {
  int forward_socket;
  pid_t down_pid;
  forward_socket = open_forwarding_socket(forward_name, forward_port);
  down_pid = fork();
  if (down_pid == -1) {
    perror("fork");
    exit(1);
    ;
  }
  if (down_pid == 0) {
    com(forward_socket, client_socket);
  } else {
    com(client_socket, forward_socket);
  }
}


x86 assembly (clang, -O0):
<forward_traffic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <open_forwarding_socket@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    119b <forward_traffic+0x4b>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11b5 <forward_traffic+0x65>
mov    -0x18(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1040 <com@plt>
jmp    11c0 <forward_traffic+0x70>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <com@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forward_traffic>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsi,%rdi
mov    %edx,%esi
call   1030 <open_forwarding_socket@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1177 <forward_traffic+0x27>
cmp    $0xffffffff,%eax
je     1186 <forward_traffic+0x36>
mov    %ebx,%edi
mov    %ebp,%esi
jmp    117b <forward_traffic+0x2b>
mov    %ebp,%edi
mov    %ebx,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <com@plt>
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
define void @forward_traffic(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 i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @open_forwarding_socket(i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = call i32 (...) @fork()
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %3
%19 = load i32, i32* %8
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i32, i32* %7
%23 = load i32, i32* %4
%24 = call i32 @com(i32 %22, i32 %23)
br label %29
25: ; preds = %18
%26 = load i32, i32* %4
%27 = load i32, i32* %7
%28 = call i32 @com(i32 %26, i32 %27)
br label %29
29: ; preds = %25, %21
ret void
}

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