#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() {
  unsigned int inner_counter = 0;
  unsigned int outer_counter = 0;
  unsigned int tick_counter = 0;
  while (1) {
    if (++tick_counter >= (10)) {
      tick_counter = 0;
    }
    unsigned int this_cycle_length = (36);
    if (outer_counter < (12))
      this_cycle_length++;
    if (++inner_counter >= this_cycle_length) {
      inner_counter = 0;
      if (++outer_counter >= (33)) {
        outer_counter = 0;
      }
      doSleep();
    }
    if (tick_counter == 0)
      doTick();
    else
      doSleep();
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    $0xa,%eax
jb     1156 <loop+0x36>
movl   $0x0,-0xc(%rbp)
movl   $0x24,-0x10(%rbp)
cmpl   $0xc,-0x8(%rbp)
jae    1170 <loop+0x50>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
cmp    -0x10(%rbp),%eax
jb     11a9 <loop+0x89>
movl   $0x0,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x21,%eax
jb     11a2 <loop+0x82>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <doSleep@plt>
cmpl   $0x0,-0xc(%rbp)
jne    11bf <loop+0x9f>
mov    $0x0,%al
call   1030 <doTick@plt>
jmp    11c6 <loop+0xa6>
mov    $0x0,%al
call   1040 <doSleep@plt>
jmp    113d <loop+0x1d>

x86 assembly (clang, -O2):
<loop>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %ebx,%ebx
jmp    1145 <loop+0x25>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1040 <doSleep@plt>
add    $0x1,%ebx
cmp    $0xa,%ebx
cmovae %r14d,%ebx
xor    %eax,%eax
cmp    $0xc,%r15d
setb   %al
or     $0x24,%eax
add    $0x1,%ebp
cmp    %eax,%ebp
jb     1177 <loop+0x57>
add    $0x1,%r15d
xor    %ebp,%ebp
cmp    $0x21,%r15d
cmovae %ebp,%r15d
xor    %eax,%eax
call   1040 <doSleep@plt>
xor    %eax,%eax
test   %ebx,%ebx
jne    1140 <loop+0x20>
call   1030 <doTick@plt>
jmp    1145 <loop+0x25>

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

LLVM IR (-O2):
define void @loop() {
br label %1
1: ; preds = %25, %0
%2 = phi i32 [ 0, %0 ], [ %18, %25 ]
%3 = phi i32 [ 0, %0 ], [ %19, %25 ]
%4 = phi i32 [ 0, %0 ], [ %7, %25 ]
%5 = add i32 %4, 1
%6 = icmp ugt i32 %5, 9
%7 = select i1 %6, i32 0, i32 %5
%8 = icmp ult i32 %3, 12
%9 = select i1 %8, i32 37, i32 36
%10 = add i32 %2, 1
%11 = icmp ult i32 %10, %9
br i1 %11, label %17, label %12
12: ; preds = %1
%13 = add i32 %3, 1
%14 = icmp ugt i32 %13, 32
%15 = select i1 %14, i32 0, i32 %13
%16 = tail call i32 (...) @doSleep()
br label %17
17: ; preds = %12, %1
%18 = phi i32 [ 0, %12 ], [ %10, %1 ]
%19 = phi i32 [ %15, %12 ], [ %3, %1 ]
%20 = icmp eq i32 %7, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = tail call i32 (...) @doTick()
br label %25
23: ; preds = %17
%24 = tail call i32 (...) @doSleep()
br label %25
25: ; preds = %23, %21
br label %1
}