#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() {
  int val = (*(volatile unsigned long *)0x7F008924) &
            ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
  (*(volatile unsigned long *)0x7F008924) = ~0x0;
  switch (val) {
  case (1):
    led_on();
    break;
  case (1 << 1):
    led_off();
    break;
  case (1 << 2):
    led_on();
    break;
  case (1 << 3):
    led_off();
    break;
  default:
    break;
  }
}


x86 assembly (clang, -O0):
<handle_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x7f008924,%rax
7f
and    $0xf,%eax
mov    %eax,-0x4(%rbp)
movq   $0xffffffffffffffff,0x7f008924
7f ff ff ff ff
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x7,%eax
ja     119b <handle_int+0x7b>
mov    -0x10(%rbp),%rax
lea    0xe9e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <led_on@plt>
jmp    11a0 <handle_int+0x80>
mov    $0x0,%al
call   1030 <led_off@plt>
jmp    11a0 <handle_int+0x80>
mov    $0x0,%al
call   1040 <led_on@plt>
jmp    11a0 <handle_int+0x80>
mov    $0x0,%al
call   1030 <led_off@plt>
jmp    11a0 <handle_int+0x80>
jmp    11a0 <handle_int+0x80>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_int>:
mov    0x7f008924,%rax
7f
and    $0xf,%eax
movq   $0xffffffffffffffff,0x7f008924
7f ff ff ff ff
add    $0xffffffff,%eax
cmp    $0x7,%eax
ja     115d <handle_int+0x3d>
lea    0xeba(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %eax,%eax
jmp    1040 <led_on@plt>
xor    %eax,%eax
jmp    1030 <led_off@plt>
ret

LLVM IR (-O0):
define void @handle_int() {
%1 = alloca i32
%2 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%3 = and i64 %2, 15
%4 = trunc i64 %3 to i32
store i32 %4, i32* %1
store volatile i64 -1, i64* inttoptr (i64 2130741540 to i64*)
%5 = load i32, i32* %1
switch i32 %5, label %14 [
i32 1, label %6
i32 2, label %8
i32 4, label %10
i32 8, label %12
]
6: ; preds = %0
%7 = call i32 (...) @led_on()
br label %15
8: ; preds = %0
%9 = call i32 (...) @led_off()
br label %15
10: ; preds = %0
%11 = call i32 (...) @led_on()
br label %15
12: ; preds = %0
%13 = call i32 (...) @led_off()
br label %15
14: ; preds = %0
br label %15
15: ; preds = %14, %12, %10, %8, %6
ret void
}

LLVM IR (-O2):
define void @handle_int() {
%1 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%2 = trunc i64 %1 to i32
%3 = and i32 %2, 15
store volatile i64 -1, i64* inttoptr (i64 2130741540 to i64*)
switch i32 %3, label %12 [
i32 1, label %4
i32 2, label %6
i32 4, label %8
i32 8, label %10
]
4: ; preds = %0
%5 = tail call i32 (...) @led_on()
br label %12
6: ; preds = %0
%7 = tail call i32 (...) @led_off()
br label %12
8: ; preds = %0
%9 = tail call i32 (...) @led_on()
br label %12
10: ; preds = %0
%11 = tail call i32 (...) @led_off()
br label %12
12: ; preds = %0, %10, %8, %6, %4
ret void
}