#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ SIGCHLD;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pause();
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  int nz = 0;
  if (argc == 2) {
    if (strcmp(argv[1], "--nz") == 0) {
      nz = 1;
    } else {
      char buf[256];
      snprintf(buf, sizeof(buf), "invalid: %s", argv[1]);
      err(buf);
    }
  }
  pid_t pid;
  if (nz) {
    signal(SIGCHLD, SIG_IGN);
  }
  if ((pid = fork()) < 0) {
    err("fork error");
  } else if (pid == 0) {
    exit(EXIT_SUCCESS);
  } else {
    pause();
    pause();
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11f5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe57(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11c4 <main+0x54>
movl   $0x1,-0x14(%rbp)
jmp    11f0 <main+0x80>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    $0x100,%esi
lea    0xe26(%rip),%rdx
call   1030 <snprintf@plt>
lea    -0x120(%rbp),%rdi
call   1070 <err@plt>
jmp    11f5 <main+0x85>
cmpl   $0x0,-0x14(%rbp)
je     1216 <main+0xa6>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jge    123f <main+0xcf>
lea    0xddc(%rip),%rdi
call   1070 <err@plt>
jmp    1277 <main+0x107>
cmpq   $0x0,-0x128(%rbp)
jne    125b <main+0xeb>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1060 <pause@plt>
mov    $0x0,%al
call   1060 <pause@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x100,%rsp
cmp    $0x2,%edi
jne    11d1 <main+0x61>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe75(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11ba <main+0x4a>
mov    0x8(%rbx),%rcx
lea    0xe65(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1030 <snprintf@plt>
mov    %rbx,%rdi
call   1070 <err@plt>
jmp    11d1 <main+0x61>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
jns    11f4 <main+0x84>
lea    0xe2d(%rip),%rdi
call   1070 <err@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
ret
je     1204 <main+0x94>
xor    %eax,%eax
call   1060 <pause@plt>
xor    %eax,%eax
call   1060 <pause@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"--nz\00"
@.str.1 = [12 x i8] c"invalid: %s\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str.2 = [11 x i8] c"fork error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [256 x i8]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, 2
br i1 %10, label %11, label %27
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %11
store i32 1, i32* %6
br label %26
18: ; preds = %11
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%25 = call i32 @err(i8* %24)
br label %26
26: ; preds = %18, %17
br label %27
27: ; preds = %26, %2
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load i32, i32* @SIGCHLD
%32 = load i32, i32* @SIG_IGN
%33 = call i32 @signal(i32 %31, i32 %32)
br label %34
34: ; preds = %30, %27
%35 = call i64 (...) @fork()
store i64 %35, i64* %8
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %50
39: ; preds = %34
%40 = load i64, i64* %8
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @EXIT_SUCCESS
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %39
%46 = call i32 (...) @pause()
%47 = call i32 (...) @pause()
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %37
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [5 x i8] c"--nz\00"
@.str.1 = [12 x i8] c"invalid: %s\00"
@SIGCHLD = global i32 0
@SIG_IGN = global i32 0
@.str.2 = [11 x i8] c"fork error\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = icmp eq i64 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = call i32 @snprintf(i8* %11, i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @err(i8* %11)
br label %19
15: ; preds = %5
%16 = load i32, i32* @SIGCHLD
%17 = load i32, i32* @SIG_IGN
%18 = tail call i32 @signal(i32 %16, i32 %17)
br label %19
19: ; preds = %2, %10, %15
%20 = call i64 (...) @fork()
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @err(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
24: ; preds = %19
%25 = icmp eq i64 %20, 0
br i1 %25, label %26, label %29
26: ; preds = %24
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %24
%30 = call i32 (...) @pause()
%31 = call i32 (...) @pause()
%32 = load i32, i32* @EXIT_SUCCESS
%33 = call i32 @exit(i32 %32)
unreachable
}