#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*/ arm_invalidate_i_cache();
int /*<<< orphan*/ dputs(char *);
int /*<<< orphan*/ keyboard_int_handler();
int /*<<< orphan*/ network_int_handler();
int /*<<< orphan*/ puts(char *);
void irq_handler(void) {
  int vector;
  arm_invalidate_i_cache();
  vector = *((volatile unsigned int *)((
      (((((((0xf0000000)) + (4 * 1024 * 1024)) + (4 * 1024 * 1024)) +
         (4 * 1024 * 1024)) +
        (4 * 1024 * 1024)) +
       (4 * 1024 * 1024)) +
      20)));
  switch (vector) {
  case 0:
    dputs("irq timer\n");
    *((volatile unsigned int *)((
        ((((((0xf0000000)) + (4 * 1024 * 1024)) + (4 * 1024 * 1024)) +
          (4 * 1024 * 1024)) +
         (4 * 1024 * 1024)) +
        8))) = 1;
    break;
  case 1:
    dputs("irq keyboard\n");
    keyboard_int_handler();
    break;
  case 2:
    dputs("irq network\n");
    network_int_handler();
    break;
  default:
    puts("unknown irq\n");
    break;
  case 0xffffffff:
    break;
  }
}


x86 assembly (clang, -O0):
<irq_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <arm_invalidate_i_cache@plt>
mov    $0xf1400014,%eax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11de <irq_handler+0x8e>
mov    -0x10(%rbp),%rax
lea    0xe77(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe77(%rip),%rdi
call   1040 <dputs@plt>
mov    $0xf1000008,%eax
movl   $0x1,(%rax)
jmp    11f4 <irq_handler+0xa4>
lea    0xe66(%rip),%rdi
call   1040 <dputs@plt>
mov    $0x0,%al
call   1060 <keyboard_int_handler@plt>
jmp    11f4 <irq_handler+0xa4>
lea    0xe5c(%rip),%rdi
call   1040 <dputs@plt>
mov    $0x0,%al
call   1070 <network_int_handler@plt>
jmp    11f4 <irq_handler+0xa4>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
jmp    11f4 <irq_handler+0xa4>
jmp    11f4 <irq_handler+0xa4>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<irq_handler>:
push   %rbx
mov    $0xf1000008,%ebx
xor    %eax,%eax
call   1050 <arm_invalidate_i_cache@plt>
mov    0x40000c(%rbx),%eax
add    $0x1,%eax
cmp    $0x3,%eax
ja     118f <irq_handler+0x3f>
lea    0xe8e(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe8e(%rip),%rdi
call   1040 <dputs@plt>
movl   $0x1,(%rbx)
pop    %rbx
ret
lea    0xea0(%rip),%rdi
pop    %rbx
jmp    1030 <puts@plt>
lea    0xe78(%rip),%rdi
call   1040 <dputs@plt>
xor    %eax,%eax
pop    %rbx
jmp    1060 <keyboard_int_handler@plt>
lea    0xe72(%rip),%rdi
call   1040 <dputs@plt>
xor    %eax,%eax
pop    %rbx
jmp    1070 <network_int_handler@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"irq timer\0A\00"
@.str.1 = [14 x i8] c"irq keyboard\0A\00"
@.str.2 = [13 x i8] c"irq network\0A\00"
@.str.3 = [13 x i8] c"unknown irq\0A\00"
define void @irq_handler() {
%1 = alloca i32
%2 = call i32 (...) @arm_invalidate_i_cache()
%3 = load volatile i32, i32* inttoptr (i64 4047503380 to i32*)
store i32 %3, i32* %1
%4 = load i32, i32* %1
switch i32 %4, label %13 [
i32 0, label %5
i32 1, label %7
i32 2, label %10
i32 -1, label %15
]
5: ; preds = %0
%6 = call i32 @dputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store volatile i32 1, i32* inttoptr (i64 4043309064 to i32*)
br label %16
7: ; preds = %0
%8 = call i32 @dputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (...) @keyboard_int_handler()
br label %16
10: ; preds = %0
%11 = call i32 @dputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 (...) @network_int_handler()
br label %16
13: ; preds = %0
%14 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %16
15: ; preds = %0
br label %16
16: ; preds = %15, %13, %10, %7, %5
ret void
}

LLVM IR (-O2):
@.str = [11 x i8] c"irq timer\0A\00"
@.str.1 = [14 x i8] c"irq keyboard\0A\00"
@.str.2 = [13 x i8] c"irq network\0A\00"
@.str.3 = [13 x i8] c"unknown irq\0A\00"
define void @irq_handler() {
%1 = tail call i32 (...) @arm_invalidate_i_cache()
%2 = load volatile i32, i32* inttoptr (i64 4047503380 to i32*)
switch i32 %2, label %11 [
i32 0, label %3
i32 1, label %5
i32 2, label %8
i32 -1, label %13
]
3: ; preds = %0
%4 = tail call i32 @dputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
store volatile i32 1, i32* inttoptr (i64 4043309064 to i32*)
br label %13
5: ; preds = %0
%6 = tail call i32 @dputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call i32 (...) @keyboard_int_handler()
br label %13
8: ; preds = %0
%9 = tail call i32 @dputs(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 (...) @network_int_handler()
br label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %0, %11, %8, %5, %3
ret void
}