#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 */
scalar_t__ AllocInstance(void *, int);
void *resolve_symbol(char *);
int run_test() {
  void *a_type_info = resolve_symbol("ktype:A");
  void *(*a_init)(void *) = resolve_symbol("kfun:A.<init>()");
  void *b_type_info = resolve_symbol("ktype:B");
  void *(*b_init)(void *, int) = resolve_symbol("kfun:B.<init>(Int)");
  int (*b_get_a)(void *) = resolve_symbol("kfun:B.<get-a>()");
  void *c_type_info = resolve_symbol("ktype:C");
  void *(*c_init)(void *, int, int) = resolve_symbol("kfun:C.<init>(Int;Int)");
  int (*c_get_a)(void *) = resolve_symbol("kfun:C.<get-a>()");
  void **a = (void **)AllocInstance(a_type_info, 1);
  if ((uintptr_t) * (a) != (uintptr_t)(a_type_info))
    return 1;
  void **b = (void **)AllocInstance(b_type_info, 1);
  if ((uintptr_t) * (b) != (uintptr_t)(b_type_info))
    return 1;
  void *b_obj = b_init((void *)b, 0xdeadbeef);
  if ((uintptr_t) * (b) != (uintptr_t)(b_type_info))
    return 1;
  if (b_get_a(b_obj) != 0xdeadbeef)
    return 1;
  void **c = (void **)AllocInstance(c_type_info, 1);
  if ((uintptr_t) * (c) != (uintptr_t)(c_type_info))
    return 1;
  void *c_obj = c_init((void *)c, 0xcafebabe, 0xabadbabe);
  if ((uintptr_t) * (c) != (uintptr_t)(c_type_info))
    return 1;
  if (c_get_a(c_obj) != 0xcafebabe)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<run_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
lea    0xed1(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x10(%rbp)
lea    0xec9(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x18(%rbp)
lea    0xec9(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x20(%rbp)
lea    0xec1(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x28(%rbp)
lea    0xec4(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x30(%rbp)
lea    0xec5(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x38(%rbp)
lea    0xebd(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x40(%rbp)
lea    0xec4(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1040 <AllocInstance@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    %rcx,%rax
je     11da <run_test+0xba>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <AllocInstance@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    %rcx,%rax
je     120c <run_test+0xec>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
mov    -0x28(%rbp),%rax
mov    -0x58(%rbp),%rdi
mov    $0xdeadbeef,%esi
call   *%rax
mov    %rax,-0x60(%rbp)
mov    -0x58(%rbp),%rax
mov    (%rax),%rax
mov    -0x20(%rbp),%rcx
cmp    %rcx,%rax
je     123f <run_test+0x11f>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
mov    -0x30(%rbp),%rax
mov    -0x60(%rbp),%rdi
call   *%rax
cmp    $0xdeadbeef,%eax
je     1260 <run_test+0x140>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
mov    -0x38(%rbp),%rdi
mov    $0x1,%esi
call   1040 <AllocInstance@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
mov    -0x38(%rbp),%rcx
cmp    %rcx,%rax
je     1292 <run_test+0x172>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
mov    -0x40(%rbp),%rax
mov    -0x68(%rbp),%rdi
mov    $0xcafebabe,%esi
mov    $0xabadbabe,%edx
call   *%rax
mov    %rax,-0x70(%rbp)
mov    -0x68(%rbp),%rax
mov    (%rax),%rax
mov    -0x38(%rbp),%rcx
cmp    %rcx,%rax
je     12ca <run_test+0x1aa>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
mov    -0x48(%rbp),%rax
mov    -0x70(%rbp),%rdi
call   *%rax
cmp    $0xcafebabe,%eax
je     12eb <run_test+0x1cb>
movl   $0x1,-0x4(%rbp)
jmp    12f2 <run_test+0x1d2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xecb(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,%r14
lea    0xec4(%rip),%rdi
call   1030 <resolve_symbol@plt>
lea    0xec8(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,(%rsp)
lea    0xec0(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,0x10(%rsp)
lea    0xec2(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,%r13
lea    0xec4(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,%rbp
lea    0xebd(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,%r15
lea    0xec5(%rip),%rdi
call   1030 <resolve_symbol@plt>
mov    %rax,%r12
mov    $0x1,%ebx
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <AllocInstance@plt>
cmp    %r14,(%rax)
jne    124f <run_test+0x12f>
mov    %r12,0x8(%rsp)
mov    %rbp,%r12
mov    $0x1,%ebx
mov    (%rsp),%r14
mov    %r14,%rdi
mov    $0x1,%esi
call   1040 <AllocInstance@plt>
cmp    %r14,(%rax)
jne    124f <run_test+0x12f>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0xdeadbeef,%esi
call   *0x10(%rsp)
mov    (%rsp),%rcx
cmp    %rcx,0x0(%rbp)
jne    124f <run_test+0x12f>
mov    %rax,%rdi
call   *%r13
cmp    $0xdeadbeef,%eax
jne    124f <run_test+0x12f>
mov    $0x1,%ebx
mov    %r12,%rdi
mov    $0x1,%esi
call   1040 <AllocInstance@plt>
cmp    %r12,(%rax)
jne    124f <run_test+0x12f>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0xcafebabe,%esi
mov    $0xabadbabe,%edx
call   *%r15
cmp    %r12,0x0(%rbp)
mov    0x8(%rsp),%r12
jne    124f <run_test+0x12f>
mov    %rax,%rdi
call   *%r12
xor    %ebx,%ebx
cmp    $0xcafebabe,%eax
setne  %bl
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"ktype:A\00"
@.str.1 = [16 x i8] c"kfun:A.<init>()\00"
@.str.2 = [8 x i8] c"ktype:B\00"
@.str.3 = [19 x i8] c"kfun:B.<init>(Int)\00"
@.str.4 = [17 x i8] c"kfun:B.<get-a>()\00"
@.str.5 = [8 x i8] c"ktype:C\00"
@.str.6 = [23 x i8] c"kfun:C.<init>(Int;Int)\00"
@.str.7 = [17 x i8] c"kfun:C.<get-a>()\00"
define i32 @run_test() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8* (i8*)*
%4 = alloca i8*
%5 = alloca i8* (i8*, i32)*
%6 = alloca i32 (i8*)*
%7 = alloca i8*
%8 = alloca i8* (i8*, i32, i32)*
%9 = alloca i32 (i8*)*
%10 = alloca i8**
%11 = alloca i8**
%12 = alloca i8*
%13 = alloca i8**
%14 = alloca i8*
%15 = call i8* @resolve_symbol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i8* %15, i8** %2
%16 = call i8* @resolve_symbol(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%17 = bitcast i8* %16 to i8* (i8*)*
store i8* (i8*)* %17, i8* (i8*)** %3
%18 = call i8* @resolve_symbol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %4
%19 = call i8* @resolve_symbol(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%20 = bitcast i8* %19 to i8* (i8*, i32)*
store i8* (i8*, i32)* %20, i8* (i8*, i32)** %5
%21 = call i8* @resolve_symbol(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%22 = bitcast i8* %21 to i32 (i8*)*
store i32 (i8*)* %22, i32 (i8*)** %6
%23 = call i8* @resolve_symbol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
store i8* %23, i8** %7
%24 = call i8* @resolve_symbol(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%25 = bitcast i8* %24 to i8* (i8*, i32, i32)*
store i8* (i8*, i32, i32)* %25, i8* (i8*, i32, i32)** %8
%26 = call i8* @resolve_symbol(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%27 = bitcast i8* %26 to i32 (i8*)*
store i32 (i8*)* %27, i32 (i8*)** %9
%28 = load i8*, i8** %2
%29 = call i64 @AllocInstance(i8* %28, i32 1)
%30 = inttoptr i64 %29 to i8**
store i8** %30, i8*** %10
%31 = load i8**, i8*** %10
%32 = load i8*, i8** %31
%33 = ptrtoint i8* %32 to i64
%34 = load i8*, i8** %2
%35 = ptrtoint i8* %34 to i64
%36 = icmp ne i64 %33, %35
br i1 %36, label %37, label %38
37: ; preds = %0
store i32 1, i32* %1
br label %97
38: ; preds = %0
%39 = load i8*, i8** %4
%40 = call i64 @AllocInstance(i8* %39, i32 1)
%41 = inttoptr i64 %40 to i8**
store i8** %41, i8*** %11
%42 = load i8**, i8*** %11
%43 = load i8*, i8** %42
%44 = ptrtoint i8* %43 to i64
%45 = load i8*, i8** %4
%46 = ptrtoint i8* %45 to i64
%47 = icmp ne i64 %44, %46
br i1 %47, label %48, label %49
48: ; preds = %38
store i32 1, i32* %1
br label %97
49: ; preds = %38
%50 = load i8* (i8*, i32)*, i8* (i8*, i32)** %5
%51 = load i8**, i8*** %11
%52 = bitcast i8** %51 to i8*
%53 = call i8* %50(i8* %52, i32 -559038737)
store i8* %53, i8** %12
%54 = load i8**, i8*** %11
%55 = load i8*, i8** %54
%56 = ptrtoint i8* %55 to i64
%57 = load i8*, i8** %4
%58 = ptrtoint i8* %57 to i64
%59 = icmp ne i64 %56, %58
br i1 %59, label %60, label %61
60: ; preds = %49
store i32 1, i32* %1
br label %97
61: ; preds = %49
%62 = load i32 (i8*)*, i32 (i8*)** %6
%63 = load i8*, i8** %12
%64 = call i32 %62(i8* %63)
%65 = icmp ne i32 %64, -559038737
br i1 %65, label %66, label %67
66: ; preds = %61
store i32 1, i32* %1
br label %97
67: ; preds = %61
%68 = load i8*, i8** %7
%69 = call i64 @AllocInstance(i8* %68, i32 1)
%70 = inttoptr i64 %69 to i8**
store i8** %70, i8*** %13
%71 = load i8**, i8*** %13
%72 = load i8*, i8** %71
%73 = ptrtoint i8* %72 to i64
%74 = load i8*, i8** %7
%75 = ptrtoint i8* %74 to i64
%76 = icmp ne i64 %73, %75
br i1 %76, label %77, label %78
77: ; preds = %67
store i32 1, i32* %1
br label %97
78: ; preds = %67
%79 = load i8* (i8*, i32, i32)*, i8* (i8*, i32, i32)** %8
%80 = load i8**, i8*** %13
%81 = bitcast i8** %80 to i8*
%82 = call i8* %79(i8* %81, i32 -889275714, i32 -1414677826)
store i8* %82, i8** %14
%83 = load i8**, i8*** %13
%84 = load i8*, i8** %83
%85 = ptrtoint i8* %84 to i64
%86 = load i8*, i8** %7
%87 = ptrtoint i8* %86 to i64
%88 = icmp ne i64 %85, %87
br i1 %88, label %89, label %90
89: ; preds = %78
store i32 1, i32* %1
br label %97
90: ; preds = %78
%91 = load i32 (i8*)*, i32 (i8*)** %9
%92 = load i8*, i8** %14
%93 = call i32 %91(i8* %92)
%94 = icmp ne i32 %93, -889275714
br i1 %94, label %95, label %96
95: ; preds = %90
store i32 1, i32* %1
br label %97
96: ; preds = %90
store i32 0, i32* %1
br label %97
97: ; preds = %96, %95, %89, %77, %66, %60, %48, %37
%98 = load i32, i32* %1
ret i32 %98
}

LLVM IR (-O2):
@.str = [8 x i8] c"ktype:A\00"
@.str.1 = [16 x i8] c"kfun:A.<init>()\00"
@.str.2 = [8 x i8] c"ktype:B\00"
@.str.3 = [19 x i8] c"kfun:B.<init>(Int)\00"
@.str.4 = [17 x i8] c"kfun:B.<get-a>()\00"
@.str.5 = [8 x i8] c"ktype:C\00"
@.str.6 = [23 x i8] c"kfun:C.<init>(Int;Int)\00"
@.str.7 = [17 x i8] c"kfun:C.<get-a>()\00"
define i32 @run_test() {
%1 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%3 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%5 = bitcast i8* %4 to i8* (i8*, i32)*
%6 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%7 = bitcast i8* %6 to i32 (i8*)*
%8 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%9 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%10 = bitcast i8* %9 to i8* (i8*, i32, i32)*
%11 = tail call i8* @resolve_symbol(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%12 = bitcast i8* %11 to i32 (i8*)*
%13 = tail call i64 @AllocInstance(i8* %1, i32 1)
%14 = inttoptr i64 %13 to i8**
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, %1
br i1 %16, label %17, label %44
17: ; preds = %0
%18 = tail call i64 @AllocInstance(i8* %3, i32 1)
%19 = inttoptr i64 %18 to i8**
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, %3
br i1 %21, label %22, label %44
22: ; preds = %17
%23 = inttoptr i64 %18 to i8*
%24 = tail call i8* %5(i8* %23, i32 -559038737)
%25 = load i8*, i8** %19
%26 = icmp eq i8* %25, %3
br i1 %26, label %27, label %44
27: ; preds = %22
%28 = tail call i32 %7(i8* %24)
%29 = icmp eq i32 %28, -559038737
br i1 %29, label %30, label %44
30: ; preds = %27
%31 = tail call i64 @AllocInstance(i8* %8, i32 1)
%32 = inttoptr i64 %31 to i8**
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, %8
br i1 %34, label %35, label %44
35: ; preds = %30
%36 = inttoptr i64 %31 to i8*
%37 = tail call i8* %10(i8* %36, i32 -889275714, i32 -1414677826)
%38 = load i8*, i8** %32
%39 = icmp eq i8* %38, %8
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = tail call i32 %12(i8* %37)
%42 = icmp ne i32 %41, -889275714
%43 = zext i1 %42 to i32
br label %44
44: ; preds = %17, %30, %40, %35, %27, %22, %0
%45 = phi i32 [ 1, %0 ], [ 1, %17 ], [ 1, %22 ], [ 1, %27 ], [ 1, %30 ], [ 1, %35 ], [ %43, %40 ]
ret i32 %45
}