#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 */
struct pt_regs {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ do_profile(int /*<<< orphan*/);
int /*<<< orphan*/ do_timer(struct pt_regs *);
int /*<<< orphan*/ instruction_pointer(struct pt_regs *);
int /*<<< orphan*/ readb(int);
int /*<<< orphan*/ user_mode(struct pt_regs *);
int /*<<< orphan*/ writeb(int, int);
void timer_interrupt(int irq, void *dev_id, struct pt_regs *regs) {
  static int count = 50;
  writeb(0x90, 0xfff00000 + 8);
  if (--count == 0) {
    static int state = 1;
    state ^= 1;
    writeb(0x1a + state, 0xffe00000);
    count = 50;
  }
  readb(0xfff00000 + 0x14);
  readb(0xfff00000 + 0x14);
  readb(0xfff00000 + 0x14);
  readb(0xfff00000 + 0x14);
  readb(0xfff00000 + 0x14);
  readb(0xfff00000 + 0x14);
  do_timer(regs);
  if (!user_mode(regs))
    do_profile(instruction_pointer(regs));
}


x86 assembly (clang, -O0):
<timer_interrupt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x90,%edi
mov    $0xfff00008,%esi
call   1080 <writeb@plt>
mov    0x2ec8(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2ebf(%rip)
cmp    $0x0,%eax
jne    11c6 <timer_interrupt+0x66>
mov    0x2eb4(%rip),%eax
xor    $0x1,%eax
mov    %eax,0x2eab(%rip)
mov    0x2ea5(%rip),%edi
add    $0x1a,%edi
mov    $0xffe00000,%esi
call   1080 <writeb@plt>
movl   $0x32,0x2e8a(%rip)
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    -0x18(%rbp),%rdi
call   1040 <do_timer@plt>
mov    -0x18(%rbp),%rdi
call   1030 <user_mode@plt>
cmp    $0x0,%eax
jne    122d <timer_interrupt+0xcd>
mov    -0x18(%rbp),%rdi
call   1070 <instruction_pointer@plt>
mov    %eax,%edi
call   1060 <do_profile@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_interrupt>:
push   %rbx
mov    %rdx,%rbx
mov    $0x90,%edi
mov    $0xfff00008,%esi
call   1080 <writeb@plt>
addl   $0xffffffff,0x2ed6(%rip)
jne    11a2 <timer_interrupt+0x42>
mov    0x2ed2(%rip),%edi
xor    $0x1,%edi
mov    %edi,0x2ec9(%rip)
add    $0x1a,%edi
mov    $0xffe00000,%esi
call   1080 <writeb@plt>
movl   $0x32,0x2eae(%rip)
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    $0xfff00014,%edi
call   1050 <readb@plt>
mov    %rbx,%rdi
call   1040 <do_timer@plt>
mov    %rbx,%rdi
call   1030 <user_mode@plt>
test   %eax,%eax
je     11f4 <timer_interrupt+0x94>
pop    %rbx
ret
mov    %rbx,%rdi
call   1070 <instruction_pointer@plt>
mov    %eax,%edi
pop    %rbx
jmp    1060 <do_profile@plt>

LLVM IR (-O0):
%struct.pt_regs = type { i32 }
@timer_interrupt.count = internal global i32 50
@timer_interrupt.state = internal global i32 1
define void @timer_interrupt(i32 %0, i8* %1, %struct.pt_regs* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca %struct.pt_regs*
store i32 %0, i32* %4
store i8* %1, i8** %5
store %struct.pt_regs* %2, %struct.pt_regs** %6
%7 = call i32 @writeb(i32 144, i32 -1048568)
%8 = load i32, i32* @timer_interrupt.count
%9 = add nsw i32 %8, -1
store i32 %9, i32* @timer_interrupt.count
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32, i32* @timer_interrupt.state
%13 = xor i32 %12, 1
store i32 %13, i32* @timer_interrupt.state
%14 = load i32, i32* @timer_interrupt.state
%15 = add nsw i32 26, %14
%16 = call i32 @writeb(i32 %15, i32 -2097152)
store i32 50, i32* @timer_interrupt.count
br label %17
17: ; preds = %11, %3
%18 = call i32 @readb(i32 -1048556)
%19 = call i32 @readb(i32 -1048556)
%20 = call i32 @readb(i32 -1048556)
%21 = call i32 @readb(i32 -1048556)
%22 = call i32 @readb(i32 -1048556)
%23 = call i32 @readb(i32 -1048556)
%24 = load %struct.pt_regs*, %struct.pt_regs** %6
%25 = call i32 @do_timer(%struct.pt_regs* %24)
%26 = load %struct.pt_regs*, %struct.pt_regs** %6
%27 = call i32 @user_mode(%struct.pt_regs* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %17
%30 = load %struct.pt_regs*, %struct.pt_regs** %6
%31 = call i32 @instruction_pointer(%struct.pt_regs* %30)
%32 = call i32 @do_profile(i32 %31)
br label %33
33: ; preds = %29, %17
ret void
}

LLVM IR (-O2):
%struct.pt_regs = type { i32 }
@timer_interrupt.count = internal unnamed_addr global i32 50
@timer_interrupt.state = internal unnamed_addr global i32 1
define void @timer_interrupt(i32 %0, i8* nocapture readnone %1, %struct.pt_regs* %2) {
%4 = tail call i32 @writeb(i32 144, i32 -1048568)
%5 = load i32, i32* @timer_interrupt.count
%6 = add nsw i32 %5, -1
store i32 %6, i32* @timer_interrupt.count
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = load i32, i32* @timer_interrupt.state
%10 = xor i32 %9, 1
store i32 %10, i32* @timer_interrupt.state
%11 = add nsw i32 %10, 26
%12 = tail call i32 @writeb(i32 %11, i32 -2097152)
store i32 50, i32* @timer_interrupt.count
br label %13
13: ; preds = %8, %3
%14 = tail call i32 @readb(i32 -1048556)
%15 = tail call i32 @readb(i32 -1048556)
%16 = tail call i32 @readb(i32 -1048556)
%17 = tail call i32 @readb(i32 -1048556)
%18 = tail call i32 @readb(i32 -1048556)
%19 = tail call i32 @readb(i32 -1048556)
%20 = tail call i32 @do_timer(%struct.pt_regs* %2)
%21 = tail call i32 @user_mode(%struct.pt_regs* %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %13
%24 = tail call i32 @instruction_pointer(%struct.pt_regs* %2)
%25 = tail call i32 @do_profile(i32 %24)
br label %26
26: ; preds = %23, %13
ret void
}