#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*/ machine_execute_call_do(int);
int /*<<< orphan*/ machine_get_ipreg();
int machine_get_mode();
int machine_interrupt_address(int);
int /*<<< orphan*/ machine_register_exception(char *, int);
int /*<<< orphan*/ machine_set_mode(int);
int /*<<< orphan*/ word_store_integer(int /*<<< orphan*/, int);
int machine_execute_interrupt_do(int interrupt) {
  int target;
  if (machine_get_mode() == 1)
    machine_register_exception("Invoking interrupts in kernel mode not allowed",
                               1);
  target = machine_interrupt_address(interrupt);
  if (interrupt != 0)
    machine_execute_call_do(target);
  else
    word_store_integer(machine_get_ipreg(), target);
  machine_set_mode(1);
  return 1;
}


x86 assembly (clang, -O0):
<machine_execute_interrupt_do>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <machine_get_mode@plt>
cmp    $0x1,%eax
jne    119c <machine_execute_interrupt_do+0x2c>
lea    0xe6e(%rip),%rdi
mov    $0x1,%esi
call   1080 <machine_register_exception@plt>
mov    -0x4(%rbp),%edi
call   1050 <machine_interrupt_address@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11be <machine_execute_interrupt_do+0x4e>
mov    -0x8(%rbp),%edi
call   1070 <machine_execute_call_do@plt>
jmp    11cf <machine_execute_interrupt_do+0x5f>
mov    $0x0,%al
call   1060 <machine_get_ipreg@plt>
mov    %eax,%edi
mov    -0x8(%rbp),%esi
call   1040 <word_store_integer@plt>
mov    $0x1,%edi
call   1090 <machine_set_mode@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<machine_execute_interrupt_do>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <machine_get_mode@plt>
cmp    $0x1,%eax
jne    1192 <machine_execute_interrupt_do+0x22>
lea    0xe78(%rip),%rdi
mov    $0x1,%esi
call   1080 <machine_register_exception@plt>
mov    %ebx,%edi
call   1050 <machine_interrupt_address@plt>
mov    %eax,%ebp
test   %ebx,%ebx
je     11a8 <machine_execute_interrupt_do+0x38>
mov    %ebp,%edi
call   1070 <machine_execute_call_do@plt>
jmp    11b8 <machine_execute_interrupt_do+0x48>
xor    %eax,%eax
call   1060 <machine_get_ipreg@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1040 <word_store_integer@plt>
mov    $0x1,%edi
call   1090 <machine_set_mode@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"Invoking interrupts in kernel mode not allowed\00"
define i32 @machine_execute_interrupt_do(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = call i32 (...) @machine_get_mode()
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @machine_register_exception(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 1)
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* %2
%10 = call i32 @machine_interrupt_address(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %3
%15 = call i32 @machine_execute_call_do(i32 %14)
br label %20
16: ; preds = %8
%17 = call i32 (...) @machine_get_ipreg()
%18 = load i32, i32* %3
%19 = call i32 @word_store_integer(i32 %17, i32 %18)
br label %20
20: ; preds = %16, %13
%21 = call i32 @machine_set_mode(i32 1)
ret i32 1
}

LLVM IR (-O2):
@.str = [47 x i8] c"Invoking interrupts in kernel mode not allowed\00"
define i32 @machine_execute_interrupt_do(i32 %0) {
%2 = tail call i32 (...) @machine_get_mode()
%3 = icmp eq i32 %2, 1
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @machine_register_exception(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 1)
br label %6
6: ; preds = %4, %1
%7 = tail call i32 @machine_interrupt_address(i32 %0)
%8 = icmp eq i32 %0, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @machine_execute_call_do(i32 %7)
br label %14
11: ; preds = %6
%12 = tail call i32 (...) @machine_get_ipreg()
%13 = tail call i32 @word_store_integer(i32 %12, i32 %7)
br label %14
14: ; preds = %11, %9
%15 = tail call i32 @machine_set_mode(i32 1)
ret i32 1
}