#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 __builtin_nyuzi_read_control_reg(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
void fault_handler() {
  printf("FAULT %d current flags %02x prev flags %02x\n",
         __builtin_nyuzi_read_control_reg(3),
         __builtin_nyuzi_read_control_reg(4),
         __builtin_nyuzi_read_control_reg(8));
  printf("scratchpad = %08x\n", __builtin_nyuzi_read_control_reg(11));
  exit(0);
}


x86 assembly (clang, -O0):
<fault_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x3,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
mov    %eax,-0x8(%rbp)
mov    $0x4,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
mov    %eax,-0x4(%rbp)
mov    $0x8,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
mov    -0x8(%rbp),%esi
mov    -0x4(%rbp),%edx
mov    %eax,%ecx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0xb,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
mov    %eax,%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<fault_handler>:
push   %rbp
push   %rbx
push   %rax
mov    $0x3,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
mov    %eax,%ebx
mov    $0x4,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
mov    %eax,%ebp
mov    $0x8,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
lea    0xea4(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xb,%edi
call   1040 <__builtin_nyuzi_read_control_reg@plt>
lea    0xeb3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [45 x i8] c"FAULT %d current flags %02x prev flags %02x\0A\00"
@.str.1 = [19 x i8] c"scratchpad = %08x\0A\00"
define void @fault_handler() {
%1 = call i32 @__builtin_nyuzi_read_control_reg(i32 3)
%2 = call i32 @__builtin_nyuzi_read_control_reg(i32 4)
%3 = call i32 @__builtin_nyuzi_read_control_reg(i32 8)
%4 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %3)
%5 = call i32 @__builtin_nyuzi_read_control_reg(i32 11)
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [45 x i8] c"FAULT %d current flags %02x prev flags %02x\0A\00"
@.str.1 = [19 x i8] c"scratchpad = %08x\0A\00"
define void @fault_handler() {
%1 = tail call i32 @__builtin_nyuzi_read_control_reg(i32 3)
%2 = tail call i32 @__builtin_nyuzi_read_control_reg(i32 4)
%3 = tail call i32 @__builtin_nyuzi_read_control_reg(i32 8)
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2, i32 %3)
%5 = tail call i32 @__builtin_nyuzi_read_control_reg(i32 11)
%6 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = tail call i32 @exit(i32 0)
unreachable
}