#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 */
int /*<<< orphan*/ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           unsigned long long, char *);
int /*<<< orphan*/ stderr;
int waitpid(int, int *, int /*<<< orphan*/);
void _run_mustfail(const char *file, unsigned long long line,
                   void (*op)(void)) {
  pid_t pid;
  int status;
  pid = fork();
  if (pid == -1)
    do {
      fprintf(stderr, "%s:%llu: %s\n", (file), (unsigned long long)(line),
              ("unable to fork"));
      fflush(stderr);
      _exit(111);
    } while (0);
  ;
  if (pid == 0) {
    close(2);
    op();
    _exit(0);
  }
  while (waitpid(pid, &status, 0) != pid) {
  };
  if (!WIFEXITED(status))
    do {
      fprintf(stderr, "%s:%llu: %s\n", (file), (unsigned long long)(line),
              ("process killed"));
      fflush(stderr);
      _exit(111);
    } while (0);
  ;
  if (!WEXITSTATUS(status))
    do {
      fprintf(stderr, "%s:%llu: %s\n", (file), (unsigned long long)(line),
              ("process exited with status = 0"));
      fflush(stderr);
      _exit(111);
    } while (0);
  ;
}


x86 assembly (clang, -O0):
<_run_mustfail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11e9 <_run_mustfail+0x69>
jmp    11ad <_run_mustfail+0x2d>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe3b(%rip),%rsi
lea    0xe41(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x6f,%edi
call   1030 <_exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1207 <_run_mustfail+0x87>
mov    $0x2,%edi
call   1040 <close@plt>
call   *-0x18(%rbp)
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    120c <_run_mustfail+0x8c>
mov    -0x1c(%rbp),%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    -0x1c(%rbp),%eax
je     1228 <_run_mustfail+0xa8>
jmp    120c <_run_mustfail+0x8c>
mov    -0x20(%rbp),%edi
call   1090 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    127a <_run_mustfail+0xfa>
jmp    123e <_run_mustfail+0xbe>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdaa(%rip),%rsi
lea    0xdbf(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x6f,%edi
call   1030 <_exit@plt>
mov    -0x20(%rbp),%edi
call   1070 <WEXITSTATUS@plt>
cmp    $0x0,%eax
jne    12cc <_run_mustfail+0x14c>
jmp    1290 <_run_mustfail+0x110>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd58(%rip),%rsi
lea    0xd7c(%rip),%r8
call   1050 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    $0x6f,%edi
call   1030 <_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_run_mustfail>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
je     11e5 <_run_mustfail+0x65>
mov    %eax,%ebp
test   %eax,%eax
je     11fe <_run_mustfail+0x7e>
lea    0x4(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    %ebp,%eax
jne    11b0 <_run_mustfail+0x30>
mov    0x4(%rsp),%edi
call   1090 <WIFEXITED@plt>
test   %eax,%eax
je     1211 <_run_mustfail+0x91>
mov    0x4(%rsp),%edi
call   1070 <WEXITSTATUS@plt>
test   %eax,%eax
je     122a <_run_mustfail+0xaa>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df4(%rip),%rbx
mov    (%rbx),%edi
lea    0xe0b(%rip),%rsi
lea    0xe11(%rip),%r8
jmp    1241 <_run_mustfail+0xc1>
mov    $0x2,%edi
call   1040 <close@plt>
call   *%rbx
xor    %edi,%edi
call   1030 <_exit@plt>
mov    0x2dc8(%rip),%rbx
mov    (%rbx),%edi
lea    0xddf(%rip),%rsi
lea    0xdf4(%rip),%r8
jmp    1241 <_run_mustfail+0xc1>
mov    0x2daf(%rip),%rbx
mov    (%rbx),%edi
lea    0xdc6(%rip),%rsi
lea    0xdea(%rip),%r8
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <fprintf@plt>
mov    (%rbx),%edi
call   1060 <fflush@plt>
mov    $0x6f,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"%s:%llu: %s\0A\00"
@.str.1 = [15 x i8] c"unable to fork\00"
@.str.2 = [15 x i8] c"process killed\00"
@.str.3 = [31 x i8] c"process exited with status = 0\00"
define void @_run_mustfail(i8* %0, i64 %1, void ()* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca void ()*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
store void ()* %2, void ()** %6
%9 = call i32 (...) @fork()
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %22
12: ; preds = %3
br label %13
13: ; preds = %12
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = load i64, i64* %5
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %15, i64 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 @fflush(i32 %18)
%20 = call i32 @_exit(i32 111)
unreachable
21: ; No predecessors!
br label %22
22: ; preds = %21, %3
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = call i32 @close(i32 2)
%27 = load void ()*, void ()** %6
%28 = call i32 @_exit(i32 0)
unreachable
29: ; preds = %22
br label %30
30: ; preds = %35, %29
%31 = load i32, i32* %7
%32 = call i32 @waitpid(i32 %31, i32* %8, i32 0)
%33 = load i32, i32* %7
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %30
br label %30
36: ; preds = %30
%37 = load i32, i32* %8
%38 = call i32 @WIFEXITED(i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %50, label %40
40: ; preds = %36
br label %41
41: ; preds = %40
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %4
%44 = load i64, i64* %5
%45 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %43, i64 %44, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%46 = load i32, i32* @stderr
%47 = call i32 @fflush(i32 %46)
%48 = call i32 @_exit(i32 111)
unreachable
49: ; No predecessors!
br label %50
50: ; preds = %49, %36
%51 = load i32, i32* %8
%52 = call i32 @WEXITSTATUS(i32 %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %64, label %54
54: ; preds = %50
br label %55
55: ; preds = %54
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %4
%58 = load i64, i64* %5
%59 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %57, i64 %58, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%60 = load i32, i32* @stderr
%61 = call i32 @fflush(i32 %60)
%62 = call i32 @_exit(i32 111)
unreachable
63: ; No predecessors!
br label %64
64: ; preds = %63, %50
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"%s:%llu: %s\0A\00"
@.str.1 = [15 x i8] c"unable to fork\00"
@.str.2 = [15 x i8] c"process killed\00"
@.str.3 = [31 x i8] c"process exited with status = 0\00"
define void @_run_mustfail(i8* %0, i64 %1, void ()* nocapture %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (...) @fork()
switch i32 %6, label %16 [
i32 -1, label %7
i32 0, label %13
]
7: ; preds = %3
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = tail call i32 @fflush(i32 %10)
%12 = tail call i32 @_exit(i32 111)
unreachable
13: ; preds = %3
%14 = tail call i32 @close(i32 2)
tail call void %2()
%15 = tail call i32 @_exit(i32 0)
unreachable
16: ; preds = %3, %16
%17 = call i32 @waitpid(i32 %6, i32* %4, i32 0)
%18 = icmp eq i32 %17, %6
br i1 %18, label %19, label %16
19: ; preds = %16
%20 = load i32, i32* %4
%21 = call i32 @WIFEXITED(i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %19
%24 = load i32, i32* @stderr
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @stderr
%27 = call i32 @fflush(i32 %26)
%28 = call i32 @_exit(i32 111)
unreachable
29: ; preds = %19
%30 = load i32, i32* %4
%31 = call i32 @WEXITSTATUS(i32 %30)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %1, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%36 = load i32, i32* @stderr
%37 = call i32 @fflush(i32 %36)
%38 = call i32 @_exit(i32 111)
unreachable
39: ; preds = %29
ret void
}