#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 */
typedef int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int inb(int);
void mssleep(uint32_t waittime) {
  uint32_t i;
  uint8_t x, y = inb(0x61) & 0x10;
  waittime *= 67;
  for (i = 0; i < waittime; i++) {
    while ((x = inb(0x61) & 0x10) == y)
      continue;
    y = x;
  }
}


x86 assembly (clang, -O0):
<mssleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x61,%edi
call   1030 <inb@plt>
and    $0x10,%eax
mov    %eax,-0x10(%rbp)
imul   $0x43,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117c <mssleep+0x6c>
jmp    114a <mssleep+0x3a>
mov    $0x61,%edi
call   1030 <inb@plt>
and    $0x10,%eax
mov    %eax,-0xc(%rbp)
cmp    -0x10(%rbp),%eax
jne    1168 <mssleep+0x58>
jmp    114a <mssleep+0x3a>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1139 <mssleep+0x29>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mssleep>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
mov    $0x61,%edi
call   1030 <inb@plt>
test   %ebp,%ebp
jle    115b <mssleep+0x4b>
mov    %eax,%ebx
imul   $0x43,%ebp,%eax
and    $0x10,%ebx
cmp    $0x2,%eax
mov    $0x1,%r14d
cmovge %eax,%r14d
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    $0x61,%edi
call   1030 <inb@plt>
and    $0x10,%eax
cmp    %ebx,%eax
je     1140 <mssleep+0x30>
add    $0x1,%ebp
mov    %eax,%ebx
cmp    %r14d,%ebp
jne    1140 <mssleep+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @mssleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
%6 = call i32 @inb(i32 97)
%7 = and i32 %6, 16
store i32 %7, i32* %5
%8 = load i32, i32* %2
%9 = mul nsw i32 %8, 67
store i32 %9, i32* %2
store i32 0, i32* %3
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
br label %15
15: ; preds = %20, %14
%16 = call i32 @inb(i32 97)
%17 = and i32 %16, 16
store i32 %17, i32* %4
%18 = load i32, i32* %5
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %15
br label %15
21: ; preds = %15
%22 = load i32, i32* %4
store i32 %22, i32* %5
br label %23
23: ; preds = %21
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %10
26: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @mssleep(i32 %0) {
%2 = tail call i32 @inb(i32 97)
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %18
4: ; preds = %1
%5 = mul i32 %0, 67
%6 = and i32 %2, 16
%7 = call i32 @llvm.smax.i32(i32 %5, i32 1)
br label %8
8: ; preds = %4, %15
%9 = phi i32 [ %13, %15 ], [ %6, %4 ]
%10 = phi i32 [ %16, %15 ], [ 0, %4 ]
br label %11
11: ; preds = %8, %11
%12 = tail call i32 @inb(i32 97)
%13 = and i32 %12, 16
%14 = icmp eq i32 %13, %9
br i1 %14, label %11, label %15
15: ; preds = %11
%16 = add nuw nsw i32 %10, 1
%17 = icmp eq i32 %16, %7
br i1 %17, label %18, label %8
18: ; preds = %15, %1
ret void
}