#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*/ haltdump(char *, int /*<<< orphan*/);
int /*<<< orphan*/ process_irq(int);
int process_syscall(int, int, int, int, int);
int /*<<< orphan*/ send_EOI(int);
int interrupt_handler(int edi, int esi, int ebp, int esp, int ebx, int edx,
                      int ecx, int eax, int num) {
  if (num >= 0x0 && num < 0x20) {
    haltdump("EXCEPTION!", 0);
    return 0;
  } else if (num >= 0x20 && num < 0x30) {
    num -= 0x20;
    process_irq(num);
    send_EOI(num);
    return 0;
  } else if (num == 0x80) {
    return process_syscall(eax, ebx, ecx, edx, esi);
  } else {
    haltdump("Unknown interrupt number.", 0);
    return -1;
  }
}


x86 assembly (clang, -O0):
<interrupt_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
cmpl   $0x0,0x20(%rbp)
jl     1193 <interrupt_handler+0x53>
cmpl   $0x20,0x20(%rbp)
jge    1193 <interrupt_handler+0x53>
lea    0xe80(%rip),%rdi
xor    %esi,%esi
call   1040 <haltdump@plt>
movl   $0x0,-0x4(%rbp)
jmp    120b <interrupt_handler+0xcb>
cmpl   $0x20,0x20(%rbp)
jl     11cc <interrupt_handler+0x8c>
cmpl   $0x30,0x20(%rbp)
jge    11cc <interrupt_handler+0x8c>
mov    0x20(%rbp),%eax
sub    $0x20,%eax
mov    %eax,0x20(%rbp)
mov    0x20(%rbp),%edi
call   1030 <process_irq@plt>
mov    0x20(%rbp),%edi
call   1050 <send_EOI@plt>
movl   $0x0,-0x4(%rbp)
jmp    120b <interrupt_handler+0xcb>
cmpl   $0x80,0x20(%rbp)
jne    11f6 <interrupt_handler+0xb6>
mov    0x18(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x10(%rbp),%edx
mov    -0x1c(%rbp),%ecx
mov    -0xc(%rbp),%r8d
call   1060 <process_syscall@plt>
mov    %eax,-0x4(%rbp)
jmp    120b <interrupt_handler+0xcb>
lea    0xe0e(%rip),%rdi
xor    %esi,%esi
call   1040 <haltdump@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interrupt_handler>:
push   %rbx
mov    0x20(%rsp),%ebx
cmp    $0x1f,%ebx
ja     115c <interrupt_handler+0x1c>
lea    0xeaf(%rip),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
call   1040 <haltdump@plt>
jmp    11af <interrupt_handler+0x6f>
mov    %ebx,%ecx
and    $0xfffffff0,%ecx
cmp    $0x20,%ecx
jne    117b <interrupt_handler+0x3b>
add    $0xffffffe0,%ebx
mov    %ebx,%edi
call   1030 <process_irq@plt>
mov    %ebx,%edi
call   1050 <send_EOI@plt>
xor    %ebx,%ebx
jmp    11af <interrupt_handler+0x6f>
cmp    $0x80,%ebx
jne    119c <interrupt_handler+0x5c>
mov    %esi,%eax
mov    0x18(%rsp),%edi
mov    0x10(%rsp),%edx
mov    %r8d,%esi
mov    %r9d,%ecx
mov    %eax,%r8d
pop    %rbx
jmp    1060 <process_syscall@plt>
lea    0xe68(%rip),%rdi
xor    %esi,%esi
call   1040 <haltdump@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"EXCEPTION!\00"
@.str.1 = [26 x i8] c"Unknown interrupt number.\00"
define i32 @interrupt_handler(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %11
store i32 %1, i32* %12
store i32 %2, i32* %13
store i32 %3, i32* %14
store i32 %4, i32* %15
store i32 %5, i32* %16
store i32 %6, i32* %17
store i32 %7, i32* %18
store i32 %8, i32* %19
%20 = load i32, i32* %19
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %9
%23 = load i32, i32* %19
%24 = icmp slt i32 %23, 32
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @haltdump(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 0, i32* %10
br label %52
27: ; preds = %22, %9
%28 = load i32, i32* %19
%29 = icmp sge i32 %28, 32
br i1 %29, label %30, label %40
30: ; preds = %27
%31 = load i32, i32* %19
%32 = icmp slt i32 %31, 48
br i1 %32, label %33, label %40
33: ; preds = %30
%34 = load i32, i32* %19
%35 = sub nsw i32 %34, 32
store i32 %35, i32* %19
%36 = load i32, i32* %19
%37 = call i32 @process_irq(i32 %36)
%38 = load i32, i32* %19
%39 = call i32 @send_EOI(i32 %38)
store i32 0, i32* %10
br label %52
40: ; preds = %30, %27
%41 = load i32, i32* %19
%42 = icmp eq i32 %41, 128
br i1 %42, label %43, label %50
43: ; preds = %40
%44 = load i32, i32* %18
%45 = load i32, i32* %15
%46 = load i32, i32* %17
%47 = load i32, i32* %16
%48 = load i32, i32* %12
%49 = call i32 @process_syscall(i32 %44, i32 %45, i32 %46, i32 %47, i32 %48)
store i32 %49, i32* %10
br label %52
50: ; preds = %40
%51 = call i32 @haltdump(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 0)
store i32 -1, i32* %10
br label %52
52: ; preds = %50, %43, %33, %25
%53 = load i32, i32* %10
ret i32 %53
}

LLVM IR (-O2):
@.str = [11 x i8] c"EXCEPTION!\00"
@.str.1 = [26 x i8] c"Unknown interrupt number.\00"
define i32 @interrupt_handler(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6, i32 %7, i32 %8) {
%10 = icmp ult i32 %8, 32
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @haltdump(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
br label %26
13: ; preds = %9
%14 = and i32 %8, -16
%15 = icmp eq i32 %14, 32
br i1 %15, label %16, label %20
16: ; preds = %13
%17 = add nsw i32 %8, -32
%18 = tail call i32 @process_irq(i32 %17)
%19 = tail call i32 @send_EOI(i32 %17)
br label %26
20: ; preds = %13
%21 = icmp eq i32 %8, 128
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 @process_syscall(i32 %7, i32 %4, i32 %6, i32 %5, i32 %1)
br label %26
24: ; preds = %20
%25 = tail call i32 @haltdump(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 0)
br label %26
26: ; preds = %24, %22, %16, %11
%27 = phi i32 [ 0, %11 ], [ 0, %16 ], [ %23, %22 ], [ -1, %24 ]
ret i32 %27
}