#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 linux_inb(int);
int /*<<< orphan*/ linux_outb(int, int);
int i8259A_irq_real(unsigned int irq) {
  int value;
  int irqmask = 1 << irq;
  if (irq < 8) {
    linux_outb(0x0B, 0x20);
    value = linux_inb(0x20) & irqmask;
    linux_outb(0x0A, 0x20);
    return value;
  }
  linux_outb(0x0B, 0xA0);
  value = linux_inb(0xA0) & (irqmask >> 8);
  linux_outb(0x0A, 0xA0);
  return value;
}


x86 assembly (clang, -O0):
<i8259A_irq_real>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x8,-0x8(%rbp)
jae    117b <i8259A_irq_real+0x5b>
mov    $0xb,%edi
mov    $0x20,%esi
call   1030 <linux_outb@plt>
mov    $0x20,%edi
call   1040 <linux_inb@plt>
and    -0x10(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
mov    $0x20,%esi
call   1030 <linux_outb@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11b4 <i8259A_irq_real+0x94>
mov    $0xb,%edi
mov    $0xa0,%esi
call   1030 <linux_outb@plt>
mov    $0xa0,%edi
call   1040 <linux_inb@plt>
mov    -0x10(%rbp),%ecx
sar    $0x8,%ecx
and    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    $0xa,%edi
mov    $0xa0,%esi
call   1030 <linux_outb@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i8259A_irq_real>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ecx
mov    $0x1,%ebp
shl    %cl,%ebp
cmp    $0x7,%edi
ja     1157 <i8259A_irq_real+0x37>
mov    $0x20,%r14d
mov    $0xb,%edi
mov    $0x20,%esi
call   1030 <linux_outb@plt>
mov    $0x20,%edi
call   1040 <linux_inb@plt>
mov    %eax,%ebx
and    %ebp,%ebx
jmp    117d <i8259A_irq_real+0x5d>
mov    $0xa0,%r14d
mov    $0xb,%edi
mov    $0xa0,%esi
call   1030 <linux_outb@plt>
mov    $0xa0,%edi
call   1040 <linux_inb@plt>
sar    $0x8,%ebp
and    %eax,%ebp
mov    %ebp,%ebx
mov    $0xa,%edi
mov    %r14d,%esi
call   1030 <linux_outb@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @i8259A_irq_real(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = shl i32 1, %6
store i32 %7, i32* %5
%8 = load i32, i32* %3
%9 = icmp ult i32 %8, 8
br i1 %9, label %10, label %17
10: ; preds = %1
%11 = call i32 @linux_outb(i32 11, i32 32)
%12 = call i32 @linux_inb(i32 32)
%13 = load i32, i32* %5
%14 = and i32 %12, %13
store i32 %14, i32* %4
%15 = call i32 @linux_outb(i32 10, i32 32)
%16 = load i32, i32* %4
store i32 %16, i32* %2
br label %25
17: ; preds = %1
%18 = call i32 @linux_outb(i32 11, i32 160)
%19 = call i32 @linux_inb(i32 160)
%20 = load i32, i32* %5
%21 = ashr i32 %20, 8
%22 = and i32 %19, %21
store i32 %22, i32* %4
%23 = call i32 @linux_outb(i32 10, i32 160)
%24 = load i32, i32* %4
store i32 %24, i32* %2
br label %25
25: ; preds = %17, %10
%26 = load i32, i32* %2
ret i32 %26
}

LLVM IR (-O2):
define i32 @i8259A_irq_real(i32 %0) {
%2 = shl nuw i32 1, %0
%3 = icmp ult i32 %0, 8
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = tail call i32 @linux_outb(i32 11, i32 32)
%6 = tail call i32 @linux_inb(i32 32)
%7 = and i32 %6, %2
br label %13
8: ; preds = %1
%9 = tail call i32 @linux_outb(i32 11, i32 160)
%10 = tail call i32 @linux_inb(i32 160)
%11 = ashr i32 %2, 8
%12 = and i32 %10, %11
br label %13
13: ; preds = %8, %4
%14 = phi i32 [ 160, %8 ], [ 32, %4 ]
%15 = phi i32 [ %12, %8 ], [ %7, %4 ]
%16 = tail call i32 @linux_outb(i32 10, i32 %14)
ret i32 %15
}