#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 inb(int);
int ioperm(int, int, int);
int /*<<< orphan*/ long_pause();
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ printf(char *, int);
main() {
  int res, cons, i;
  res = ioperm(0x40, 0x40, 1);
  printf(" res of ioperm = %d\n", res);
  for (i = 1; i < 10; i++) {
    cons = (1193180) / (i * 22);
    outb(inb(0x61) | 3, 0x61);
    outb(0xb6, 0x43);
    outb(cons & 0xff, 0x42);
    outb((cons >> 8) & 0xff, 0x42);
    long_pause();
    outb(inb(0x63) & 0xfc, 0x61);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x40,%esi
mov    $0x1,%edx
mov    %esi,%edi
call   1060 <ioperm@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x10(%rbp)
cmpl   $0xa,-0x10(%rbp)
jge    1224 <main+0xd4>
imul   $0x16,-0x10(%rbp),%ecx
mov    $0x1234dc,%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    $0x61,%edi
call   1070 <inb@plt>
mov    %eax,%edi
or     $0x3,%edi
mov    $0x61,%esi
call   1050 <outb@plt>
mov    $0xb6,%edi
mov    $0x43,%esi
call   1050 <outb@plt>
mov    -0xc(%rbp),%edi
and    $0xff,%edi
mov    $0x42,%esi
call   1050 <outb@plt>
mov    -0xc(%rbp),%edi
sar    $0x8,%edi
and    $0xff,%edi
mov    $0x42,%esi
call   1050 <outb@plt>
mov    $0x0,%al
call   1030 <long_pause@plt>
mov    $0x63,%edi
call   1070 <inb@plt>
mov    %eax,%edi
and    $0xfc,%edi
mov    $0x61,%esi
call   1050 <outb@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1189 <main+0x39>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x40,%edi
mov    $0x40,%esi
mov    $0x1,%edx
call   1060 <ioperm@plt>
lea    0xe92(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x16,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x1234dc,%eax
xor    %edx,%edx
div    %ebp
mov    %eax,%ebx
mov    $0x61,%edi
call   1070 <inb@plt>
or     $0x3,%eax
mov    %eax,%edi
mov    $0x61,%esi
call   1050 <outb@plt>
mov    $0xb6,%edi
mov    $0x43,%esi
call   1050 <outb@plt>
movzbl %bl,%edi
mov    $0x42,%esi
call   1050 <outb@plt>
movzbl %bh,%edi
mov    $0x42,%esi
call   1050 <outb@plt>
xor    %eax,%eax
call   1030 <long_pause@plt>
mov    $0x63,%edi
call   1070 <inb@plt>
and    $0xfc,%eax
mov    %eax,%edi
mov    $0x61,%esi
call   1050 <outb@plt>
add    $0x16,%ebp
cmp    $0xdc,%ebp
jne    1180 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c" res of ioperm = %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @ioperm(i32 64, i32 64, i32 1)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 1, i32* %4
br label %8
8: ; preds = %30, %0
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 10
br i1 %10, label %11, label %33
11: ; preds = %8
%12 = load i32, i32* %4
%13 = mul nsw i32 %12, 22
%14 = sdiv i32 1193180, %13
store i32 %14, i32* %3
%15 = call i32 @inb(i32 97)
%16 = or i32 %15, 3
%17 = call i32 @outb(i32 %16, i32 97)
%18 = call i32 @outb(i32 182, i32 67)
%19 = load i32, i32* %3
%20 = and i32 %19, 255
%21 = call i32 @outb(i32 %20, i32 66)
%22 = load i32, i32* %3
%23 = ashr i32 %22, 8
%24 = and i32 %23, 255
%25 = call i32 @outb(i32 %24, i32 66)
%26 = call i32 (...) @long_pause()
%27 = call i32 @inb(i32 99)
%28 = and i32 %27, 252
%29 = call i32 @outb(i32 %28, i32 97)
br label %30
30: ; preds = %11
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %8
33: ; preds = %8
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [21 x i8] c" res of ioperm = %d\0A\00"
define i32 @main() {
%1 = tail call i32 @ioperm(i32 64, i32 64, i32 1)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 1, %0 ], [ %20, %3 ]
%5 = mul nuw nsw i32 %4, 22
%6 = udiv i32 1193180, %5
%7 = tail call i32 @inb(i32 97)
%8 = or i32 %7, 3
%9 = tail call i32 @outb(i32 %8, i32 97)
%10 = tail call i32 @outb(i32 182, i32 67)
%11 = and i32 %6, 255
%12 = tail call i32 @outb(i32 %11, i32 66)
%13 = lshr i32 %6, 8
%14 = and i32 %13, 255
%15 = tail call i32 @outb(i32 %14, i32 66)
%16 = tail call i32 (...) @long_pause()
%17 = tail call i32 @inb(i32 99)
%18 = and i32 %17, 252
%19 = tail call i32 @outb(i32 %18, i32 97)
%20 = add nuw nsw i32 %4, 1
%21 = icmp eq i32 %20, 10
br i1 %21, label %22, label %3
22: ; preds = %3
ret i32 0
}