#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 */
long install_irq(long IntNumber, void *HandlerAddr) {
  long i;
  long *vect_addr;
  long *vect_cntl;
  (*(volatile unsigned long *)(0xFFFFF000 + 0x014)) = 1 << IntNumber;
  for (i = 0; i < 16; i++) {
    vect_addr = (long *)(0xFFFFF000 + 0x100 + i * 4);
    vect_cntl = (long *)(0xFFFFF000 + 0x200 + i * 4);
    if (*vect_addr == (long)NULL) {
      *vect_addr = (long)HandlerAddr;
      *vect_cntl = (long)(0x20 | IntNumber);
      break;
    }
  }
  if (i == 16) {
    return (0);
  }
  (*(volatile unsigned long *)(0xFFFFF000 + 0x010)) = 1 << IntNumber;
  return (1);
}


x86 assembly (clang, -O0):
<install_irq>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%rcx
mov    $0xfffff014,%eax
mov    %rcx,(%rax)
movq   $0x0,-0x20(%rbp)
cmpq   $0x10,-0x20(%rbp)
jge    11ac <install_irq+0xac>
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
movabs $0xfffff100,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x2,%rax
movabs $0xfffff200,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1196 <install_irq+0x96>
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
or     $0x20,%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
jmp    11ac <install_irq+0xac>
jmp    119b <install_irq+0x9b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    112c <install_irq+0x2c>
cmpq   $0x10,-0x20(%rbp)
jne    11c4 <install_irq+0xc4>
movq   $0x0,-0x8(%rbp)
jmp    11e4 <install_irq+0xe4>
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%eax
movslq %eax,%rcx
mov    $0xfffff010,%eax
mov    %rcx,(%rax)
movq   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<install_irq>:
mov    %rdi,%rcx
mov    $0xfffff100,%eax
mov    $0x1,%edx
shl    %cl,%edx
movslq %edx,%r8
mov    %r8,-0xec(%rax)
cmpq   $0x0,(%rax)
je     11cb <install_irq+0xcb>
cmpq   $0x0,0x4(%rax)
je     11dc <install_irq+0xdc>
cmpq   $0x0,0x8(%rax)
je     11f1 <install_irq+0xf1>
cmpq   $0x0,0xc(%rax)
je     1206 <install_irq+0x106>
cmpq   $0x0,0x10(%rax)
je     121b <install_irq+0x11b>
cmpq   $0x0,0x14(%rax)
je     1230 <install_irq+0x130>
cmpq   $0x0,0x18(%rax)
je     1245 <install_irq+0x145>
cmpq   $0x0,0x1c(%rax)
je     125a <install_irq+0x15a>
cmpq   $0x0,0x20(%rax)
je     126f <install_irq+0x16f>
cmpq   $0x0,0x24(%rax)
je     1281 <install_irq+0x181>
cmpq   $0x0,0x28(%rax)
je     1293 <install_irq+0x193>
cmpq   $0x0,0x2c(%rax)
je     12a5 <install_irq+0x1a5>
cmpq   $0x0,0x30(%rax)
je     12b7 <install_irq+0x1b7>
cmpq   $0x0,0x34(%rax)
je     12c9 <install_irq+0x1c9>
cmpq   $0x0,0x38(%rax)
je     12db <install_irq+0x1db>
cmpq   $0x0,0x3c(%rax)
je     12ed <install_irq+0x1ed>
xor    %eax,%eax
ret
lea    0x100(%rax),%rdx
mov    $0xfffff100,%edi
jmp    12fd <install_irq+0x1fd>
lea    0x4(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x104,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x8(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x108,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0xc(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x10c,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x10(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x110,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x14(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x114,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x18(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x118,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x1c(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x11c,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x20(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x120,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x24(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x124,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x28(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x128,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x2c(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x12c,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x30(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x130,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x34(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x134,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x38(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x138,%rdx
jmp    12fd <install_irq+0x1fd>
lea    0x3c(%rax),%rdi
mov    $0xfffff100,%edx
add    $0x13c,%rdx
mov    %rsi,(%rdi)
or     $0x20,%rcx
mov    %rcx,(%rdx)
mov    %r8,-0xf0(%rax)
mov    $0x1,%eax
ret

LLVM IR (-O0):
define i64 @install_irq(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64*
%8 = alloca i64*
store i64 %0, i64* %4
store i8* %1, i8** %5
%9 = load i64, i64* %4
%10 = trunc i64 %9 to i32
%11 = shl i32 1, %10
%12 = sext i32 %11 to i64
store volatile i64 %12, i64* inttoptr (i64 4294963220 to i64*)
store i64 0, i64* %6
br label %13
13: ; preds = %36, %2
%14 = load i64, i64* %6
%15 = icmp slt i64 %14, 16
br i1 %15, label %16, label %39
16: ; preds = %13
%17 = load i64, i64* %6
%18 = mul nsw i64 %17, 4
%19 = add nsw i64 4294963456, %18
%20 = inttoptr i64 %19 to i64*
store i64* %20, i64** %7
%21 = load i64, i64* %6
%22 = mul nsw i64 %21, 4
%23 = add nsw i64 4294963712, %22
%24 = inttoptr i64 %23 to i64*
store i64* %24, i64** %8
%25 = load i64*, i64** %7
%26 = load i64, i64* %25
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %35
28: ; preds = %16
%29 = load i8*, i8** %5
%30 = ptrtoint i8* %29 to i64
%31 = load i64*, i64** %7
store i64 %30, i64* %31
%32 = load i64, i64* %4
%33 = or i64 32, %32
%34 = load i64*, i64** %8
store i64 %33, i64* %34
br label %39
35: ; preds = %16
br label %36
36: ; preds = %35
%37 = load i64, i64* %6
%38 = add nsw i64 %37, 1
store i64 %38, i64* %6
br label %13
39: ; preds = %28, %13
%40 = load i64, i64* %6
%41 = icmp eq i64 %40, 16
br i1 %41, label %42, label %43
42: ; preds = %39
store i64 0, i64* %3
br label %48
43: ; preds = %39
%44 = load i64, i64* %4
%45 = trunc i64 %44 to i32
%46 = shl i32 1, %45
%47 = sext i32 %46 to i64
store volatile i64 %47, i64* inttoptr (i64 4294963216 to i64*)
store i64 1, i64* %3
br label %48
48: ; preds = %43, %42
%49 = load i64, i64* %3
ret i64 %49
}

LLVM IR (-O2):
define i64 @install_irq(i64 %0, i8* %1) {
%3 = trunc i64 %0 to i32
%4 = shl nuw i32 1, %3
%5 = sext i32 %4 to i64
store volatile i64 %5, i64* inttoptr (i64 4294963220 to i64*)
%6 = load i64, i64* inttoptr (i64 4294963456 to i64*)
%7 = icmp eq i64 %6, 0
br i1 %7, label %53, label %8
8: ; preds = %2
%9 = load i64, i64* inttoptr (i64 4294963460 to i64*)
%10 = icmp eq i64 %9, 0
br i1 %10, label %53, label %11
11: ; preds = %8
%12 = load i64, i64* inttoptr (i64 4294963464 to i64*)
%13 = icmp eq i64 %12, 0
br i1 %13, label %53, label %14
14: ; preds = %11
%15 = load i64, i64* inttoptr (i64 4294963468 to i64*)
%16 = icmp eq i64 %15, 0
br i1 %16, label %53, label %17
17: ; preds = %14
%18 = load i64, i64* inttoptr (i64 4294963472 to i64*)
%19 = icmp eq i64 %18, 0
br i1 %19, label %53, label %20
20: ; preds = %17
%21 = load i64, i64* inttoptr (i64 4294963476 to i64*)
%22 = icmp eq i64 %21, 0
br i1 %22, label %53, label %23
23: ; preds = %20
%24 = load i64, i64* inttoptr (i64 4294963480 to i64*)
%25 = icmp eq i64 %24, 0
br i1 %25, label %53, label %26
26: ; preds = %23
%27 = load i64, i64* inttoptr (i64 4294963484 to i64*)
%28 = icmp eq i64 %27, 0
br i1 %28, label %53, label %29
29: ; preds = %26
%30 = load i64, i64* inttoptr (i64 4294963488 to i64*)
%31 = icmp eq i64 %30, 0
br i1 %31, label %53, label %32
32: ; preds = %29
%33 = load i64, i64* inttoptr (i64 4294963492 to i64*)
%34 = icmp eq i64 %33, 0
br i1 %34, label %53, label %35
35: ; preds = %32
%36 = load i64, i64* inttoptr (i64 4294963496 to i64*)
%37 = icmp eq i64 %36, 0
br i1 %37, label %53, label %38
38: ; preds = %35
%39 = load i64, i64* inttoptr (i64 4294963500 to i64*)
%40 = icmp eq i64 %39, 0
br i1 %40, label %53, label %41
41: ; preds = %38
%42 = load i64, i64* inttoptr (i64 4294963504 to i64*)
%43 = icmp eq i64 %42, 0
br i1 %43, label %53, label %44
44: ; preds = %41
%45 = load i64, i64* inttoptr (i64 4294963508 to i64*)
%46 = icmp eq i64 %45, 0
br i1 %46, label %53, label %47
47: ; preds = %44
%48 = load i64, i64* inttoptr (i64 4294963512 to i64*)
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %47
%51 = load i64, i64* inttoptr (i64 4294963516 to i64*)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %2, %8, %11, %14, %17, %20, %23, %26, %29, %32, %35, %38, %41, %44, %47, %50
%54 = phi i64* [ inttoptr (i64 4294963712 to i64*), %2 ], [ inttoptr (i64 4294963716 to i64*), %8 ], [ inttoptr (i64 4294963720 to i64*), %11 ], [ inttoptr (i64 4294963724 to i64*), %14 ], [ inttoptr (i64 4294963728 to i64*), %17 ], [ inttoptr (i64 4294963732 to i64*), %20 ], [ inttoptr (i64 4294963736 to i64*), %23 ], [ inttoptr (i64 4294963740 to i64*), %26 ], [ inttoptr (i64 4294963744 to i64*), %29 ], [ inttoptr (i64 4294963748 to i64*), %32 ], [ inttoptr (i64 4294963752 to i64*), %35 ], [ inttoptr (i64 4294963756 to i64*), %38 ], [ inttoptr (i64 4294963760 to i64*), %41 ], [ inttoptr (i64 4294963764 to i64*), %44 ], [ inttoptr (i64 4294963768 to i64*), %47 ], [ inttoptr (i64 4294963772 to i64*), %50 ]
%55 = phi i64* [ inttoptr (i64 4294963456 to i64*), %2 ], [ inttoptr (i64 4294963460 to i64*), %8 ], [ inttoptr (i64 4294963464 to i64*), %11 ], [ inttoptr (i64 4294963468 to i64*), %14 ], [ inttoptr (i64 4294963472 to i64*), %17 ], [ inttoptr (i64 4294963476 to i64*), %20 ], [ inttoptr (i64 4294963480 to i64*), %23 ], [ inttoptr (i64 4294963484 to i64*), %26 ], [ inttoptr (i64 4294963488 to i64*), %29 ], [ inttoptr (i64 4294963492 to i64*), %32 ], [ inttoptr (i64 4294963496 to i64*), %35 ], [ inttoptr (i64 4294963500 to i64*), %38 ], [ inttoptr (i64 4294963504 to i64*), %41 ], [ inttoptr (i64 4294963508 to i64*), %44 ], [ inttoptr (i64 4294963512 to i64*), %47 ], [ inttoptr (i64 4294963516 to i64*), %50 ]
%56 = ptrtoint i8* %1 to i64
store i64 %56, i64* %55
%57 = or i64 %0, 32
store i64 %57, i64* %54
store volatile i64 %5, i64* inttoptr (i64 4294963216 to i64*)
br label %58
58: ; preds = %50, %53
%59 = phi i64 [ 1, %53 ], [ 0, %50 ]
ret i64 %59
}