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

/* Variables and functions */
int O_APPEND;
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int getpid();
int open(char *, int, int);
int /*<<< orphan*/ spawn_slaves();
int srv_init() {
  FILE *pidfile;
  int logfd, errfd;
  pidfile = fopen("/tmp/manbomber-srv.pid", "w+");
  fprintf(pidfile, "%d\n", getpid());
  fflush(pidfile);
  fclose(pidfile);
  logfd = open("/tmp/manbomber-srv.log", O_CREAT | O_WRONLY | O_APPEND, 0755);
  errfd = open("/tmp/manbomber-srv.error", O_CREAT | O_WRONLY | O_APPEND, 0755);
  close(2);
  dup(errfd);
  close(1);
  dup(logfd);
  close(0);
  spawn_slaves();
}


x86 assembly (clang, -O0):
<srv_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
lea    0xe71(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xe4f(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2dde(%rip),%rax
or     (%rax),%esi
mov    0x2dcd(%rip),%rax
or     (%rax),%esi
lea    0xe1a(%rip),%rdi
mov    $0x1ed,%edx
call   10a0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%esi
mov    0x2daf(%rip),%rax
or     (%rax),%esi
mov    0x2d9e(%rip),%rax
or     (%rax),%esi
lea    0xe02(%rip),%rdi
mov    $0x1ed,%edx
call   10a0 <open@plt>
mov    %eax,-0x18(%rbp)
mov    $0x2,%edi
call   1060 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <dup@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    -0x14(%rbp),%edi
call   1050 <dup@plt>
xor    %edi,%edi
call   1060 <close@plt>
mov    $0x0,%al
call   1090 <spawn_slaves@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srv_init>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe62(%rip),%rdi
lea    0xe72(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2e1c(%rip),%r14
mov    0x2ded(%rip),%rbp
mov    0x0(%rbp),%esi
or     (%r14),%esi
mov    0x2dd8(%rip),%r15
or     (%r15),%esi
lea    0xe24(%rip),%rdi
mov    $0x1ed,%edx
call   10a0 <open@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%esi
or     (%r14),%esi
or     (%r15),%esi
lea    0xe1f(%rip),%rdi
mov    $0x1ed,%edx
call   10a0 <open@plt>
mov    %eax,%ebp
mov    $0x2,%edi
call   1060 <close@plt>
mov    %ebp,%edi
call   1050 <dup@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    %ebx,%edi
call   1050 <dup@plt>
xor    %edi,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <spawn_slaves@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"/tmp/manbomber-srv.pid\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [23 x i8] c"/tmp/manbomber-srv.log\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.4 = [25 x i8] c"/tmp/manbomber-srv.error\00"
define i32 @srv_init() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 (...) @getpid()
%8 = call i32 @fprintf(i32* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = load i32*, i32** %2
%10 = call i32 @fflush(i32* %9)
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
%13 = load i32, i32* @O_CREAT
%14 = load i32, i32* @O_WRONLY
%15 = or i32 %13, %14
%16 = load i32, i32* @O_APPEND
%17 = or i32 %15, %16
%18 = call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %17, i32 493)
store i32 %18, i32* %3
%19 = load i32, i32* @O_CREAT
%20 = load i32, i32* @O_WRONLY
%21 = or i32 %19, %20
%22 = load i32, i32* @O_APPEND
%23 = or i32 %21, %22
%24 = call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %23, i32 493)
store i32 %24, i32* %4
%25 = call i32 @close(i32 2)
%26 = load i32, i32* %4
%27 = call i32 @dup(i32 %26)
%28 = call i32 @close(i32 1)
%29 = load i32, i32* %3
%30 = call i32 @dup(i32 %29)
%31 = call i32 @close(i32 0)
%32 = call i32 (...) @spawn_slaves()
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [23 x i8] c"/tmp/manbomber-srv.pid\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [23 x i8] c"/tmp/manbomber-srv.log\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.4 = [25 x i8] c"/tmp/manbomber-srv.error\00"
define i32 @srv_init() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %2)
%4 = tail call i32 @fflush(i32* %1)
%5 = tail call i32 @fclose(i32* %1)
%6 = load i32, i32* @O_CREAT
%7 = load i32, i32* @O_WRONLY
%8 = or i32 %7, %6
%9 = load i32, i32* @O_APPEND
%10 = or i32 %8, %9
%11 = tail call i32 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %10, i32 493)
%12 = load i32, i32* @O_CREAT
%13 = load i32, i32* @O_WRONLY
%14 = or i32 %13, %12
%15 = load i32, i32* @O_APPEND
%16 = or i32 %14, %15
%17 = tail call i32 @open(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %16, i32 493)
%18 = tail call i32 @close(i32 2)
%19 = tail call i32 @dup(i32 %17)
%20 = tail call i32 @close(i32 1)
%21 = tail call i32 @dup(i32 %11)
%22 = tail call i32 @close(i32 0)
%23 = tail call i32 (...) @spawn_slaves()
ret i32 undef
}