#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int si_code;
  int /*<<< orphan*/ si_addr;
};
typedef TYPE_1__ siginfo_t;
typedef int /*<<< orphan*/ pointers;

/* Variables and functions */
#define BUS_ADRALN 130
#define BUS_ADRERR 129
#define BUS_OBJERR 128
int /*<<< orphan*/ abort();
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ log_err(char *, int, ...);
void bus(int sig, siginfo_t *info, void *data) {
  int i;
  int frame_count = 0;
  void *pointers[256];
  switch (info->si_code) {
  case BUS_ADRALN:
    log_err("BUS: invalid address alignment (%p)", info->si_addr);
    break;
  case BUS_ADRERR:
    log_err("BUS: non-existent physical address (%p)", info->si_addr);
    break;
  case BUS_OBJERR:
    log_err("BUS: object specific hardware error (%p)", info->si_addr);
    break;
  default:
    log_err("bus error at address %p\n", info->si_addr);
  }
  frame_count = backtrace(pointers, sizeof(pointers));
  char **frames = backtrace_symbols(pointers, frame_count);
  for (i = 0; i < frame_count; ++i) {
    log_err("frame(%03d): %s", i, frames[i]);
  }
  abort();
}


x86 assembly (clang, -O0):
<bus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x82c(%rbp)
sub    $0x80,%eax
je     11d9 <bus+0x99>
jmp    1179 <bus+0x39>
mov    -0x82c(%rbp),%eax
sub    $0x81,%eax
je     11bf <bus+0x7f>
jmp    118f <bus+0x4f>
mov    -0x82c(%rbp),%eax
sub    $0x82,%eax
jne    11f3 <bus+0xb3>
jmp    11a5 <bus+0x65>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    1208 <bus+0xc8>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    1208 <bus+0xc8>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
jmp    1208 <bus+0xc8>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
lea    -0x820(%rbp),%rdi
mov    $0x800,%esi
call   1050 <backtrace@plt>
mov    %eax,-0x20(%rbp)
lea    -0x820(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <backtrace_symbols@plt>
mov    %rax,-0x828(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1273 <bus+0x133>
mov    -0x1c(%rbp),%esi
mov    -0x828(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <log_err@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1239 <bus+0xf9>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<bus>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    (%rsi),%eax
add    $0xffffff80,%eax
cmp    $0x2,%eax
ja     116a <bus+0x2a>
cltq
lea    0xf3f(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1171 <bus+0x31>
lea    0xf04(%rip),%rdi
mov    0x4(%rsi),%esi
xor    %eax,%eax
call   1060 <log_err@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x800,%esi
call   1050 <backtrace@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <backtrace_symbols@plt>
test   %ebx,%ebx
jle    11c9 <bus+0x89>
mov    %rax,%r15
mov    %ebx,%r12d
lea    0xee6(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdx
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <log_err@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11b0 <bus+0x70>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [36 x i8] c"BUS: invalid address alignment (%p)\00"
@.str.1 = [40 x i8] c"BUS: non-existent physical address (%p)\00"
@.str.2 = [41 x i8] c"BUS: object specific hardware error (%p)\00"
@.str.3 = [25 x i8] c"bus error at address %p\0A\00"
@.str.4 = [16 x i8] c"frame(%03d): %s\00"
define void @bus(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [256 x i8*]
%10 = alloca i8**
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
store i32 0, i32* %8
%11 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%12 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %11, i32 0, i32 0
%13 = load i32, i32* %12
switch i32 %13, label %29 [
i32 130, label %14
i32 129, label %19
i32 128, label %24
]
14: ; preds = %3
%15 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = call i32 (i8*, i32, ...) @log_err(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %17)
br label %34
19: ; preds = %3
%20 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%21 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = call i32 (i8*, i32, ...) @log_err(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %34
24: ; preds = %3
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = call i32 (i8*, i32, ...) @log_err(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %27)
br label %34
29: ; preds = %3
%30 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %30, i32 0, i32 1
%32 = load i32, i32* %31
%33 = call i32 (i8*, i32, ...) @log_err(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %29, %24, %19, %14
%35 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%36 = call i32 @backtrace(i8** %35, i32 2048)
store i32 %36, i32* %8
%37 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%38 = load i32, i32* %8
%39 = call i8** @backtrace_symbols(i8** %37, i32 %38)
store i8** %39, i8*** %10
store i32 0, i32* %7
br label %40
40: ; preds = %52, %34
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %55
44: ; preds = %40
%45 = load i32, i32* %7
%46 = load i8**, i8*** %10
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 (i8*, i32, ...) @log_err(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %45, i8* %50)
br label %52
52: ; preds = %44
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %40
55: ; preds = %40
%56 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@.str = [36 x i8] c"BUS: invalid address alignment (%p)\00"
@.str.1 = [40 x i8] c"BUS: non-existent physical address (%p)\00"
@.str.2 = [41 x i8] c"BUS: object specific hardware error (%p)\00"
@.str.3 = [25 x i8] c"bus error at address %p\0A\00"
@.str.4 = [16 x i8] c"frame(%03d): %s\00"
@reltable.bus = [3 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([41 x i8]* @.str.2 to i64), i64 ptrtoint ([3 x i32]* @reltable.bus to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([40 x i8]* @.str.1 to i64), i64 ptrtoint ([3 x i32]* @reltable.bus to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([36 x i8]* @.str to i64), i64 ptrtoint ([3 x i32]* @reltable.bus to i64)) to i32)]
define void @bus(i32 %0, %struct.TYPE_3__* nocapture %1, i8* nocapture readnone %2) {
%4 = alloca [256 x i8*]
%5 = bitcast [256 x i8*]* %4 to i8*
%6 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = add i32 %7, -128
%9 = icmp ult i32 %8, 3
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = sext i32 %8 to i64
%12 = shl i64 %11, 2
%13 = call i8* @llvm.load.relative.i64(i8* bitcast ([3 x i32]* @reltable.bus to i8*), i64 %12)
br label %14
14: ; preds = %3, %10
%15 = phi i8* [ %13, %10 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), %3 ]
%16 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, i32, ...) @log_err(i8* %15, i32 %17)
%19 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 0
%20 = call i32 @backtrace(i8** %19, i32 2048)
%21 = call i8** @backtrace_symbols(i8** %19, i32 %20)
%22 = icmp sgt i32 %20, 0
br i1 %22, label %23, label %33
23: ; preds = %14
%24 = zext i32 %20 to i64
br label %25
25: ; preds = %23, %25
%26 = phi i64 [ 0, %23 ], [ %31, %25 ]
%27 = getelementptr inbounds i8*, i8** %21, i64 %26
%28 = load i8*, i8** %27
%29 = trunc i64 %26 to i32
%30 = call i32 (i8*, i32, ...) @log_err(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %29, i8* %28)
%31 = add nuw nsw i64 %26, 1
%32 = icmp eq i64 %31, %24
br i1 %32, label %33, label %25
33: ; preds = %25, %14
%34 = call i32 (...) @abort()
unreachable
}