#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 /*<<< orphan*/ exit(int);
int inb(int);
scalar_t__ ioperm(int, int, int);
int /*<<< orphan*/ outb(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ usleep(int);
int main() {
  if (ioperm(0x378, 3, 1)) {
    perror("ioperm");
    exit(1);
  }
  outb(0, 0x378);
  int c = 1;
  int DELAY = 100000;
  while (1) {
    c++;
    if (c > 1000) {
      break;
    }
    printf("статус: %d\n", c);
    outb(0x20, 0x378);
    outb(0x04, 0x37a);
    usleep(100);
    outb(0x00, 0x37a);
    usleep(DELAY);
    outb(0x10, 0x378);
    outb(0x04, 0x37a);
    usleep(100);
    outb(0x00, 0x37a);
    usleep(DELAY);
    outb(0x40, 0x378);
    outb(0x04, 0x37a);
    usleep(100);
    outb(0x00, 0x37a);
    usleep(DELAY);
    outb(0x80, 0x378);
    outb(0x04, 0x37a);
    usleep(100);
    outb(0x00, 0x37a);
    usleep(DELAY);
  }
  outb(0x00, 0x378);
  outb(0x04, 0x37a);
  usleep(100);
  outb(0x00, 0x37a);
  printf("статус: %d\n", inb(0x378 + 1));
  if (ioperm(0x378, 3, 0)) {
    perror("ioperm");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     11b3 <main+0x43>
lea    0xe5c(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
movl   $0x1,-0x8(%rbp)
movl   $0x186a0,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x3e8,-0x8(%rbp)
jle    11e8 <main+0x78>
jmp    12ec <main+0x17c>
mov    -0x8(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1030 <printf@plt>
mov    $0x20,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    -0xc(%rbp),%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    -0xc(%rbp),%edi
call   1090 <usleep@plt>
mov    $0x40,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    -0xc(%rbp),%edi
call   1090 <usleep@plt>
mov    $0x80,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    -0xc(%rbp),%edi
call   1090 <usleep@plt>
jmp    11cd <main+0x5d>
xor    %edi,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x379,%edi
call   1060 <inb@plt>
mov    %eax,%esi
lea    0xcd7(%rip),%rdi
call   1030 <printf@plt>
mov    $0x378,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1050 <ioperm@plt>
cmp    $0x0,%rax
je     1366 <main+0x1f6>
lea    0xca9(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x378,%edi
mov    $0x3,%esi
mov    $0x1,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
jne    1327 <main+0x1b7>
xor    %edi,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x2,%ebx
lea    0xe5e(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0x20,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    $0x10,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    $0x40,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
mov    $0x80,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x186a0,%edi
call   1090 <usleep@plt>
add    $0x1,%ebx
cmp    $0x3e9,%ebx
jne    11b0 <main+0x40>
xor    %edi,%edi
mov    $0x378,%esi
call   1040 <outb@plt>
mov    $0x4,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x64,%edi
call   1090 <usleep@plt>
xor    %edi,%edi
mov    $0x37a,%esi
call   1040 <outb@plt>
mov    $0x379,%edi
call   1060 <inb@plt>
lea    0xd04(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    $0x378,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1050 <ioperm@plt>
test   %rax,%rax
jne    1327 <main+0x1b7>
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xcd2(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"ioperm\00"
@.str.1 = [18 x i8] c"\D1\81\D1\82\D0\B0\D1\82\D1\83\D1\81: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @ioperm(i32 888, i32 3, i32 1)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = call i32 @outb(i32 0, i32 888)
store i32 1, i32* %2
store i32 100000, i32* %3
br label %11
11: ; preds = %9, %17
%12 = load i32, i32* %2
%13 = add nsw i32 %12, 1
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 1000
br i1 %15, label %16, label %17
16: ; preds = %11
br label %44
17: ; preds = %11
%18 = load i32, i32* %2
%19 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = call i32 @outb(i32 32, i32 888)
%21 = call i32 @outb(i32 4, i32 890)
%22 = call i32 @usleep(i32 100)
%23 = call i32 @outb(i32 0, i32 890)
%24 = load i32, i32* %3
%25 = call i32 @usleep(i32 %24)
%26 = call i32 @outb(i32 16, i32 888)
%27 = call i32 @outb(i32 4, i32 890)
%28 = call i32 @usleep(i32 100)
%29 = call i32 @outb(i32 0, i32 890)
%30 = load i32, i32* %3
%31 = call i32 @usleep(i32 %30)
%32 = call i32 @outb(i32 64, i32 888)
%33 = call i32 @outb(i32 4, i32 890)
%34 = call i32 @usleep(i32 100)
%35 = call i32 @outb(i32 0, i32 890)
%36 = load i32, i32* %3
%37 = call i32 @usleep(i32 %36)
%38 = call i32 @outb(i32 128, i32 888)
%39 = call i32 @outb(i32 4, i32 890)
%40 = call i32 @usleep(i32 100)
%41 = call i32 @outb(i32 0, i32 890)
%42 = load i32, i32* %3
%43 = call i32 @usleep(i32 %42)
br label %11
44: ; preds = %16
%45 = call i32 @outb(i32 0, i32 888)
%46 = call i32 @outb(i32 4, i32 890)
%47 = call i32 @usleep(i32 100)
%48 = call i32 @outb(i32 0, i32 890)
%49 = call i32 @inb(i32 889)
%50 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = call i64 @ioperm(i32 888, i32 3, i32 0)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %44
%54 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %44
%57 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"ioperm\00"
@.str.1 = [18 x i8] c"\D1\81\D1\82\D0\B0\D1\82\D1\83\D1\81: %d\0A\00"
define i32 @main() {
%1 = tail call i64 @ioperm(i32 888, i32 3, i32 1)
%2 = icmp eq i64 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call i32 @outb(i32 0, i32 888)
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ 2, %6 ], [ %31, %8 ]
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = tail call i32 @outb(i32 32, i32 888)
%12 = tail call i32 @outb(i32 4, i32 890)
%13 = tail call i32 @usleep(i32 100)
%14 = tail call i32 @outb(i32 0, i32 890)
%15 = tail call i32 @usleep(i32 100000)
%16 = tail call i32 @outb(i32 16, i32 888)
%17 = tail call i32 @outb(i32 4, i32 890)
%18 = tail call i32 @usleep(i32 100)
%19 = tail call i32 @outb(i32 0, i32 890)
%20 = tail call i32 @usleep(i32 100000)
%21 = tail call i32 @outb(i32 64, i32 888)
%22 = tail call i32 @outb(i32 4, i32 890)
%23 = tail call i32 @usleep(i32 100)
%24 = tail call i32 @outb(i32 0, i32 890)
%25 = tail call i32 @usleep(i32 100000)
%26 = tail call i32 @outb(i32 128, i32 888)
%27 = tail call i32 @outb(i32 4, i32 890)
%28 = tail call i32 @usleep(i32 100)
%29 = tail call i32 @outb(i32 0, i32 890)
%30 = tail call i32 @usleep(i32 100000)
%31 = add nuw nsw i32 %9, 1
%32 = icmp eq i32 %31, 1001
br i1 %32, label %33, label %8
33: ; preds = %8
%34 = tail call i32 @outb(i32 0, i32 888)
%35 = tail call i32 @outb(i32 4, i32 890)
%36 = tail call i32 @usleep(i32 100)
%37 = tail call i32 @outb(i32 0, i32 890)
%38 = tail call i32 @inb(i32 889)
%39 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = tail call i64 @ioperm(i32 888, i32 3, i32 0)
%41 = icmp eq i64 %40, 0
br i1 %41, label %45, label %42
42: ; preds = %33
%43 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %33
%46 = tail call i32 @exit(i32 0)
unreachable
}