#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 /*<<< orphan*/ linestr;

/* Variables and functions */
int /*<<< orphan*/ SIGABRT;
int /*<<< orphan*/ SYS_kill;
int /*<<< orphan*/ gotcha_getpid();
int gotcha_strlen(char const *);
int /*<<< orphan*/ gotcha_write(int, char const *, int);
int /*<<< orphan*/ syscall(int /*<<< orphan*/, int /*<<< orphan*/,
                           int /*<<< orphan*/);
int ulong_to_str(unsigned int, char *, int);
void gotcha_assert_fail(const char *s, const char *file, unsigned int line,
                        const char *function) {
  char linestr[64];
  int result;
  result = ulong_to_str(line, linestr, sizeof(linestr) - 1);
  if (result == -1)
    linestr[0] = '\0';
  gotcha_write(2, file, gotcha_strlen(file));
  gotcha_write(2, ":", 1);
  gotcha_write(2, linestr, gotcha_strlen(linestr));
  gotcha_write(2, ": ", 2);
  gotcha_write(2, function, gotcha_strlen(function));
  gotcha_write(2, ": Assertion `", 13);
  gotcha_write(2, s, gotcha_strlen(s));
  gotcha_write(2, "' failed.\n", 10);
  syscall(SYS_kill, gotcha_getpid(), SIGABRT);
}


x86 assembly (clang, -O0):
<gotcha_assert_fail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x3f,%edx
call   1060 <ulong_to_str@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    118c <gotcha_assert_fail+0x3c>
movb   $0x0,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <gotcha_strlen@plt>
mov    -0x88(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1050 <gotcha_write@plt>
mov    $0x2,%edi
lea    0xe41(%rip),%rsi
mov    $0x1,%edx
call   1050 <gotcha_write@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x60(%rbp),%rdi
call   1030 <gotcha_strlen@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1050 <gotcha_write@plt>
mov    $0x2,%edx
lea    0xe0c(%rip),%rsi
mov    %edx,%edi
call   1050 <gotcha_write@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <gotcha_strlen@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1050 <gotcha_write@plt>
mov    $0x2,%edi
lea    0xddb(%rip),%rsi
mov    $0xd,%edx
call   1050 <gotcha_write@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gotcha_strlen@plt>
mov    -0x70(%rbp),%rsi
mov    %eax,%edx
mov    $0x2,%edi
call   1050 <gotcha_write@plt>
mov    $0x2,%edi
lea    0xdb2(%rip),%rsi
mov    $0xa,%edx
call   1050 <gotcha_write@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    $0x0,%al
call   1070 <gotcha_getpid@plt>
mov    -0x68(%rbp),%edi
mov    %eax,%esi
mov    0x2d4e(%rip),%rax
mov    (%rax),%edx
call   1040 <syscall@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gotcha_assert_fail>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rcx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %edx,%edi
mov    $0x3f,%edx
call   1060 <ulong_to_str@plt>
cmp    $0xffffffff,%eax
jne    117a <gotcha_assert_fail+0x2a>
movb   $0x0,(%rsp)
mov    %rbx,%rdi
call   1030 <gotcha_strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <gotcha_write@plt>
lea    0xe68(%rip),%rsi
mov    $0x2,%edi
mov    $0x1,%edx
call   1050 <gotcha_write@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <gotcha_strlen@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <gotcha_write@plt>
lea    0xe3a(%rip),%rsi
mov    $0x2,%edi
mov    $0x2,%edx
call   1050 <gotcha_write@plt>
mov    %r15,%rdi
call   1030 <gotcha_strlen@plt>
mov    $0x2,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <gotcha_write@plt>
lea    0xe10(%rip),%rsi
mov    $0x2,%edi
mov    $0xd,%edx
call   1050 <gotcha_write@plt>
mov    %r14,%rdi
call   1030 <gotcha_strlen@plt>
mov    $0x2,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <gotcha_write@plt>
lea    0xdf1(%rip),%rsi
mov    $0x2,%edi
mov    $0xa,%edx
call   1050 <gotcha_write@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1070 <gotcha_getpid@plt>
mov    0x2d90(%rip),%rcx
mov    (%rcx),%edx
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <syscall@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [14 x i8] c": Assertion `\00"
@.str.3 = [11 x i8] c"' failed.\0A\00"
@SYS_kill = global i32 0
@SIGABRT = global i32 0
define void @gotcha_assert_fail(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [64 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
%11 = load i32, i32* %7
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%13 = call i32 @ulong_to_str(i32 %11, i8* %12, i32 63)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
store i8 0, i8* %17
br label %18
18: ; preds = %16, %4
%19 = load i8*, i8** %6
%20 = load i8*, i8** %6
%21 = call i32 @gotcha_strlen(i8* %20)
%22 = call i32 @gotcha_write(i32 2, i8* %19, i32 %21)
%23 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%25 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%26 = call i32 @gotcha_strlen(i8* %25)
%27 = call i32 @gotcha_write(i32 2, i8* %24, i32 %26)
%28 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%29 = load i8*, i8** %8
%30 = load i8*, i8** %8
%31 = call i32 @gotcha_strlen(i8* %30)
%32 = call i32 @gotcha_write(i32 2, i8* %29, i32 %31)
%33 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 13)
%34 = load i8*, i8** %5
%35 = load i8*, i8** %5
%36 = call i32 @gotcha_strlen(i8* %35)
%37 = call i32 @gotcha_write(i32 2, i8* %34, i32 %36)
%38 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%39 = load i32, i32* @SYS_kill
%40 = call i32 (...) @gotcha_getpid()
%41 = load i32, i32* @SIGABRT
%42 = call i32 @syscall(i32 %39, i32 %40, i32 %41)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c":\00"
@.str.1 = [3 x i8] c": \00"
@.str.2 = [14 x i8] c": Assertion `\00"
@.str.3 = [11 x i8] c"' failed.\0A\00"
@SYS_kill = global i32 0
@SIGABRT = global i32 0
define void @gotcha_assert_fail(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%7 = call i32 @ulong_to_str(i32 %2, i8* %6, i32 63)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %4
store i8 0, i8* %6
br label %10
10: ; preds = %9, %4
%11 = call i32 @gotcha_strlen(i8* %1)
%12 = call i32 @gotcha_write(i32 2, i8* %1, i32 %11)
%13 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = call i32 @gotcha_strlen(i8* %6)
%15 = call i32 @gotcha_write(i32 2, i8* %6, i32 %14)
%16 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
%17 = call i32 @gotcha_strlen(i8* %3)
%18 = call i32 @gotcha_write(i32 2, i8* %3, i32 %17)
%19 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 13)
%20 = call i32 @gotcha_strlen(i8* %0)
%21 = call i32 @gotcha_write(i32 2, i8* %0, i32 %20)
%22 = call i32 @gotcha_write(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 10)
%23 = load i32, i32* @SYS_kill
%24 = call i32 (...) @gotcha_getpid()
%25 = load i32, i32* @SIGABRT
%26 = call i32 @syscall(i32 %23, i32 %24, i32 %25)
ret void
}