#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*/ printf(char *);
void interrupt_handler() {
  static int i = 0;
  switch (i) {
  case 0:
    printf("User interrupt 1.\n");
    break;
  case 1:
    printf("User interrupt 2.\n");
    break;
  case 2:
    printf("User interrupt 3.\n");
    break;
  case 3:
    printf("User interrupt 4.\n");
    break;
  default:
    printf("Another user interrupt.\n");
    break;
  }
  i++;
}


x86 assembly (clang, -O0):
<interrupt_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2f0e(%rip),%eax
mov    %rax,-0x8(%rbp)
sub    $0x3,%rax
ja     1184 <interrupt_handler+0x74>
mov    -0x8(%rbp),%rax
lea    0xec9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec9(%rip),%rdi
call   1030 <printf@plt>
jmp    1190 <interrupt_handler+0x80>
lea    0xecb(%rip),%rdi
call   1030 <printf@plt>
jmp    1190 <interrupt_handler+0x80>
lea    0xecd(%rip),%rdi
call   1030 <printf@plt>
jmp    1190 <interrupt_handler+0x80>
lea    0xecf(%rip),%rdi
call   1030 <printf@plt>
jmp    1190 <interrupt_handler+0x80>
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e96(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e8d(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<interrupt_handler>:
push   %rax
movslq 0x2f14(%rip),%rax
cmp    $0x3,%rax
ja     112e <interrupt_handler+0x1e>
lea    0xf3b(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1135 <interrupt_handler+0x25>
lea    0xf13(%rip),%rdi
call   1030 <puts@plt>
addl   $0x1,0x2eeb(%rip)
pop    %rax
ret

LLVM IR (-O0):
@interrupt_handler.i = internal global i32 0
@.str = [19 x i8] c"User interrupt 1.\0A\00"
@.str.1 = [19 x i8] c"User interrupt 2.\0A\00"
@.str.2 = [19 x i8] c"User interrupt 3.\0A\00"
@.str.3 = [19 x i8] c"User interrupt 4.\0A\00"
@.str.4 = [25 x i8] c"Another user interrupt.\0A\00"
define void @interrupt_handler() {
%1 = load i32, i32* @interrupt_handler.i
switch i32 %1, label %10 [
i32 0, label %2
i32 1, label %4
i32 2, label %6
i32 3, label %8
]
2: ; preds = %0
%3 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %12
4: ; preds = %0
%5 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %12
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %12
8: ; preds = %0
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %12
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
br label %12
12: ; preds = %10, %8, %6, %4, %2
%13 = load i32, i32* @interrupt_handler.i
%14 = add nsw i32 %13, 1
store i32 %14, i32* @interrupt_handler.i
ret void
}

LLVM IR (-O2):
@interrupt_handler.i = internal unnamed_addr global i32 0
@str = [18 x i8] c"User interrupt 4.\00"
@str.5 = [18 x i8] c"User interrupt 3.\00"
@str.6 = [18 x i8] c"User interrupt 2.\00"
@str.7 = [18 x i8] c"User interrupt 1.\00"
@str.8 = [24 x i8] c"Another user interrupt.\00"
@reltable.interrupt_handler = [4 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.7 to i64), i64 ptrtoint ([4 x i32]* @reltable.interrupt_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.6 to i64), i64 ptrtoint ([4 x i32]* @reltable.interrupt_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.5 to i64), i64 ptrtoint ([4 x i32]* @reltable.interrupt_handler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str to i64), i64 ptrtoint ([4 x i32]* @reltable.interrupt_handler to i64)) to i32)]
define void @interrupt_handler() {
%1 = load i32, i32* @interrupt_handler.i
%2 = icmp ult i32 %1, 4
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = sext i32 %1 to i64
%5 = shl i64 %4, 2
%6 = call i8* @llvm.load.relative.i64(i8* bitcast ([4 x i32]* @reltable.interrupt_handler to i8*), i64 %5)
br label %7
7: ; preds = %0, %3
%8 = phi i8* [ %6, %3 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @str.8, i64 0, i64 0), %0 ]
%9 = tail call i32 @puts(i8* dereferenceable(1) %8)
%10 = load i32, i32* @interrupt_handler.i
%11 = add nsw i32 %10, 1
store i32 %11, i32* @interrupt_handler.i
ret void
}