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

/* Variables and functions */
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execlp(char *, char *, char *, char *, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ fork();
int get_random_port_numer();
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int start_game_server(int players) {
  int static port;
  if (!players) {
    port = get_random_port_numer();
    if (!(fork())) {
      execlp("bin/sh", "sh", "-c", "./game_server", port, NULL);
      syslog(LOG_ERR, "%s", strerror(errno));
    } else {
      return port;
    }
  }
}


x86 assembly (clang, -O0):
<start_game_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    11f2 <start_game_server+0xa2>
mov    $0x0,%al
call   1040 <get_random_port_numer@plt>
mov    %eax,0x2eda(%rip)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%eax
jne    11df <start_game_server+0x8f>
mov    0x2ec3(%rip),%r8d
lea    0xe70(%rip),%rdi
lea    0xe6d(%rip),%rsi
lea    0xe69(%rip),%rdx
lea    0xe65(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r9d
call   1050 <execlp@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%edx
lea    0xe43(%rip),%rsi
call   1030 <syslog@plt>
jmp    11ed <start_game_server+0x9d>
mov    0x2e67(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    11f2 <start_game_server+0xa2>
jmp    11f2 <start_game_server+0xa2>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_game_server>:
push   %rbx
test   %edi,%edi
je     1157 <start_game_server+0x7>
pop    %rbx
ret
xor    %eax,%eax
call   1040 <get_random_port_numer@plt>
mov    %eax,0x2ee8(%rip)
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ecx
mov    0x2ed9(%rip),%eax
test   %ecx,%ecx
jne    1155 <start_game_server+0x5>
lea    0xe82(%rip),%rdi
lea    0xe7f(%rip),%rsi
lea    0xe7b(%rip),%rdx
lea    0xe77(%rip),%rcx
mov    %eax,%r8d
xor    %r9d,%r9d
call   1050 <execlp@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%ebx
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe5c(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1030 <syslog@plt>
pop    %rbx
ret

LLVM IR (-O0):
@start_game_server.port = internal global i32 0
@.str = [7 x i8] c"bin/sh\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [14 x i8] c"./game_server\00"
@LOG_ERR = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@errno = global i32 0
define i32 @start_game_server(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp ne i32 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %1
%7 = call i32 (...) @get_random_port_numer()
store i32 %7, i32* @start_game_server.port
%8 = call i32 (...) @fork()
%9 = icmp ne i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %6
%11 = load i32, i32* @start_game_server.port
%12 = call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32* null)
%13 = load i32, i32* @LOG_ERR
%14 = load i32, i32* @errno
%15 = call i32 @strerror(i32 %14)
%16 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %15)
br label %19
17: ; preds = %6
%18 = load i32, i32* @start_game_server.port
store i32 %18, i32* %2
br label %20
19: ; preds = %10
br label %20
20: ; preds = %17, %19, %1
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
@start_game_server.port = internal unnamed_addr global i32 0
@.str = [7 x i8] c"bin/sh\00"
@.str.1 = [3 x i8] c"sh\00"
@.str.2 = [3 x i8] c"-c\00"
@.str.3 = [14 x i8] c"./game_server\00"
@LOG_ERR = global i32 0
@.str.4 = [3 x i8] c"%s\00"
@errno = global i32 0
define i32 @start_game_server(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %14
3: ; preds = %1
%4 = tail call i32 (...) @get_random_port_numer()
store i32 %4, i32* @start_game_server.port
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
%7 = load i32, i32* @start_game_server.port
br i1 %6, label %8, label %14
8: ; preds = %3
%9 = tail call i32 @execlp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %7, i32* null)
%10 = load i32, i32* @LOG_ERR
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @syslog(i32 %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %3, %8, %1
%15 = phi i32 [ undef, %1 ], [ undef, %8 ], [ %7, %3 ]
ret i32 %15
}