#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*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ database_init();
int fork();
int /*<<< orphan*/ killprot_init();
int /*<<< orphan*/ printf(char *, int);
scalar_t__ setsid();
int /*<<< orphan*/ socket_mainloop();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
int main() {
  int pid;
  assert((pid = fork()) >= 0);
  if (pid) {
    printf("Opensvs started at pid %d.\n", pid);
    return 0;
  }
  assert(setsid() >= 0);
  close(0);
  close(1);
  close(2);
  srand(time(0));
  database_init();
  killprot_init();
  socket_mainloop();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
cmpl   $0x0,-0x8(%rbp)
je     11ee <main+0x4e>
mov    -0x8(%rbp),%esi
lea    0xe23(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    124b <main+0xab>
mov    $0x0,%al
call   1060 <setsid@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1080 <assert@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
mov    $0x0,%al
call   10b0 <database_init@plt>
mov    $0x0,%al
call   1040 <killprot_init@plt>
mov    $0x0,%al
call   10a0 <socket_mainloop@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ebx
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1080 <assert@plt>
test   %ebx,%ebx
je     11ca <main+0x2a>
lea    0xe3f(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
jmp    121d <main+0x7d>
xor    %eax,%eax
call   1060 <setsid@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1080 <assert@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10b0 <database_init@plt>
xor    %eax,%eax
call   1040 <killprot_init@plt>
xor    %eax,%eax
call   10a0 <socket_mainloop@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Opensvs started at pid %d.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = icmp sge i32 %3, 0
%5 = zext i1 %4 to i32
%6 = call i32 @assert(i32 %5)
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i32, i32* %2
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %10)
store i32 0, i32* %1
br label %25
12: ; preds = %0
%13 = call i64 (...) @setsid()
%14 = icmp sge i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = call i32 @close(i32 0)
%18 = call i32 @close(i32 1)
%19 = call i32 @close(i32 2)
%20 = call i32 @time(i32 0)
%21 = call i32 @srand(i32 %20)
%22 = call i32 (...) @database_init()
%23 = call i32 (...) @killprot_init()
%24 = call i32 (...) @socket_mainloop()
store i32 0, i32* %1
br label %25
25: ; preds = %12, %9
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [28 x i8] c"Opensvs started at pid %d.\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = xor i32 %1, -1
%3 = lshr i32 %2, 31
%4 = tail call i32 @assert(i32 %3)
%5 = icmp eq i32 %1, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %22
8: ; preds = %0
%9 = tail call i64 (...) @setsid()
%10 = lshr i64 %9, 63
%11 = trunc i64 %10 to i32
%12 = xor i32 %11, 1
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 @close(i32 0)
%15 = tail call i32 @close(i32 1)
%16 = tail call i32 @close(i32 2)
%17 = tail call i32 @time(i32 0)
%18 = tail call i32 @srand(i32 %17)
%19 = tail call i32 (...) @database_init()
%20 = tail call i32 (...) @killprot_init()
%21 = tail call i32 (...) @socket_mainloop()
br label %22
22: ; preds = %8, %6
ret i32 0
}