#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*/ led_off();
int /*<<< orphan*/ led_on();
void handle_int() {
  unsigned long value = *((volatile unsigned long *)0x4a000014);
  switch (value) {
  case 0:
    led_on();
    break;
  case 1:
    led_off();
    break;
  case 2:
    led_on();
    break;
  case 4:
    led_off();
    break;
  default:
    break;
  }
  if (4 == value)
    *((volatile unsigned long *)0x560000a8) |= (1 << 4);
  *((volatile unsigned long *)0x4a000000) |= (1 << value);
  *((volatile unsigned long *)0x4a000010) |= (1 << value);
}


x86 assembly (clang, -O0):
<handle_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x4a000014,%rax
4a
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
sub    $0x4,%rax
ja     118a <handle_int+0x6a>
mov    -0x10(%rbp),%rax
lea    0xeaf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <led_on@plt>
jmp    118f <handle_int+0x6f>
mov    $0x0,%al
call   1030 <led_off@plt>
jmp    118f <handle_int+0x6f>
mov    $0x0,%al
call   1040 <led_on@plt>
jmp    118f <handle_int+0x6f>
mov    $0x0,%al
call   1030 <led_off@plt>
jmp    118f <handle_int+0x6f>
jmp    118f <handle_int+0x6f>
mov    $0x4,%eax
cmp    -0x8(%rbp),%rax
jne    11b2 <handle_int+0x92>
mov    $0x560000a8,%eax
mov    (%rax),%rcx
or     $0x10,%rcx
mov    $0x560000a8,%eax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    $0x4a000000,%ecx
mov    (%rcx),%rcx
or     %rax,%rcx
mov    $0x4a000000,%eax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
cltq
mov    $0x4a000010,%ecx
mov    (%rcx),%rcx
or     %rax,%rcx
mov    $0x4a000010,%eax
mov    %rcx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_int>:
push   %rbx
mov    0x4a000014,%rbx
4a
cmp    $0x4,%rbx
ja     1161 <handle_int+0x41>
lea    0xeca(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
call   1040 <led_on@plt>
jmp    1161 <handle_int+0x41>
xor    %eax,%eax
call   1030 <led_off@plt>
jmp    1161 <handle_int+0x41>
xor    %eax,%eax
call   1030 <led_off@plt>
orq    $0x10,0x560000a8
56 10
mov    $0x1,%eax
mov    %ebx,%ecx
shl    %cl,%eax
cltq
or     %rax,0x4a000000
4a
or     %rax,0x4a000010
4a
pop    %rbx
ret

LLVM IR (-O0):
define void @handle_int() {
%1 = alloca i64
%2 = load volatile i64, i64* inttoptr (i64 1241514004 to i64*)
store i64 %2, i64* %1
%3 = load i64, i64* %1
switch i64 %3, label %12 [
i64 0, label %4
i64 1, label %6
i64 2, label %8
i64 4, label %10
]
4: ; preds = %0
%5 = call i32 (...) @led_on()
br label %13
6: ; preds = %0
%7 = call i32 (...) @led_off()
br label %13
8: ; preds = %0
%9 = call i32 (...) @led_on()
br label %13
10: ; preds = %0
%11 = call i32 (...) @led_off()
br label %13
12: ; preds = %0
br label %13
13: ; preds = %12, %10, %8, %6, %4
%14 = load i64, i64* %1
%15 = icmp eq i64 4, %14
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load volatile i64, i64* inttoptr (i64 1442840744 to i64*)
%18 = or i64 %17, 16
store volatile i64 %18, i64* inttoptr (i64 1442840744 to i64*)
br label %19
19: ; preds = %16, %13
%20 = load i64, i64* %1
%21 = trunc i64 %20 to i32
%22 = shl i32 1, %21
%23 = sext i32 %22 to i64
%24 = load volatile i64, i64* inttoptr (i64 1241513984 to i64*)
%25 = or i64 %24, %23
store volatile i64 %25, i64* inttoptr (i64 1241513984 to i64*)
%26 = load i64, i64* %1
%27 = trunc i64 %26 to i32
%28 = shl i32 1, %27
%29 = sext i32 %28 to i64
%30 = load volatile i64, i64* inttoptr (i64 1241514000 to i64*)
%31 = or i64 %30, %29
store volatile i64 %31, i64* inttoptr (i64 1241514000 to i64*)
ret void
}

LLVM IR (-O2):
define void @handle_int() {
%1 = load volatile i64, i64* inttoptr (i64 1241514004 to i64*)
switch i64 %1, label %12 [
i64 0, label %2
i64 1, label %4
i64 2, label %6
i64 4, label %8
]
2: ; preds = %0
%3 = tail call i32 (...) @led_on()
br label %12
4: ; preds = %0
%5 = tail call i32 (...) @led_off()
br label %12
6: ; preds = %0
%7 = tail call i32 (...) @led_on()
br label %12
8: ; preds = %0
%9 = tail call i32 (...) @led_off()
%10 = load volatile i64, i64* inttoptr (i64 1442840744 to i64*)
%11 = or i64 %10, 16
store volatile i64 %11, i64* inttoptr (i64 1442840744 to i64*)
br label %12
12: ; preds = %2, %4, %6, %0, %8
%13 = trunc i64 %1 to i32
%14 = shl nuw i32 1, %13
%15 = sext i32 %14 to i64
%16 = load volatile i64, i64* inttoptr (i64 1241513984 to i64*)
%17 = or i64 %16, %15
store volatile i64 %17, i64* inttoptr (i64 1241513984 to i64*)
%18 = load volatile i64, i64* inttoptr (i64 1241514000 to i64*)
%19 = or i64 %18, %15
store volatile i64 %19, i64* inttoptr (i64 1241514000 to i64*)
ret void
}