#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 io_in8(int);
int /*<<< orphan*/ io_out8(int, int);
int open_PIC(unsigned char IRQ) {
  if (IRQ > 15) {
    return (-1);
  } else if (IRQ <= 7) {
    io_out8(0x0021, (io_in8(0x0021) & (~(1 << IRQ))));
  } else {
    io_out8(0x00a1, (io_in8(0x00a1) & (~(1 << IRQ - 8))));
  }
  return 0;
}


x86 assembly (clang, -O0):
<open_PIC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0xf,%eax
jle    1147 <open_PIC+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <open_PIC+0x94>
movzbl -0x5(%rbp),%eax
cmp    $0x7,%eax
jg     117f <open_PIC+0x5f>
mov    $0x21,%edi
call   1040 <io_in8@plt>
mov    %eax,%esi
movzbl -0x5(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    %eax,%esi
mov    $0x21,%edi
call   1030 <io_out8@plt>
jmp    11a8 <open_PIC+0x88>
mov    $0xa1,%edi
call   1040 <io_in8@plt>
mov    %eax,%esi
movzbl -0x5(%rbp),%ecx
sub    $0x8,%ecx
mov    $0x1,%eax
shl    %cl,%eax
xor    $0xffffffff,%eax
and    %eax,%esi
mov    $0xa1,%edi
call   1030 <io_out8@plt>
jmp    11ad <open_PIC+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_PIC>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
mov    $0xffffffff,%eax
cmp    $0xf,%bl
ja     1165 <open_PIC+0x45>
cmp    $0x7,%bl
ja     1145 <open_PIC+0x25>
mov    $0x21,%ebp
mov    $0x21,%edi
call   1040 <io_in8@plt>
jmp    1157 <open_PIC+0x37>
mov    $0xa1,%ebp
mov    $0xa1,%edi
call   1040 <io_in8@plt>
add    $0xfffffff8,%ebx
btr    %ebx,%eax
mov    %ebp,%edi
mov    %eax,%esi
call   1030 <io_out8@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @open_PIC(i8 zeroext %0) {
%2 = zext i8 %0 to i32
%3 = icmp ugt i8 %0, 15
br i1 %3, label %19, label %4
4: ; preds = %1
%5 = icmp ult i8 %0, 8
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @io_in8(i32 33)
br label %11
8: ; preds = %4
%9 = tail call i32 @io_in8(i32 161)
%10 = add nsw i32 %2, -8
br label %11
11: ; preds = %6, %8
%12 = phi i32 [ %10, %8 ], [ %2, %6 ]
%13 = phi i32 [ %9, %8 ], [ %7, %6 ]
%14 = phi i32 [ 161, %8 ], [ 33, %6 ]
%15 = shl nuw i32 1, %12
%16 = xor i32 %15, -1
%17 = and i32 %13, %16
%18 = tail call i32 @io_out8(i32 %14, i32 %17)
br label %19
19: ; preds = %11, %1
%20 = phi i32 [ -1, %1 ], [ 0, %11 ]
ret i32 %20
}