#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*/ LOG_ERR;
int /*<<< orphan*/ abort();
int backtrace(void **, int);
char **backtrace_symbols(void **, int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, 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:
    syslog(LOG_ERR, "BUS: invalid address alignment (%p)", info->si_addr);
    break;
  case BUS_ADRERR:
    syslog(LOG_ERR, "BUS: non-existent physical address (%p)", info->si_addr);
    break;
  case BUS_OBJERR:
    syslog(LOG_ERR, "BUS: object specific hardware error (%p)", info->si_addr);
    break;
  default:
    syslog(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) {
    syslog(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     11eb <bus+0xab>
jmp    1179 <bus+0x39>
mov    -0x82c(%rbp),%eax
sub    $0x81,%eax
je     11c8 <bus+0x88>
jmp    118f <bus+0x4f>
mov    -0x82c(%rbp),%eax
sub    $0x82,%eax
jne    120e <bus+0xce>
jmp    11a5 <bus+0x65>
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe44(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
jmp    122c <bus+0xec>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe45(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
jmp    122c <bus+0xec>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
jmp    122c <bus+0xec>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
lea    0xe50(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@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    12a0 <bus+0x160>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x828(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1060 <syslog@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    125d <bus+0x11d>
mov    $0x0,%al
call   1030 <abort@plt>

x86 assembly (clang, -O2):
<bus>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
mov    (%rsi),%eax
add    $0xffffff80,%eax
cmp    $0x2,%eax
ja     116c <bus+0x2c>
cltq
lea    0xf3d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    1173 <bus+0x33>
lea    0xf02(%rip),%rax
mov    0x2e5e(%rip),%r12
mov    (%r12),%edi
mov    0x4(%rsi),%edx
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <syslog@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    11dd <bus+0x9d>
mov    %rax,%r15
mov    %ebx,%r13d
lea    0xed6(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    (%r15,%rbx,8),%rcx
mov    %r14,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1060 <syslog@plt>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11c0 <bus+0x80>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
@LOG_ERR = global i32 0
@.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 %32 [
i32 130, label %14
i32 129, label %20
i32 128, label %26
]
14: ; preds = %3
%15 = load i32, i32* @LOG_ERR
%16 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = call i32 (i32, i8*, i32, ...) @syslog(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %38
20: ; preds = %3
%21 = load i32, i32* @LOG_ERR
%22 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = call i32 (i32, i8*, i32, ...) @syslog(i32 %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %38
26: ; preds = %3
%27 = load i32, i32* @LOG_ERR
%28 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = call i32 (i32, i8*, i32, ...) @syslog(i32 %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %38
32: ; preds = %3
%33 = load i32, i32* @LOG_ERR
%34 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = call i32 (i32, i8*, i32, ...) @syslog(i32 %33, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %32, %26, %20, %14
%39 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%40 = call i32 @backtrace(i8** %39, i32 2048)
store i32 %40, i32* %8
%41 = getelementptr inbounds [256 x i8*], [256 x i8*]* %9, i64 0, i64 0
%42 = load i32, i32* %8
%43 = call i8** @backtrace_symbols(i8** %41, i32 %42)
store i8** %43, i8*** %10
store i32 0, i32* %7
br label %44
44: ; preds = %57, %38
%45 = load i32, i32* %7
%46 = load i32, i32* %8
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %60
48: ; preds = %44
%49 = load i32, i32* @LOG_ERR
%50 = load i32, i32* %7
%51 = load i8**, i8*** %10
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8*, i8** %51, i64 %53
%55 = load i8*, i8** %54
%56 = call i32 (i32, i8*, i32, ...) @syslog(i32 %49, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %50, i8* %55)
br label %57
57: ; preds = %48
%58 = load i32, i32* %7
%59 = add nsw i32 %58, 1
store i32 %59, i32* %7
br label %44
60: ; preds = %44
%61 = call i32 (...) @abort()
unreachable
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
@LOG_ERR = global i32 0
@.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 = load i32, i32* @LOG_ERR
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = tail call i32 (i32, i8*, i32, ...) @syslog(i32 %16, i8* %15, i32 %18)
%20 = getelementptr inbounds [256 x i8*], [256 x i8*]* %4, i64 0, i64 0
%21 = call i32 @backtrace(i8** %20, i32 2048)
%22 = call i8** @backtrace_symbols(i8** %20, i32 %21)
%23 = icmp sgt i32 %21, 0
br i1 %23, label %24, label %35
24: ; preds = %14
%25 = zext i32 %21 to i64
br label %26
26: ; preds = %24, %26
%27 = phi i64 [ 0, %24 ], [ %33, %26 ]
%28 = load i32, i32* @LOG_ERR
%29 = getelementptr inbounds i8*, i8** %22, i64 %27
%30 = load i8*, i8** %29
%31 = trunc i64 %27 to i32
%32 = call i32 (i32, i8*, i32, ...) @syslog(i32 %28, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i32 %31, i8* %30)
%33 = add nuw nsw i64 %27, 1
%34 = icmp eq i64 %33, %25
br i1 %34, label %35, label %26
35: ; preds = %26, %14
%36 = call i32 (...) @abort()
unreachable
}