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

/* Variables and functions */
int /*<<< orphan*/ ALOGE(char *, ...);
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ free(char **);
int __ycheck(const char *e, const char *file, unsigned int line) {
  ALOGE("%s:%u: failed assertion '%s'", file, line, e);
  void *callstack[128];
  int frames = backtrace(callstack, sizeof(callstack) / sizeof(callstack[0]));
  char **symbols = backtrace_symbols(callstack, frames);
  if (symbols != NULL) {
    int i;
    for (i = 0; i < frames; i++) {
      ALOGE("[%d] %s", i, (symbols[i] == NULL) ? "<unknown>" : symbols[i]);
    }
    free(symbols);
  }
  return 1;
}


x86 assembly (clang, -O0):
<__ycheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rcx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1060 <ALOGE@plt>
lea    -0x420(%rbp),%rdi
mov    $0x80,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x424(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x424(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     1255 <__ycheck+0x115>
movl   $0x0,-0x434(%rbp)
mov    -0x434(%rbp),%eax
cmp    -0x424(%rbp),%eax
jge    1249 <__ycheck+0x109>
mov    -0x434(%rbp),%eax
mov    %eax,-0x438(%rbp)
mov    -0x430(%rbp),%rax
movslq -0x434(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
jne    1201 <__ycheck+0xc1>
lea    0xe30(%rip),%rax
mov    %rax,-0x440(%rbp)
jmp    121a <__ycheck+0xda>
mov    -0x430(%rbp),%rax
movslq -0x434(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x440(%rbp)
mov    -0x438(%rbp),%esi
mov    -0x440(%rbp),%rdx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1060 <ALOGE@plt>
mov    -0x434(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x434(%rbp)
jmp    11b7 <__ycheck+0x77>
mov    -0x430(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__ycheck>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rdi,%rcx
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1060 <ALOGE@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x80,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %rax,%rax
je     11c8 <__ycheck+0x88>
mov    %rax,%r15
test   %ebx,%ebx
jle    11c0 <__ycheck+0x80>
mov    %ebx,%r12d
lea    0xe92(%rip),%r13
lea    0xe83(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r15,%rbx,8),%rdx
test   %rdx,%rdx
cmove  %r13,%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <ALOGE@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11a0 <__ycheck+0x60>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"%s:%u: failed assertion '%s'\00"
@.str.1 = [8 x i8] c"[%d] %s\00"
@.str.2 = [10 x i8] c"<unknown>\00"
define i32 @__ycheck(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [128 x i8*]
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = load i8*, i8** %4
%14 = call i32 (i8*, ...) @ALOGE(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %11, i32 %12, i8* %13)
%15 = getelementptr inbounds [128 x i8*], [128 x i8*]* %7, i64 0, i64 0
%16 = call i32 @backtrace(i8** %15, i32 128)
store i32 %16, i32* %8
%17 = getelementptr inbounds [128 x i8*], [128 x i8*]* %7, i64 0, i64 0
%18 = load i32, i32* %8
%19 = call i8** @backtrace_symbols(i8** %17, i32 %18)
store i8** %19, i8*** %9
%20 = load i8**, i8*** %9
%21 = icmp ne i8** %20, null
br i1 %21, label %22, label %51
22: ; preds = %3
store i32 0, i32* %10
br label %23
23: ; preds = %45, %22
%24 = load i32, i32* %10
%25 = load i32, i32* %8
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %48
27: ; preds = %23
%28 = load i32, i32* %10
%29 = load i8**, i8*** %9
%30 = load i32, i32* %10
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %29, i64 %31
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %36
35: ; preds = %27
br label %42
36: ; preds = %27
%37 = load i8**, i8*** %9
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
br label %42
42: ; preds = %36, %35
%43 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %35 ], [ %41, %36 ]
%44 = call i32 (i8*, ...) @ALOGE(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %28, i8* %43)
br label %45
45: ; preds = %42
%46 = load i32, i32* %10
%47 = add nsw i32 %46, 1
store i32 %47, i32* %10
br label %23
48: ; preds = %23
%49 = load i8**, i8*** %9
%50 = call i32 @free(i8** %49)
br label %51
51: ; preds = %48, %3
ret i32 1
}

LLVM IR (-O2):
@.str = [29 x i8] c"%s:%u: failed assertion '%s'\00"
@.str.1 = [8 x i8] c"[%d] %s\00"
@.str.2 = [10 x i8] c"<unknown>\00"
define i32 @__ycheck(i8* %0, i8* %1, i32 %2) {
%4 = alloca [128 x i8*]
%5 = tail call i32 (i8*, ...) @ALOGE(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %2, i8* %0)
%6 = bitcast [128 x i8*]* %4 to i8*
%7 = getelementptr inbounds [128 x i8*], [128 x i8*]* %4, i64 0, i64 0
%8 = call i32 @backtrace(i8** %7, i32 128)
%9 = call i8** @backtrace_symbols(i8** %7, i32 %8)
%10 = icmp eq i8** %9, null
br i1 %10, label %27, label %11
11: ; preds = %3
%12 = icmp sgt i32 %8, 0
br i1 %12, label %13, label %25
13: ; preds = %11
%14 = zext i32 %8 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %23, %15 ]
%17 = getelementptr inbounds i8*, i8** %9, i64 %16
%18 = load i8*, i8** %17
%19 = icmp eq i8* %18, null
%20 = select i1 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %18
%21 = trunc i64 %16 to i32
%22 = call i32 (i8*, ...) @ALOGE(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %20)
%23 = add nuw nsw i64 %16, 1
%24 = icmp eq i64 %23, %14
br i1 %24, label %25, label %15
25: ; preds = %15, %11
%26 = call i32 @free(i8** %9)
br label %27
27: ; preds = %25, %3
ret i32 1
}