#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 */
typedef int uint8_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *);
void IO_PrintResetReason(void) {
  uint8_t resetreason = (*(volatile unsigned long *)(0xE01FC000 + 0x180));
  (*(volatile unsigned long *)(0xE01FC000 + 0x180)) = 0x0f;
  printf("\nReset reason(s): %s%s%s%s", (resetreason & (1 << 0)) ? "[POR]" : "",
         (resetreason & (1 << 1)) ? "[EXTR]" : "",
         (resetreason & (1 << 2)) ? "[WDTR]" : "",
         (resetreason & (1 << 3)) ? "[BODR]" : "");
}


x86 assembly (clang, -O0):
<IO_PrintResetReason>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0xe01fc180,%eax
mov    (%rax),%rax
mov    %eax,-0x4(%rbp)
mov    $0xe01fc180,%eax
movq   $0xf,(%rax)
mov    -0x4(%rbp),%ecx
and    $0x1,%ecx
lea    0xef9(%rip),%rsi
lea    0xed8(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
mov    -0x4(%rbp),%ecx
and    $0x2,%ecx
lea    0xede(%rip),%rdx
lea    0xec3(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0x4(%rbp),%edi
and    $0x4,%edi
lea    0xec3(%rip),%rcx
lea    0xeaf(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%rcx
mov    -0x4(%rbp),%edi
and    $0x8,%edi
lea    0xea8(%rip),%r8
lea    0xe9b(%rip),%rax
cmp    $0x0,%edi
cmovne %rax,%r8
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IO_PrintResetReason>:
mov    $0xe01fc180,%eax
mov    (%rax),%rdi
movq   $0xf,(%rax)
test   $0x1,%dil
lea    0xf0b(%rip),%rax
lea    0xeea(%rip),%rsi
cmove  %rax,%rsi
test   $0x2,%dil
lea    0xee1(%rip),%rdx
cmove  %rax,%rdx
test   $0x4,%dil
lea    0xed9(%rip),%rcx
cmove  %rax,%rcx
test   $0x8,%dil
lea    0xed1(%rip),%r8
cmove  %rax,%r8
lea    0xe97(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"\0AReset reason(s): %s%s%s%s\00"
@.str.1 = [6 x i8] c"[POR]\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [7 x i8] c"[EXTR]\00"
@.str.4 = [7 x i8] c"[WDTR]\00"
@.str.5 = [7 x i8] c"[BODR]\00"
define void @IO_PrintResetReason() {
%1 = alloca i32
%2 = load volatile i64, i64* inttoptr (i64 3760177536 to i64*)
%3 = trunc i64 %2 to i32
store i32 %3, i32* %1
store volatile i64 15, i64* inttoptr (i64 3760177536 to i64*)
%4 = load i32, i32* %1
%5 = and i32 %4, 1
%6 = icmp ne i32 %5, 0
%7 = zext i1 %6 to i64
%8 = select i1 %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%9 = load i32, i32* %1
%10 = and i32 %9, 2
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%14 = load i32, i32* %1
%15 = and i32 %14, 4
%16 = icmp ne i32 %15, 0
%17 = zext i1 %16 to i64
%18 = select i1 %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%19 = load i32, i32* %1
%20 = and i32 %19, 8
%21 = icmp ne i32 %20, 0
%22 = zext i1 %21 to i64
%23 = select i1 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0)
%24 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %13, i8* %18, i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"\0AReset reason(s): %s%s%s%s\00"
@.str.1 = [6 x i8] c"[POR]\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [7 x i8] c"[EXTR]\00"
@.str.4 = [7 x i8] c"[WDTR]\00"
@.str.5 = [7 x i8] c"[BODR]\00"
define void @IO_PrintResetReason() {
%1 = load volatile i64, i64* inttoptr (i64 3760177536 to i64*)
%2 = trunc i64 %1 to i32
store volatile i64 15, i64* inttoptr (i64 3760177536 to i64*)
%3 = and i32 %2, 1
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0)
%6 = and i32 %2, 2
%7 = icmp eq i32 %6, 0
%8 = select i1 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0)
%9 = and i32 %2, 4
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0)
%12 = and i32 %2, 8
%13 = icmp eq i32 %12, 0
%14 = select i1 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %5, i8* %8, i8* %11, i8* %14)
ret void
}