#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*/ doSleep();
int /*<<< orphan*/ doTick();
void loop() {
  for (int i = 0; i < (30 * 5); i++) {
    doTick();
    doSleep();
  }
  while (1) {
    static unsigned int fractional_position = 0;
    static unsigned int tick_counter = 0;
    unsigned int limit = 545;
    if (fractional_position < 4679)
      limit++;
    if (tick_counter++ >= limit) {
      tick_counter = 0;
      fractional_position++;
      if (fractional_position >= 10800)
        fractional_position = 0;
      doTick();
    } else {
      doSleep();
    }
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x96,-0x4(%rbp)
jge    1158 <loop+0x38>
mov    $0x0,%al
call   1030 <doTick@plt>
mov    $0x0,%al
call   1040 <doSleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    112f <loop+0xf>
jmp    115d <loop+0x3d>
movl   $0x221,-0x8(%rbp)
cmpl   $0x1247,0x2ec6(%rip)
jae    117d <loop+0x5d>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    0x2eb5(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2eaa(%rip)
cmp    -0x8(%rbp),%eax
jb     11d6 <loop+0xb6>
movl   $0x0,0x2e97(%rip)
mov    0x2e8d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e84(%rip)
cmpl   $0x2a30,0x2e7a(%rip)
jb     11ca <loop+0xaa>
movl   $0x0,0x2e6a(%rip)
mov    $0x0,%al
call   1030 <doTick@plt>
jmp    11dd <loop+0xbd>
mov    $0x0,%al
call   1040 <doSleep@plt>
jmp    115d <loop+0x3d>

x86 assembly (clang, -O2):
<loop>:
push   %rbx
mov    $0x96,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <doTick@plt>
xor    %eax,%eax
call   1040 <doSleep@plt>
add    $0xffffffff,%ebx
jne    1130 <loop+0x10>
xor    %ebx,%ebx
jmp    1172 <loop+0x52>
nopw   0x0(%rax,%rax,1)
movl   $0x0,0x2ede(%rip)
add    $0x1,%eax
cmp    $0x2a30,%eax
cmovae %ebx,%eax
mov    %eax,0x2ec9(%rip)
xor    %eax,%eax
call   1030 <doTick@plt>
mov    0x2ebc(%rip),%eax
cmp    $0x1247,%eax
mov    $0x221,%ecx
adc    $0x0,%ecx
mov    0x2ead(%rip),%edx
lea    0x1(%rdx),%esi
mov    %esi,0x2ea4(%rip)
cmp    %ecx,%edx
jae    1150 <loop+0x30>
xor    %eax,%eax
call   1040 <doSleep@plt>
jmp    1172 <loop+0x52>

LLVM IR (-O0):
@loop.fractional_position = internal global i32 0
@loop.tick_counter = internal global i32 0
define void @loop() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
br label %3
3: ; preds = %9, %0
%4 = load i32, i32* %1
%5 = icmp slt i32 %4, 150
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = call i32 (...) @doTick()
%8 = call i32 (...) @doSleep()
br label %9
9: ; preds = %6
%10 = load i32, i32* %1
%11 = add nsw i32 %10, 1
store i32 %11, i32* %1
br label %3
12: ; preds = %3
br label %13
13: ; preds = %12, %34
store i32 545, i32* %2
%14 = load i32, i32* @loop.fractional_position
%15 = icmp ult i32 %14, 4679
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %2
%18 = add i32 %17, 1
store i32 %18, i32* %2
br label %19
19: ; preds = %16, %13
%20 = load i32, i32* @loop.tick_counter
%21 = add i32 %20, 1
store i32 %21, i32* @loop.tick_counter
%22 = load i32, i32* %2
%23 = icmp uge i32 %20, %22
br i1 %23, label %24, label %32
24: ; preds = %19
store i32 0, i32* @loop.tick_counter
%25 = load i32, i32* @loop.fractional_position
%26 = add i32 %25, 1
store i32 %26, i32* @loop.fractional_position
%27 = load i32, i32* @loop.fractional_position
%28 = icmp uge i32 %27, 10800
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 0, i32* @loop.fractional_position
br label %30
30: ; preds = %29, %24
%31 = call i32 (...) @doTick()
br label %34
32: ; preds = %19
%33 = call i32 (...) @doSleep()
br label %34
34: ; preds = %32, %30
br label %13
}

LLVM IR (-O2):
@loop.fractional_position = internal unnamed_addr global i32 0
@loop.tick_counter = internal unnamed_addr global i32 0
define void @loop() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 0, %0 ], [ %5, %1 ]
%3 = tail call i32 (...) @doTick()
%4 = tail call i32 (...) @doSleep()
%5 = add nuw nsw i32 %2, 1
%6 = icmp eq i32 %5, 150
br i1 %6, label %7, label %1
7: ; preds = %1, %21
%8 = load i32, i32* @loop.fractional_position
%9 = icmp ult i32 %8, 4679
%10 = select i1 %9, i32 546, i32 545
%11 = load i32, i32* @loop.tick_counter
%12 = add i32 %11, 1
store i32 %12, i32* @loop.tick_counter
%13 = icmp ult i32 %11, %10
br i1 %13, label %19, label %14
14: ; preds = %7
store i32 0, i32* @loop.tick_counter
%15 = add i32 %8, 1
%16 = icmp ugt i32 %15, 10799
%17 = select i1 %16, i32 0, i32 %15
store i32 %17, i32* @loop.fractional_position
%18 = tail call i32 (...) @doTick()
br label %21
19: ; preds = %7
%20 = tail call i32 (...) @doSleep()
br label %21
21: ; preds = %19, %14
br label %7
}