#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*/ BiosGetTicks(unsigned int *);
void delay(unsigned milliseconds) {
  unsigned tcnt = (milliseconds + 27) / 55;
  unsigned ticks[2][2];
  BiosGetTicks(ticks[0]);
  for (;;) {
    BiosGetTicks(ticks[1]);
    if (ticks[1][0] < ticks[0][0])
      --ticks[1][1];
    ticks[1][0] -= ticks[0][0];
    ticks[1][1] -= ticks[0][1];
    if (ticks[1][0] >= tcnt || ticks[1][1])
      break;
  }
}


x86 assembly (clang, -O0):
<delay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1b,%eax
mov    $0x37,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <BiosGetTicks@plt>
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   1030 <BiosGetTicks@plt>
mov    -0x18(%rbp),%eax
cmp    -0x20(%rbp),%eax
jae    1158 <delay+0x48>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x18(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1184 <delay+0x74>
cmpl   $0x0,-0x14(%rbp)
je     1189 <delay+0x79>
jmp    118e <delay+0x7e>
jmp    1136 <delay+0x26>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delay>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
add    $0x1b,%ebx
imul   $0x29e4129f,%rbx,%rax
shr    $0x20,%rax
sub    %eax,%ebx
shr    %ebx
add    %eax,%ebx
shr    $0x5,%ebx
mov    %rsp,%rdi
call   1030 <BiosGetTicks@plt>
lea    0x8(%rsp),%r14
nopl   (%rax)
mov    %r14,%rdi
call   1030 <BiosGetTicks@plt>
mov    0x8(%rsp),%ecx
sub    (%rsp),%ecx
mov    0xc(%rsp),%eax
sbb    $0x0,%eax
mov    %ecx,0x8(%rsp)
sub    0x4(%rsp),%eax
mov    %eax,0xc(%rsp)
cmp    %ebx,%ecx
jae    116a <delay+0x5a>
test   %eax,%eax
je     1140 <delay+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @delay(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x [2 x i32]]
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = add i32 %5, 27
%7 = udiv i32 %6, 55
store i32 %7, i32* %3
%8 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%10 = call i32 @BiosGetTicks(i32* %9)
br label %11
11: ; preds = %53, %1
%12 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %12, i64 0, i64 0
%14 = call i32 @BiosGetTicks(i32* %13)
%15 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%17 = load i32, i32* %16
%18 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 0
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %18, i64 0, i64 0
%20 = load i32, i32* %19
%21 = icmp ult i32 %17, %20
br i1 %21, label %22, label %27
22: ; preds = %11
%23 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %23, i64 0, i64 1
%25 = load i32, i32* %24
%26 = add i32 %25, -1
store i32 %26, i32* %24
br label %27
27: ; preds = %22, %11
%28 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 0
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %28, i64 0, i64 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %31, i64 0, i64 0
%33 = load i32, i32* %32
%34 = sub i32 %33, %30
store i32 %34, i32* %32
%35 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 0
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %35, i64 0, i64 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %38, i64 0, i64 1
%40 = load i32, i32* %39
%41 = sub i32 %40, %37
store i32 %41, i32* %39
%42 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %42, i64 0, i64 0
%44 = load i32, i32* %43
%45 = load i32, i32* %3
%46 = icmp uge i32 %44, %45
br i1 %46, label %52, label %47
47: ; preds = %27
%48 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %4, i64 0, i64 1
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %48, i64 0, i64 1
%50 = load i32, i32* %49
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %47, %27
br label %54
53: ; preds = %47
br label %11
54: ; preds = %52
ret void
}

LLVM IR (-O2):
define void @delay(i32 %0) {
%2 = alloca [2 x [2 x i32]]
%3 = add i32 %0, 27
%4 = udiv i32 %3, 55
%5 = bitcast [2 x [2 x i32]]* %2 to i8*
%6 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 0, i64 0
%7 = call i32 @BiosGetTicks(i32* %6)
%8 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 1, i64 0
%9 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 1, i64 1
%10 = getelementptr inbounds [2 x [2 x i32]], [2 x [2 x i32]]* %2, i64 0, i64 0, i64 1
br label %11
11: ; preds = %11, %1
%12 = call i32 @BiosGetTicks(i32* %8)
%13 = load i32, i32* %8
%14 = load i32, i32* %6
%15 = icmp ult i32 %13, %14
%16 = load i32, i32* %9
%17 = sext i1 %15 to i32
%18 = add i32 %16, %17
%19 = sub i32 %13, %14
store i32 %19, i32* %8
%20 = load i32, i32* %10
%21 = sub i32 %18, %20
store i32 %21, i32* %9
%22 = icmp uge i32 %19, %4
%23 = icmp ne i32 %21, 0
%24 = select i1 %22, i1 true, i1 %23
br i1 %24, label %25, label %11
25: ; preds = %11
ret void
}