#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
scalar_t__ execv(char *, char **);
int fork();
int waitpid(int, int *, int /*<<< orphan*/);
void __start_kmc_server(char *argv[]) {
  pid_t pid;
  pid = fork();
  assert(pid != -1);
  if (pid > 0) {
    int stat;
    pid_t c;
    while ((c = waitpid(pid, &stat, 0)) == (pid_t)-1 && errno == EINTR)
      ;
    assert(c == pid);
    assert(stat == 0);
  } else {
    assert(execv(argv[0], argv) == 0);
  }
}


x86 assembly (clang, -O0):
<__start_kmc_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0xc(%rbp)
jle    11ef <__start_kmc_server+0xaf>
jmp    1176 <__start_kmc_server+0x36>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x15(%rbp)
jne    11b1 <__start_kmc_server+0x71>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e30(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    11c1 <__start_kmc_server+0x81>
jmp    11c6 <__start_kmc_server+0x86>
jmp    1176 <__start_kmc_server+0x36>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpl   $0x0,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
jmp    1210 <__start_kmc_server+0xd0>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execv@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__start_kmc_server>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1030 <assert@plt>
test   %ebx,%ebx
jle    11c3 <__start_kmc_server+0x83>
lea    0x4(%rsp),%r14
mov    0x2e6e(%rip),%r15
mov    0x2e5f(%rip),%r12
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    119a <__start_kmc_server+0x5a>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1180 <__start_kmc_server+0x40>
xor    %edi,%edi
cmp    %ebx,%eax
sete   %dil
call   1030 <assert@plt>
xor    %edi,%edi
cmpl   $0x0,0x4(%rsp)
sete   %dil
call   1030 <assert@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    (%r14),%rdi
mov    %r14,%rsi
call   1050 <execv@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <assert@plt>

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
define void @__start_kmc_server(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %2
%6 = call i32 (...) @fork()
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, -1
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %1
br label %14
14: ; preds = %24, %13
%15 = load i32, i32* %3
%16 = call i32 @waitpid(i32 %15, i32* %4, i32 0)
store i32 %16, i32* %5
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br label %22
22: ; preds = %18, %14
%23 = phi i1 [ false, %14 ], [ %21, %18 ]
br i1 %23, label %24, label %25
24: ; preds = %22
br label %14
25: ; preds = %22
%26 = load i32, i32* %5
%27 = load i32, i32* %3
%28 = icmp eq i32 %26, %27
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
br label %44
35: ; preds = %1
%36 = load i8**, i8*** %2
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %2
%40 = call i64 @execv(i8* %38, i8** %39)
%41 = icmp eq i64 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
br label %44
44: ; preds = %35, %25
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
define void @__start_kmc_server(i8** %0) {
%2 = alloca i32
%3 = tail call i32 (...) @fork()
%4 = icmp ne i32 %3, -1
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp sgt i32 %3, 0
br i1 %7, label %8, label %25
8: ; preds = %1
%9 = bitcast i32* %2 to i8*
br label %10
10: ; preds = %10, %8
%11 = call i32 @waitpid(i32 %3, i32* %2, i32 0)
%12 = icmp eq i32 %11, -1
%13 = load i64, i64* @errno
%14 = load i64, i64* @EINTR
%15 = icmp eq i64 %13, %14
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %10, label %17
17: ; preds = %10
%18 = icmp eq i32 %11, %3
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = load i32, i32* %2
%22 = icmp eq i32 %21, 0
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
br label %31
25: ; preds = %1
%26 = load i8*, i8** %0
%27 = tail call i64 @execv(i8* %26, i8** %0)
%28 = icmp eq i64 %27, 0
%29 = zext i1 %28 to i32
%30 = tail call i32 @assert(i32 %29)
br label %31
31: ; preds = %25, %17
ret void
}