#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 */
unsigned char inb(int);
int /*<<< orphan*/ outb(int, unsigned char);
void enable_irq(unsigned char irq) {
  unsigned char mask_master, mask_slave;
  mask_master = inb(0x21);
  mask_slave = inb(0xa1);
  if (irq > 7) {
    outb(0xa1, mask_slave & ~(1 << (irq - 8)));
  } else {
    outb(0x21, mask_master & ~(1 << irq));
  }
}


x86 assembly (clang, -O0):
<enable_irq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
mov    $0x21,%edi
call   1040 <inb@plt>
mov    %al,-0x2(%rbp)
mov    $0xa1,%edi
call   1040 <inb@plt>
mov    %al,-0x3(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x7,%eax
jle    1180 <enable_irq+0x60>
movzbl -0x3(%rbp),%eax
movzbl -0x1(%rbp),%ecx
sub    $0x8,%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    $0xa1,%edi
movzbl %al,%esi
call   1030 <outb@plt>
jmp    11a3 <enable_irq+0x83>
movzbl -0x2(%rbp),%eax
movzbl -0x1(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    $0x21,%edi
movzbl %al,%esi
call   1030 <outb@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enable_irq>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0x21,%edi
call   1040 <inb@plt>
mov    %eax,%ebp
mov    $0xa1,%edi
call   1040 <inb@plt>
lea    -0x8(%rbx),%ecx
xor    %edi,%edi
cmp    $0x8,%bl
setae  %dil
movzbl %bpl,%edx
movzbl %al,%eax
cmovb  %edx,%eax
movzbl %cl,%ecx
cmovb  %ebx,%ecx
shl    $0x7,%edi
mov    $0x1,%edx
shl    %cl,%edx
or     $0x21,%edi
not    %dl
and    %al,%dl
movzbl %dl,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <outb@plt>

LLVM IR (-O0):
define void @enable_irq(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 %0, i8* %2
%5 = call zeroext i8 @inb(i32 33)
store i8 %5, i8* %3
%6 = call zeroext i8 @inb(i32 161)
store i8 %6, i8* %4
%7 = load i8, i8* %2
%8 = zext i8 %7 to i32
%9 = icmp sgt i32 %8, 7
br i1 %9, label %10, label %21
10: ; preds = %1
%11 = load i8, i8* %4
%12 = zext i8 %11 to i32
%13 = load i8, i8* %2
%14 = zext i8 %13 to i32
%15 = sub nsw i32 %14, 8
%16 = shl i32 1, %15
%17 = xor i32 %16, -1
%18 = and i32 %12, %17
%19 = trunc i32 %18 to i8
%20 = call i32 @outb(i32 161, i8 zeroext %19)
br label %31
21: ; preds = %1
%22 = load i8, i8* %3
%23 = zext i8 %22 to i32
%24 = load i8, i8* %2
%25 = zext i8 %24 to i32
%26 = shl i32 1, %25
%27 = xor i32 %26, -1
%28 = and i32 %23, %27
%29 = trunc i32 %28 to i8
%30 = call i32 @outb(i32 33, i8 zeroext %29)
br label %31
31: ; preds = %21, %10
ret void
}

LLVM IR (-O2):
define void @enable_irq(i8 zeroext %0) {
%2 = tail call zeroext i8 @inb(i32 33)
%3 = tail call zeroext i8 @inb(i32 161)
%4 = zext i8 %0 to i32
%5 = icmp ugt i8 %0, 7
%6 = add nsw i32 %4, -8
%7 = select i1 %5, i32 %6, i32 %4
%8 = select i1 %5, i8 %3, i8 %2
%9 = select i1 %5, i32 161, i32 33
%10 = shl nuw i32 1, %7
%11 = trunc i32 %10 to i8
%12 = xor i8 %11, -1
%13 = and i8 %8, %12
%14 = tail call i32 @outb(i32 %9, i8 zeroext %13)
ret void
}