#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 /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *, unsigned long,
                           void *, unsigned long, void *);
int /*<<< orphan*/ stderr;
void read_trap(void *addr, void *oldPC, unsigned long oldTid, void *newPC,
               unsigned long newTid) {
  if (newPC == (void *)0x400c53 && *((unsigned long *)addr) == 0) {
    fprintf(stderr, "M[%p]: T%lu,W@%p -> T%lu,R@%p\n", addr, oldTid, oldPC,
            newTid, newPC);
    fprintf(stderr, "NULL POINTER!!!\n", addr, oldTid, oldPC, newTid, newPC);
    abort();
  }
}


x86 assembly (clang, -O0):
<read_trap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    $0x400c53,%eax
cmp    %rax,-0x20(%rbp)
jne    11ba <read_trap+0x9a>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11ba <read_trap+0x9a>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x20(%rbp),%rax
lea    0xe83(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x28(%rbp),%r9
mov    -0x20(%rbp),%rax
lea    0xe75(%rip),%rsi
mov    %rax,(%rsp)
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_trap>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
cmp    $0x400c53,%rcx
jne    113f <read_trap+0x1f>
mov    %rdi,%rbx
cmpq   $0x0,(%rdi)
je     114d <read_trap+0x2d>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    %r8,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    0x2e83(%rip),%r13
mov    0x0(%r13),%edi
movq   $0x400c53,(%rsp)
lea    0xe90(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r14,%r9
call   1040 <fprintf@plt>
mov    0x0(%r13),%edi
movq   $0x400c53,(%rsp)
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r14,%r9
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"M[%p]: T%lu,W@%p -> T%lu,R@%p\0A\00"
@.str.1 = [17 x i8] c"NULL POINTER!!!\0A\00"
define void @read_trap(i8* %0, i8* %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%11 = load i8*, i8** %9
%12 = icmp eq i8* %11, inttoptr (i64 4197459 to i8*)
br i1 %12, label %13, label %34
13: ; preds = %5
%14 = load i8*, i8** %6
%15 = bitcast i8* %14 to i64*
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %6
%21 = load i64, i64* %8
%22 = load i8*, i8** %7
%23 = load i64, i64* %10
%24 = load i8*, i8** %9
%25 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %20, i64 %21, i8* %22, i64 %23, i8* %24)
%26 = load i32, i32* @stderr
%27 = load i8*, i8** %6
%28 = load i64, i64* %8
%29 = load i8*, i8** %7
%30 = load i64, i64* %10
%31 = load i8*, i8** %9
%32 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %27, i64 %28, i8* %29, i64 %30, i8* %31)
%33 = call i32 (...) @abort()
unreachable
34: ; preds = %13, %5
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"M[%p]: T%lu,W@%p -> T%lu,R@%p\0A\00"
@.str.1 = [17 x i8] c"NULL POINTER!!!\0A\00"
define void @read_trap(i8* %0, i8* %1, i64 %2, i8* readnone %3, i64 %4) {
%6 = icmp eq i8* %3, inttoptr (i64 4197459 to i8*)
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = bitcast i8* %0 to i64*
%9 = load i64, i64* %8
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %2, i8* %1, i64 %4, i8* inttoptr (i64 4197459 to i8*))
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %0, i64 %2, i8* %1, i64 %4, i8* inttoptr (i64 4197459 to i8*))
%16 = tail call i32 (...) @abort()
unreachable
17: ; preds = %7, %5
ret void
}