#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 MAP_ANONYMOUS;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int *mmap(int /*<<< orphan*/, int, int, int, int, int /*<<< orphan*/);
int tap_test_died(int status) {
  static int *test_died = NULL;
  int prev;
  if (!test_died) {
    test_died = mmap(0, sizeof(int), PROT_READ | PROT_WRITE,
                     MAP_SHARED | MAP_ANONYMOUS, -1, 0);
    *test_died = 0;
  }
  prev = *test_died;
  *test_died = status;
  return prev;
}


x86 assembly (clang, -O0):
<tap_test_died>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpq   $0x0,0x2f0d(%rip)
jne    1177 <tap_test_died+0x67>
mov    0x2ec8(%rip),%rax
mov    (%rax),%edx
mov    0x2e8f(%rip),%rax
or     (%rax),%edx
mov    0x2ea6(%rip),%rax
mov    (%rax),%ecx
mov    0x2e8d(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0x4,%esi
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
mov    %rax,0x2ec6(%rip)
mov    0x2ebf(%rip),%rax
movl   $0x0,(%rax)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%ecx
mov    0x2ea3(%rip),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tap_test_died>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2f14(%rip),%rax
test   %rax,%rax
je     1125 <tap_test_died+0x15>
mov    (%rax),%ebp
jmp    116d <tap_test_died+0x5d>
mov    0x2ecc(%rip),%rax
mov    0x2e95(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2eaa(%rip),%rax
mov    0x2e93(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %ebp,%ebp
xor    %edi,%edi
mov    $0x4,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,0x2ec9(%rip)
movl   $0x0,(%rax)
mov    %ebx,(%rax)
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@tap_test_died.test_died = internal global i32* null
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
define i32 @tap_test_died(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32*, i32** @tap_test_died.test_died
%5 = icmp ne i32* %4, null
br i1 %5, label %15, label %6
6: ; preds = %1
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %7, %8
%10 = load i32, i32* @MAP_SHARED
%11 = load i32, i32* @MAP_ANONYMOUS
%12 = or i32 %10, %11
%13 = call i32* @mmap(i32 0, i32 4, i32 %9, i32 %12, i32 -1, i32 0)
store i32* %13, i32** @tap_test_died.test_died
%14 = load i32*, i32** @tap_test_died.test_died
store i32 0, i32* %14
br label %15
15: ; preds = %6, %1
%16 = load i32*, i32** @tap_test_died.test_died
%17 = load i32, i32* %16
store i32 %17, i32* %3
%18 = load i32, i32* %2
%19 = load i32*, i32** @tap_test_died.test_died
store i32 %18, i32* %19
%20 = load i32, i32* %3
ret i32 %20
}

LLVM IR (-O2):
@tap_test_died.test_died = internal unnamed_addr global i32* null
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
define i32 @tap_test_died(i32 %0) {
%2 = load i32*, i32** @tap_test_died.test_died
%3 = icmp eq i32* %2, null
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = load i32, i32* %2
br label %14
6: ; preds = %1
%7 = load i32, i32* @PROT_READ
%8 = load i32, i32* @PROT_WRITE
%9 = or i32 %8, %7
%10 = load i32, i32* @MAP_SHARED
%11 = load i32, i32* @MAP_ANONYMOUS
%12 = or i32 %11, %10
%13 = tail call i32* @mmap(i32 0, i32 4, i32 %9, i32 %12, i32 -1, i32 0)
store i32* %13, i32** @tap_test_died.test_died
store i32 0, i32* %13
br label %14
14: ; preds = %4, %6
%15 = phi i32 [ 0, %6 ], [ %5, %4 ]
%16 = phi i32* [ %13, %6 ], [ %2, %4 ]
store i32 %0, i32* %16
ret i32 %15
}