#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*/ sprintf(char *, char *, unsigned long volatile);
int /*<<< orphan*/ uart_puts(char *);
int rac_setting(int value) {
  int rac_value;
  char msg[256];
  switch (value) {
  case 0:
    rac_value = 0x00;
    break;
  case 1:
    rac_value = 0x94;
    break;
  case 2:
    rac_value = 0x00;
    break;
  case 3:
    rac_value = 0xD4;
    break;
  default:
    rac_value = 0x00;
    break;
  }
  *((volatile unsigned long *)0xffe0040c) = 0x01;
  while ((*((volatile unsigned long *)0xffe00424) & 0xffff) != 0)
    ;
  *((volatile unsigned long *)0xffe0040c) = 0x00;
  *((volatile unsigned long *)0xffe00408) = 0x08000000;
  *((volatile unsigned long *)0xffe00404) = rac_value;
  sprintf(msg, "after init RAC 0x%08x    \n",
          *((volatile unsigned long *)0xffe00404));
  uart_puts(msg);
}


x86 assembly (clang, -O0):
<rac_setting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x118(%rbp)
sub    $0x3,%rax
ja     1189 <rac_setting+0x69>
mov    -0x118(%rbp),%rax
lea    0xeb0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0xc(%rbp)
jmp    1190 <rac_setting+0x70>
movl   $0x94,-0xc(%rbp)
jmp    1190 <rac_setting+0x70>
movl   $0x0,-0xc(%rbp)
jmp    1190 <rac_setting+0x70>
movl   $0xd4,-0xc(%rbp)
jmp    1190 <rac_setting+0x70>
movl   $0x0,-0xc(%rbp)
mov    $0xffe0040c,%eax
movq   $0x1,(%rax)
mov    $0xffe00424,%eax
mov    (%rax),%rax
and    $0xffff,%rax
cmp    $0x0,%rax
je     11b9 <rac_setting+0x99>
jmp    119c <rac_setting+0x7c>
mov    $0xffe0040c,%eax
movq   $0x0,(%rax)
mov    $0xffe00408,%eax
movq   $0x8000000,(%rax)
movslq -0xc(%rbp),%rcx
mov    $0xffe00404,%eax
mov    %rcx,(%rax)
lea    -0x110(%rbp),%rdi
mov    $0xffe00404,%eax
mov    (%rax),%rdx
lea    0xe1d(%rip),%rsi
call   1030 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1040 <uart_puts@plt>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rac_setting>:
push   %rbx
sub    $0x100,%rsp
mov    $0xffe00404,%eax
movq   $0x1,0x8(%rax)
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x20(%rax),%rcx
test   %cx,%cx
jne    1140 <rac_setting+0x20>
xor    %ecx,%ecx
cmp    $0x1,%edi
mov    $0x94,%edx
cmovne %rcx,%rdx
cmp    $0x3,%edi
mov    $0xd4,%ecx
cmovne %rdx,%rcx
movq   $0x0,0x8(%rax)
movq   $0x8000000,0x4(%rax)
08
mov    %rcx,(%rax)
mov    (%rax),%rdx
lea    0xe80(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <uart_puts@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [27 x i8] c"after init RAC 0x%08x \0A\00"
define i32 @rac_setting(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [256 x i8]
store i32 %0, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %11 [
i32 0, label %7
i32 1, label %8
i32 2, label %9
i32 3, label %10
]
7: ; preds = %1
store i32 0, i32* %4
br label %12
8: ; preds = %1
store i32 148, i32* %4
br label %12
9: ; preds = %1
store i32 0, i32* %4
br label %12
10: ; preds = %1
store i32 212, i32* %4
br label %12
11: ; preds = %1
store i32 0, i32* %4
br label %12
12: ; preds = %11, %10, %9, %8, %7
store volatile i64 1, i64* inttoptr (i64 4292871180 to i64*)
br label %13
13: ; preds = %17, %12
%14 = load volatile i64, i64* inttoptr (i64 4292871204 to i64*)
%15 = and i64 %14, 65535
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
store volatile i64 0, i64* inttoptr (i64 4292871180 to i64*)
store volatile i64 134217728, i64* inttoptr (i64 4292871176 to i64*)
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
store volatile i64 %20, i64* inttoptr (i64 4292871172 to i64*)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = load volatile i64, i64* inttoptr (i64 4292871172 to i64*)
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%25 = call i32 @uart_puts(i8* %24)
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
@.str = [27 x i8] c"after init RAC 0x%08x \0A\00"
define i32 @rac_setting(i32 %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
store volatile i64 1, i64* inttoptr (i64 4292871180 to i64*)
br label %4
4: ; preds = %4, %1
%5 = load volatile i64, i64* inttoptr (i64 4292871204 to i64*)
%6 = and i64 %5, 65535
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
%9 = icmp eq i32 %0, 3
%10 = icmp eq i32 %0, 1
%11 = select i1 %10, i64 148, i64 0
%12 = select i1 %9, i64 212, i64 %11
store volatile i64 0, i64* inttoptr (i64 4292871180 to i64*)
store volatile i64 134217728, i64* inttoptr (i64 4292871176 to i64*)
store volatile i64 %12, i64* inttoptr (i64 4292871172 to i64*)
%13 = load volatile i64, i64* inttoptr (i64 4292871172 to i64*)
%14 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i64 %13)
%15 = call i32 @uart_puts(i8* %3)
ret i32 undef
}