#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 assert_exception_caught(char *, int, unsigned int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int,
                           unsigned int, unsigned int);
int /*<<< orphan*/ stderr;
int assert_tlb_exception_caught(char *testname, int number,
                                unsigned int expectedpc, unsigned int vpn) {
  if (assert_exception_caught(testname, number, expectedpc) == 1) {
    return 1;
  }
  unsigned int pteh = (*((volatile unsigned long *)(0xFF000000)));
  if ((pteh & 0xFFFFFC00) != (vpn & 0xFFFFFC00)) {
    fprintf(stderr,
            "%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\n",
            testname, number, (vpn >> 10), (pteh >> 10));
    return 1;
  }
  unsigned int tea = (*((volatile unsigned long *)(0xFF00000C)));
  if (tea != vpn) {
    fprintf(stderr, "%s: Test %d failed: Expected TEA = %08X, but was %08X\n",
            testname, number, vpn, tea);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<assert_tlb_exception_caught>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1030 <assert_exception_caught@plt>
cmp    $0x1,%eax
jne    1159 <assert_tlb_exception_caught+0x39>
movl   $0x1,-0x4(%rbp)
jmp    1203 <assert_tlb_exception_caught+0xe3>
mov    $0xff000000,%eax
mov    (%rax),%rax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
and    $0xfffffc00,%eax
mov    -0x1c(%rbp),%ecx
and    $0xfffffc00,%ecx
cmp    %ecx,%eax
je     11b5 <assert_tlb_exception_caught+0x95>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
shr    $0xa,%r8d
mov    -0x20(%rbp),%r9d
shr    $0xa,%r9d
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1203 <assert_tlb_exception_caught+0xe3>
mov    $0xff00000c,%eax
mov    (%rax),%rax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11fc <assert_tlb_exception_caught+0xdc>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    -0x24(%rbp),%r9d
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1203 <assert_tlb_exception_caught+0xe3>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<assert_tlb_exception_caught>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %esi,%r14d
mov    %rdi,%rbp
call   1030 <assert_exception_caught@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    $0x1,%ecx
je     1199 <assert_tlb_exception_caught+0x79>
mov    $0xff000000,%eax
mov    (%rax),%r9
mov    %r9d,%ecx
xor    %ebx,%ecx
cmp    $0x400,%ecx
jae    116f <assert_tlb_exception_caught+0x4f>
mov    0xc(%rax),%r9
xor    %eax,%eax
cmp    %ebx,%r9d
je     1199 <assert_tlb_exception_caught+0x79>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xecf(%rip),%rsi
jmp    1186 <assert_tlb_exception_caught+0x66>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
shr    $0xa,%ebx
shr    $0xa,%r9d
lea    0xe7a(%rip),%rsi
mov    %rbp,%rdx
mov    %r14d,%ecx
mov    %ebx,%r8d
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [60 x i8] c"%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\0A\00"
@.str.1 = [55 x i8] c"%s: Test %d failed: Expected TEA = %08X, but was %08X\0A\00"
define i32 @assert_tlb_exception_caught(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = call i32 @assert_exception_caught(i8* %12, i32 %13, i32 %14)
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 1, i32* %5
br label %49
18: ; preds = %4
%19 = load volatile i64, i64* inttoptr (i64 4278190080 to i64*)
%20 = trunc i64 %19 to i32
store i32 %20, i32* %10
%21 = load i32, i32* %10
%22 = and i32 %21, -1024
%23 = load i32, i32* %9
%24 = and i32 %23, -1024
%25 = icmp ne i32 %22, %24
br i1 %25, label %26, label %35
26: ; preds = %18
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = load i32, i32* %9
%31 = lshr i32 %30, 10
%32 = load i32, i32* %10
%33 = lshr i32 %32, 10
%34 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %28, i32 %29, i32 %31, i32 %33)
store i32 1, i32* %5
br label %49
35: ; preds = %18
%36 = load volatile i64, i64* inttoptr (i64 4278190092 to i64*)
%37 = trunc i64 %36 to i32
store i32 %37, i32* %11
%38 = load i32, i32* %11
%39 = load i32, i32* %9
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %48
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %6
%44 = load i32, i32* %7
%45 = load i32, i32* %9
%46 = load i32, i32* %11
%47 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %43, i32 %44, i32 %45, i32 %46)
store i32 1, i32* %5
br label %49
48: ; preds = %35
store i32 0, i32* %5
br label %49
49: ; preds = %48, %41, %26, %17
%50 = load i32, i32* %5
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [60 x i8] c"%s: Test %d failed: Expected PTEH.VPN = %08X, but was %08X\0A\00"
@.str.1 = [55 x i8] c"%s: Test %d failed: Expected TEA = %08X, but was %08X\0A\00"
define i32 @assert_tlb_exception_caught(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = tail call i32 @assert_exception_caught(i8* %0, i32 %1, i32 %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %24, label %7
7: ; preds = %4
%8 = load volatile i64, i64* inttoptr (i64 4278190080 to i64*)
%9 = trunc i64 %8 to i32
%10 = xor i32 %9, %3
%11 = icmp ult i32 %10, 1024
br i1 %11, label %17, label %12
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = lshr i32 %3, 10
%15 = lshr i32 %9, 10
%16 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %14, i32 %15)
br label %24
17: ; preds = %7
%18 = load volatile i64, i64* inttoptr (i64 4278190092 to i64*)
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %19, %3
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i32 %3, i32 %19)
br label %24
24: ; preds = %12, %17, %21, %4
%25 = phi i32 [ 1, %4 ], [ 1, %12 ], [ 1, %21 ], [ 0, %17 ]
ret i32 %25
}