#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 in8(int);
int /*<<< orphan*/ out8(int, int);
int /*<<< orphan*/ printf(char *, int);
void pic_mask(int interrupt_id) {
  if (((interrupt_id) >= 0x20 && (interrupt_id) < 0x20 + 8)) {
    interrupt_id -= 0x20;
    out8(0x21, in8(0x21) | (1 << interrupt_id));
  } else if (((interrupt_id) >= 0x28 && (interrupt_id) < 0x28 + 8)) {
    interrupt_id -= 0x28;
    out8(0xA1, in8(0xA1) | (1 << interrupt_id));
  } else {
    printf("Invalid call: pic_mask(%d)", interrupt_id);
  }
}


x86 assembly (clang, -O0):
<pic_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x20,-0x4(%rbp)
jl     117f <pic_mask+0x4f>
cmpl   $0x28,-0x4(%rbp)
jge    117f <pic_mask+0x4f>
mov    -0x4(%rbp),%eax
sub    $0x20,%eax
mov    %eax,-0x4(%rbp)
mov    $0x21,%edi
call   1050 <in8@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     %eax,%esi
mov    $0x21,%edi
call   1040 <out8@plt>
jmp    11d7 <pic_mask+0xa7>
cmpl   $0x28,-0x4(%rbp)
jl     11c3 <pic_mask+0x93>
cmpl   $0x30,-0x4(%rbp)
jge    11c3 <pic_mask+0x93>
mov    -0x4(%rbp),%eax
sub    $0x28,%eax
mov    %eax,-0x4(%rbp)
mov    $0xa1,%edi
call   1050 <in8@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     %eax,%esi
mov    $0xa1,%edi
call   1040 <out8@plt>
jmp    11d2 <pic_mask+0xa2>
mov    -0x4(%rbp),%esi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
jmp    11d7 <pic_mask+0xa7>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pic_mask>:
push   %rbx
mov    %edi,%ebx
mov    %edi,%eax
and    $0xfffffff8,%eax
cmp    $0x28,%eax
je     1159 <pic_mask+0x29>
cmp    $0x20,%eax
jne    1176 <pic_mask+0x46>
mov    $0x21,%edi
call   1050 <in8@plt>
add    $0xe0,%bl
bts    %ebx,%eax
mov    $0x21,%edi
jmp    116e <pic_mask+0x3e>
mov    $0xa1,%edi
call   1050 <in8@plt>
add    $0xd8,%bl
bts    %ebx,%eax
mov    $0xa1,%edi
mov    %eax,%esi
pop    %rbx
jmp    1040 <out8@plt>
lea    0xe83(%rip),%rdi
mov    %ebx,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Invalid call: pic_mask(%d)\00"
define void @pic_mask(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sge i32 %3, 32
br i1 %4, label %5, label %16
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 40
br i1 %7, label %8, label %16
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sub nsw i32 %9, 32
store i32 %10, i32* %2
%11 = call i32 @in8(i32 33)
%12 = load i32, i32* %2
%13 = shl i32 1, %12
%14 = or i32 %11, %13
%15 = call i32 @out8(i32 33, i32 %14)
br label %34
16: ; preds = %5, %1
%17 = load i32, i32* %2
%18 = icmp sge i32 %17, 40
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i32, i32* %2
%21 = icmp slt i32 %20, 48
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = load i32, i32* %2
%24 = sub nsw i32 %23, 40
store i32 %24, i32* %2
%25 = call i32 @in8(i32 161)
%26 = load i32, i32* %2
%27 = shl i32 1, %26
%28 = or i32 %25, %27
%29 = call i32 @out8(i32 161, i32 %28)
br label %33
30: ; preds = %19, %16
%31 = load i32, i32* %2
%32 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %22
br label %34
34: ; preds = %33, %8
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"Invalid call: pic_mask(%d)\00"
define void @pic_mask(i32 %0) {
%2 = and i32 %0, -8
switch i32 %2, label %15 [
i32 32, label %3
i32 40, label %9
]
3: ; preds = %1
%4 = add nsw i32 %0, -32
%5 = tail call i32 @in8(i32 33)
%6 = shl nuw nsw i32 1, %4
%7 = or i32 %5, %6
%8 = tail call i32 @out8(i32 33, i32 %7)
br label %17
9: ; preds = %1
%10 = add nsw i32 %0, -40
%11 = tail call i32 @in8(i32 161)
%12 = shl nuw nsw i32 1, %10
%13 = or i32 %11, %12
%14 = tail call i32 @out8(i32 161, i32 %13)
br label %17
15: ; preds = %1
%16 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %17
17: ; preds = %9, %15, %3
ret void
}