#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;

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ SIGSEGV;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(scalar_t__, int *, int /*<<< orphan*/);
int main(void) {
  pid_t pid = fork();
  if (pid < 0) {
    perror("fork");
    exit(1);
  } else if (pid == 0) {
    char *s = NULL;
    s[0] = 1;
  } else {
    pid_t ret;
    int status;
    while ((ret = waitpid(pid, &status, 0)) != pid) {
      if (errno != EINTR) {
        perror("waitpid");
        exit(1);
      }
    }
    if (WIFSIGNALED(status)) {
      assert(WTERMSIG(status) != 0);
      if (WTERMSIG(status) == SIGSEGV) {
        printf("PASS\n");
      } else {
        fprintf(stderr, "Child process died with unexpected signal %d.\n",
                WTERMSIG(status));
      }
    } else if (WIFEXITED(status)) {
      if (WEXITSTATUS(status) == 0) {
        fprintf(stderr, "Child process exited without expected SIGSEGV "
                        "signal.\n");
      } else {
        fprintf(stderr, "Child process exited with unexpected status %d.\n",
                WEXITSTATUS(status));
      }
    } else {
      fprintf(stderr, "Unrecognized status of child proces %x?\n", status);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11eb <main+0x3b>
lea    0xe24(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    120a <main+0x5a>
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x1,(%rax)
jmp    1371 <main+0x1c1>
jmp    120f <main+0x5f>
mov    -0x10(%rbp),%rdi
lea    -0x24(%rbp),%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
mov    %rax,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
je     1261 <main+0xb1>
mov    0x2d9d(%rip),%rax
mov    (%rax),%rax
mov    0x2d8b(%rip),%rcx
cmp    (%rcx),%rax
je     125c <main+0xac>
lea    0xdb8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    120f <main+0x5f>
mov    -0x24(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     12e2 <main+0x132>
mov    -0x24(%rbp),%edi
call   1070 <WTERMSIG@plt>
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x24(%rbp),%edi
call   1070 <WTERMSIG@plt>
cltq
mov    0x2d4c(%rip),%rcx
cmp    (%rcx),%rax
jne    12b6 <main+0x106>
lea    0xd61(%rip),%rdi
call   1030 <printf@plt>
jmp    12dd <main+0x12d>
mov    0x2d1b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <WTERMSIG@plt>
mov    -0x28(%rbp),%edi
mov    %eax,%edx
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    136c <main+0x1bc>
mov    -0x24(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     134d <main+0x19d>
mov    -0x24(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
cmp    $0x0,%eax
jne    1321 <main+0x171>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1348 <main+0x198>
mov    0x2cb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <WEXITSTATUS@plt>
mov    -0x2c(%rbp),%edi
mov    %eax,%edx
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1367 <main+0x1b7>
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    136c <main+0x1bc>
jmp    1371 <main+0x1c1>
jmp    1376 <main+0x1c6>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     12e6 <main+0x136>
mov    %rax,%rbx
lea    0x4(%rsp),%r14
mov    0x2df9(%rip),%r15
mov    0x2dea(%rip),%r12
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1090 <waitpid@plt>
cmp    %rbx,%rax
je     1211 <main+0x61>
mov    (%r15),%rax
cmp    (%r12),%rax
je     11e0 <main+0x30>
lea    0xe03(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x4(%rsp),%edi
call   1040 <WIFSIGNALED@plt>
mov    0x4(%rsp),%edi
test   %rax,%rax
je     125a <main+0xaa>
call   1070 <WTERMSIG@plt>
xor    %edi,%edi
test   %eax,%eax
setne  %dil
call   1050 <assert@plt>
mov    0x4(%rsp),%edi
call   1070 <WTERMSIG@plt>
cltq
mov    0x2da1(%rip),%rcx
cmp    %rax,(%rcx)
jne    128c <main+0xdc>
lea    0xe7a(%rip),%rdi
call   1030 <puts@plt>
jmp    12c6 <main+0x116>
call   10b0 <WIFEXITED@plt>
test   %rax,%rax
je     12ab <main+0xfb>
mov    0x4(%rsp),%edi
call   1080 <WEXITSTATUS@plt>
mov    0x2d64(%rip),%rcx
mov    (%rcx),%ebx
test   %eax,%eax
je     12d4 <main+0x124>
mov    0x4(%rsp),%edi
call   1080 <WEXITSTATUS@plt>
lea    0xde9(%rip),%rsi
jmp    12a5 <main+0xf5>
mov    0x2d45(%rip),%rax
mov    (%rax),%ebx
mov    0x4(%rsp),%edi
call   1070 <WTERMSIG@plt>
lea    0xd68(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
jmp    12bf <main+0x10f>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
mov    0x4(%rsp),%edx
lea    0xde5(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xd61(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12c6 <main+0x116>
lea    0xd13(%rip),%rdi
jmp    1202 <main+0x52>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [8 x i8] c"waitpid\00"
@SIGSEGV = global i64 0
@.str.2 = [6 x i8] c"PASS\0A\00"
@stderr = global i32 0
@.str.3 = [47 x i8] c"Child process died with unexpected signal %d.\0A\00"
@.str.4 = [55 x i8] c"Child process exited without expected SIGSEGV signal.\0A\00"
@.str.5 = [49 x i8] c"Child process exited with unexpected status %d.\0A\00"
@.str.6 = [41 x i8] c"Unrecognized status of child proces %x?\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %12
store i8* null, i8** %3
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 0
store i8 1, i8* %17
br label %78
18: ; preds = %12
br label %19
19: ; preds = %31, %18
%20 = load i64, i64* %2
%21 = call i64 @waitpid(i64 %20, i32* %5, i32 0)
store i64 %21, i64* %4
%22 = load i64, i64* %2
%23 = icmp ne i64 %21, %22
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i64, i64* @errno
%26 = load i64, i64* @EINTR
%27 = icmp ne i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %24
br label %19
32: ; preds = %19
%33 = load i32, i32* %5
%34 = call i64 @WIFSIGNALED(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %55
36: ; preds = %32
%37 = load i32, i32* %5
%38 = call i32 @WTERMSIG(i32 %37)
%39 = icmp ne i32 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i32, i32* %5
%43 = call i32 @WTERMSIG(i32 %42)
%44 = sext i32 %43 to i64
%45 = load i64, i64* @SIGSEGV
%46 = icmp eq i64 %44, %45
br i1 %46, label %47, label %49
47: ; preds = %36
%48 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %54
49: ; preds = %36
%50 = load i32, i32* @stderr
%51 = load i32, i32* %5
%52 = call i32 @WTERMSIG(i32 %51)
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %49, %47
br label %77
55: ; preds = %32
%56 = load i32, i32* %5
%57 = call i64 @WIFEXITED(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %72
59: ; preds = %55
%60 = load i32, i32* %5
%61 = call i32 @WEXITSTATUS(i32 %60)
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %71
66: ; preds = %59
%67 = load i32, i32* @stderr
%68 = load i32, i32* %5
%69 = call i32 @WEXITSTATUS(i32 %68)
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %66, %63
br label %76
72: ; preds = %55
%73 = load i32, i32* @stderr
%74 = load i32, i32* %5
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %74)
br label %76
76: ; preds = %72, %71
br label %77
77: ; preds = %76, %54
br label %78
78: ; preds = %77, %15
br label %79
79: ; preds = %78
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [8 x i8] c"waitpid\00"
@SIGSEGV = global i64 0
@stderr = global i32 0
@.str.3 = [47 x i8] c"Child process died with unexpected signal %d.\0A\00"
@.str.4 = [55 x i8] c"Child process exited without expected SIGSEGV signal.\0A\00"
@.str.5 = [49 x i8] c"Child process exited with unexpected status %d.\0A\00"
@.str.6 = [41 x i8] c"Unrecognized status of child proces %x?\0A\00"
@str = [5 x i8] c"PASS\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i64 (...) @fork()
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = icmp ne i64 %2, 0
tail call void @llvm.assume(i1 %8)
%9 = bitcast i32* %1 to i8*
br label %10
10: ; preds = %13, %7
%11 = call i64 @waitpid(i64 %2, i32* %1, i32 0)
%12 = icmp eq i64 %11, %2
br i1 %12, label %20, label %13
13: ; preds = %10
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
br i1 %16, label %10, label %17
17: ; preds = %13
%18 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = load i32, i32* %1
%22 = call i64 @WIFSIGNALED(i32 %21)
%23 = icmp eq i64 %22, 0
%24 = load i32, i32* %1
br i1 %23, label %42, label %25
25: ; preds = %20
%26 = call i32 @WTERMSIG(i32 %24)
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i32, i32* %1
%31 = call i32 @WTERMSIG(i32 %30)
%32 = sext i32 %31 to i64
%33 = load i64, i64* @SIGSEGV
%34 = icmp eq i64 %33, %32
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %60
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = load i32, i32* %1
%40 = call i32 @WTERMSIG(i32 %39)
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %60
42: ; preds = %20
%43 = call i64 @WIFEXITED(i32 %24)
%44 = icmp eq i64 %43, 0
br i1 %44, label %56, label %45
45: ; preds = %42
%46 = load i32, i32* %1
%47 = call i32 @WEXITSTATUS(i32 %46)
%48 = icmp eq i32 %47, 0
%49 = load i32, i32* @stderr
br i1 %48, label %50, label %52
50: ; preds = %45
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0))
br label %60
52: ; preds = %45
%53 = load i32, i32* %1
%54 = call i32 @WEXITSTATUS(i32 %53)
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.5, i64 0, i64 0), i32 %54)
br label %60
56: ; preds = %42
%57 = load i32, i32* @stderr
%58 = load i32, i32* %1
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %56, %52, %50, %35, %37
ret i32 0
}