#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();
int /*<<< orphan*/ tc_handler();
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;
  case 31:
    tc_handler();
    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    $0x1f,%rax
ja     11a6 <handle_int+0x76>
mov    -0x10(%rbp),%rax
lea    0xe9f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <led_on@plt>
jmp    11ab <handle_int+0x7b>
mov    $0x0,%al
call   1030 <led_off@plt>
jmp    11ab <handle_int+0x7b>
mov    $0x0,%al
call   1040 <led_on@plt>
jmp    11ab <handle_int+0x7b>
mov    $0x0,%al
call   1030 <led_off@plt>
jmp    11ab <handle_int+0x7b>
mov    $0x0,%al
call   1050 <tc_handler@plt>
jmp    11ab <handle_int+0x7b>
jmp    11ab <handle_int+0x7b>
mov    $0x4,%eax
cmp    -0x8(%rbp),%rax
jne    11ce <handle_int+0x9e>
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    $0x1f,%rbx
ja     117a <handle_int+0x4a>
lea    0xeba(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
xor    %eax,%eax
call   1040 <led_on@plt>
jmp    117a <handle_int+0x4a>
xor    %eax,%eax
call   1030 <led_off@plt>
jmp    117a <handle_int+0x4a>
xor    %eax,%eax
call   1030 <led_off@plt>
orq    $0x10,0x560000a8
56 10
jmp    117a <handle_int+0x4a>
xor    %eax,%eax
call   1050 <tc_handler@plt>
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 %14 [
i64 0, label %4
i64 1, label %6
i64 2, label %8
i64 4, label %10
i64 31, label %12
]
4: ; preds = %0
%5 = call i32 (...) @led_on()
br label %15
6: ; preds = %0
%7 = call i32 (...) @led_off()
br label %15
8: ; preds = %0
%9 = call i32 (...) @led_on()
br label %15
10: ; preds = %0
%11 = call i32 (...) @led_off()
br label %15
12: ; preds = %0
%13 = call i32 (...) @tc_handler()
br label %15
14: ; preds = %0
br label %15
15: ; preds = %14, %12, %10, %8, %6, %4
%16 = load i64, i64* %1
%17 = icmp eq i64 4, %16
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load volatile i64, i64* inttoptr (i64 1442840744 to i64*)
%20 = or i64 %19, 16
store volatile i64 %20, i64* inttoptr (i64 1442840744 to i64*)
br label %21
21: ; preds = %18, %15
%22 = load i64, i64* %1
%23 = trunc i64 %22 to i32
%24 = shl i32 1, %23
%25 = sext i32 %24 to i64
%26 = load volatile i64, i64* inttoptr (i64 1241513984 to i64*)
%27 = or i64 %26, %25
store volatile i64 %27, i64* inttoptr (i64 1241513984 to i64*)
%28 = load i64, i64* %1
%29 = trunc i64 %28 to i32
%30 = shl i32 1, %29
%31 = sext i32 %30 to i64
%32 = load volatile i64, i64* inttoptr (i64 1241514000 to i64*)
%33 = or i64 %32, %31
store volatile i64 %33, 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 %14 [
i64 0, label %2
i64 1, label %4
i64 2, label %6
i64 4, label %10
i64 31, label %8
]
2: ; preds = %0
%3 = tail call i32 (...) @led_on()
br label %14
4: ; preds = %0
%5 = tail call i32 (...) @led_off()
br label %14
6: ; preds = %0
%7 = tail call i32 (...) @led_on()
br label %14
8: ; preds = %0
%9 = tail call i32 (...) @tc_handler()
br label %14
10: ; preds = %0
%11 = tail call i32 (...) @led_off()
%12 = load volatile i64, i64* inttoptr (i64 1442840744 to i64*)
%13 = or i64 %12, 16
store volatile i64 %13, i64* inttoptr (i64 1442840744 to i64*)
br label %14
14: ; preds = %2, %4, %6, %8, %0, %10
%15 = trunc i64 %1 to i32
%16 = shl nuw i32 1, %15
%17 = sext i32 %16 to i64
%18 = load volatile i64, i64* inttoptr (i64 1241513984 to i64*)
%19 = or i64 %18, %17
store volatile i64 %19, i64* inttoptr (i64 1241513984 to i64*)
%20 = load volatile i64, i64* inttoptr (i64 1241514000 to i64*)
%21 = or i64 %20, %17
store volatile i64 %21, i64* inttoptr (i64 1241514000 to i64*)
ret void
}