#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 do_irq(void) {
  int i = 0;
  printf("do_irq\n\r");
  printf("SERVICE     = 0x%x\n\r", (*((volatile unsigned long *)0x7F008284)));
  printf("SERVICEPEND = 0x%x\n\r", (*((volatile unsigned long *)0x7F008288)));
  printf("EINT0PEND   = 0x%x\n\r", (*((volatile unsigned long *)0x7F008924)));
  for (i = 0; i < 6; i++) {
    if ((*((volatile unsigned long *)0x7F008924)) & (1 << i)) {
      if ((*((volatile unsigned long *)0x7F008834)) & (1 << i)) {
        printf("K%d released\n\r", i + 1);
      } else {
        printf("K%d pressed\n\r", i + 1);
      }
    }
  }
  (*((volatile unsigned long *)0x7F008924)) = 0x3f;
  (*((volatile unsigned long *)0x71200f00)) = 0;
}


x86 assembly (clang, -O0):
<do_irq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7f008284,%eax
mov    (%rax),%rsi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7f008288,%eax
mov    (%rax),%rsi
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x7f008924,%eax
mov    (%rax),%rsi
lea    0xecb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x6,-0x4(%rbp)
jge    120d <do_irq+0xfd>
mov    $0x7f008924,%eax
mov    (%rax),%rax
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     11fa <do_irq+0xea>
mov    $0x7f008834,%eax
mov    (%rax),%rax
mov    -0x4(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
movslq %ecx,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     11e1 <do_irq+0xd1>
mov    -0x4(%rbp),%esi
add    $0x1,%esi
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f5 <do_irq+0xe5>
mov    -0x4(%rbp),%esi
add    $0x1,%esi
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11fa <do_irq+0xea>
jmp    11ff <do_irq+0xef>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1176 <do_irq+0x66>
mov    $0x7f008924,%eax
movq   $0x3f,(%rax)
mov    $0x71200f00,%eax
movq   $0x0,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_irq>:
push   %rax
lea    0xee8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x7f008284,%rsi
7f
lea    0xedb(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x7f008288,%rsi
7f
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x7f008924,%rsi
7f
lea    0xed9(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
testq  $0x1,0x7f008924
jne    120d <do_irq+0xfd>
testq  $0x2,0x7f008924
jne    1249 <do_irq+0x139>
testq  $0x4,0x7f008924
jne    1285 <do_irq+0x175>
testq  $0x8,0x7f008924
jne    12c1 <do_irq+0x1b1>
testq  $0x10,0x7f008924
jne    12fd <do_irq+0x1ed>
testq  $0x20,0x7f008924
je     11f3 <do_irq+0xe3>
testq  $0x20,0x7f008834
lea    0xe7b(%rip),%rax
lea    0xe65(%rip),%rdi
cmove  %rax,%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1030 <printf@plt>
movq   $0x3f,0x7f008924
movq   $0x0,0x71200f00
pop    %rax
ret
testq  $0x1,0x7f008834
lea    0xe37(%rip),%rax
lea    0xe21(%rip),%rdi
cmove  %rax,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1030 <printf@plt>
testq  $0x2,0x7f008924
je     1185 <do_irq+0x75>
testq  $0x2,0x7f008834
lea    0xdfb(%rip),%rax
lea    0xde5(%rip),%rdi
cmove  %rax,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1030 <printf@plt>
testq  $0x4,0x7f008924
je     1197 <do_irq+0x87>
testq  $0x4,0x7f008834
lea    0xdbf(%rip),%rax
lea    0xda9(%rip),%rdi
cmove  %rax,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1030 <printf@plt>
testq  $0x8,0x7f008924
je     11a9 <do_irq+0x99>
testq  $0x8,0x7f008834
lea    0xd83(%rip),%rax
lea    0xd6d(%rip),%rdi
cmove  %rax,%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1030 <printf@plt>
testq  $0x10,0x7f008924
je     11bb <do_irq+0xab>
testq  $0x10,0x7f008834
lea    0xd47(%rip),%rax
lea    0xd31(%rip),%rdi
cmove  %rax,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1030 <printf@plt>
testq  $0x20,0x7f008924
jne    11c9 <do_irq+0xb9>
jmp    11f3 <do_irq+0xe3>

LLVM IR (-O0):
@.str = [9 x i8] c"do_irq\0A\0D\00"
@.str.1 = [21 x i8] c"SERVICE = 0x%x\0A\0D\00"
@.str.2 = [21 x i8] c"SERVICEPEND = 0x%x\0A\0D\00"
@.str.3 = [21 x i8] c"EINT0PEND = 0x%x\0A\0D\00"
@.str.4 = [15 x i8] c"K%d released\0A\0D\00"
@.str.5 = [14 x i8] c"K%d pressed\0A\0D\00"
define void @do_irq() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%3 = load volatile i64, i64* inttoptr (i64 2130739844 to i64*)
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %3)
%5 = load volatile i64, i64* inttoptr (i64 2130739848 to i64*)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %5)
%7 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %7)
store i32 0, i32* %1
br label %9
9: ; preds = %36, %0
%10 = load i32, i32* %1
%11 = icmp slt i32 %10, 6
br i1 %11, label %12, label %39
12: ; preds = %9
%13 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%14 = load i32, i32* %1
%15 = shl i32 1, %14
%16 = sext i32 %15 to i64
%17 = and i64 %13, %16
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %35
19: ; preds = %12
%20 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%21 = load i32, i32* %1
%22 = shl i32 1, %21
%23 = sext i32 %22 to i64
%24 = and i64 %20, %23
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %19
%27 = load i32, i32* %1
%28 = add nsw i32 %27, 1
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %28)
br label %34
30: ; preds = %19
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %30, %26
br label %35
35: ; preds = %34, %12
br label %36
36: ; preds = %35
%37 = load i32, i32* %1
%38 = add nsw i32 %37, 1
store i32 %38, i32* %1
br label %9
39: ; preds = %9
store volatile i64 63, i64* inttoptr (i64 2130741540 to i64*)
store volatile i64 0, i64* inttoptr (i64 1897926400 to i64*)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"do_irq\0A\0D\00"
@.str.1 = [21 x i8] c"SERVICE = 0x%x\0A\0D\00"
@.str.2 = [21 x i8] c"SERVICEPEND = 0x%x\0A\0D\00"
@.str.3 = [21 x i8] c"EINT0PEND = 0x%x\0A\0D\00"
@.str.4 = [15 x i8] c"K%d released\0A\0D\00"
@.str.5 = [14 x i8] c"K%d pressed\0A\0D\00"
define void @do_irq() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = load volatile i64, i64* inttoptr (i64 2130739844 to i64*)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %2)
%4 = load volatile i64, i64* inttoptr (i64 2130739848 to i64*)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i64 %4)
%6 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %6)
%8 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%9 = and i64 %8, 1
%10 = icmp eq i64 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %0
%12 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%13 = and i64 %12, 1
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %15, i32 1)
br label %17
17: ; preds = %11, %0
%18 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%19 = and i64 %18, 2
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%23 = and i64 %22, 2
%24 = icmp eq i64 %23, 0
%25 = select i1 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %25, i32 2)
br label %27
27: ; preds = %21, %17
%28 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%29 = and i64 %28, 4
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %27
%32 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%33 = and i64 %32, 4
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %35, i32 3)
br label %37
37: ; preds = %31, %27
%38 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%39 = and i64 %38, 8
%40 = icmp eq i64 %39, 0
br i1 %40, label %47, label %41
41: ; preds = %37
%42 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%43 = and i64 %42, 8
%44 = icmp eq i64 %43, 0
%45 = select i1 %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %45, i32 4)
br label %47
47: ; preds = %41, %37
%48 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%49 = and i64 %48, 16
%50 = icmp eq i64 %49, 0
br i1 %50, label %57, label %51
51: ; preds = %47
%52 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%53 = and i64 %52, 16
%54 = icmp eq i64 %53, 0
%55 = select i1 %54, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %55, i32 5)
br label %57
57: ; preds = %51, %47
%58 = load volatile i64, i64* inttoptr (i64 2130741540 to i64*)
%59 = and i64 %58, 32
%60 = icmp eq i64 %59, 0
br i1 %60, label %67, label %61
61: ; preds = %57
%62 = load volatile i64, i64* inttoptr (i64 2130741300 to i64*)
%63 = and i64 %62, 32
%64 = icmp eq i64 %63, 0
%65 = select i1 %64, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0)
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %65, i32 6)
br label %67
67: ; preds = %61, %57
store volatile i64 63, i64* inttoptr (i64 2130741540 to i64*)
store volatile i64 0, i64* inttoptr (i64 1897926400 to i64*)
ret void
}