#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 /*<<< orphan*/ printf(char *, int, int volatile);
void fault_test_by_unalign(void) {
  volatile int *SCB_CCR = (volatile int *)0xE000ED14;
  volatile int *p;
  volatile int value;
  *SCB_CCR |= (1 << 3);
  p = (int *)0x00;
  value = *p;
  printf("addr:0x%02X value:0x%08X\r\n", (int)p, value);
  p = (int *)0x04;
  value = *p;
  printf("addr:0x%02X value:0x%08X\r\n", (int)p, value);
  p = (int *)0x03;
  value = *p;
  printf("addr:0x%02X value:0x%08X\r\n", (int)p, value);
}


x86 assembly (clang, -O0):
<fault_test_by_unalign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0xe000ed14,%eax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
or     $0x8,%ecx
mov    %ecx,(%rax)
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xeb3(%rip),%rdi
call   1030 <printf@plt>
mov    $0x4,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe8c(%rip),%rdi
call   1030 <printf@plt>
mov    $0x3,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fault_test_by_unalign>:
push   %rbx
sub    $0x10,%rsp
mov    $0xe000ed14,%eax
orl    $0x8,(%rax)
mov    0x0,%eax
mov    %eax,0xc(%rsp)
mov    0xc(%rsp),%edx
lea    0xecd(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x4,%eax
mov    %eax,0xc(%rsp)
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x3,%eax
mov    %eax,0xc(%rsp)
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"addr:0x%02X value:0x%08X\0D\0A\00"
define void @fault_test_by_unalign() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32
store i32* inttoptr (i64 3758157076 to i32*), i32** %1
%4 = load i32*, i32** %1
%5 = load volatile i32, i32* %4
%6 = or i32 %5, 8
store volatile i32 %6, i32* %4
store i32* null, i32** %2
%7 = load i32*, i32** %2
%8 = load volatile i32, i32* %7
store volatile i32 %8, i32* %3
%9 = load i32*, i32** %2
%10 = ptrtoint i32* %9 to i32
%11 = load volatile i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
store i32* inttoptr (i64 4 to i32*), i32** %2
%13 = load i32*, i32** %2
%14 = load volatile i32, i32* %13
store volatile i32 %14, i32* %3
%15 = load i32*, i32** %2
%16 = ptrtoint i32* %15 to i32
%17 = load volatile i32, i32* %3
%18 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
store i32* inttoptr (i64 3 to i32*), i32** %2
%19 = load i32*, i32** %2
%20 = load volatile i32, i32* %19
store volatile i32 %20, i32* %3
%21 = load i32*, i32** %2
%22 = ptrtoint i32* %21 to i32
%23 = load volatile i32, i32* %3
%24 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"addr:0x%02X value:0x%08X\0D\0A\00"
define void @fault_test_by_unalign() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load volatile i32, i32* inttoptr (i64 3758157076 to i32*)
%4 = or i32 %3, 8
store volatile i32 %4, i32* inttoptr (i64 3758157076 to i32*)
%5 = load volatile i32, i32* null
store volatile i32 %5, i32* %1
%6 = load volatile i32, i32* %1
%7 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 0, i32 %6)
%8 = load volatile i32, i32* inttoptr (i64 4 to i32*)
store volatile i32 %8, i32* %1
%9 = load volatile i32, i32* %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 4, i32 %9)
%11 = load volatile i32, i32* inttoptr (i64 3 to i32*)
store volatile i32 %11, i32* %1
%12 = load volatile i32, i32* %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 3, i32 %12)
ret void
}