#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();
int q_random();
void loop() {
  unsigned char ticks_needed = ((10) - (0));
  while (1) {
    doTick();
    doSleep();
    if (q_random() % 4) {
      for (unsigned char i = 0; i < (10) - 2; i++)
        doSleep();
    } else {
      if (--ticks_needed == 0) {
        doTick();
        for (unsigned char i = 0; i < (0); i++)
          doSleep();
        ticks_needed = ((10) - (0));
      } else {
        doSleep();
      }
      for (unsigned char i = 0; i < (10) - 2; i++)
        doSleep();
    }
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movb   $0xa,-0x1(%rbp)
mov    $0x0,%al
call   1030 <doTick@plt>
mov    $0x0,%al
call   1050 <doSleep@plt>
mov    $0x0,%al
call   1040 <q_random@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     118c <loop+0x5c>
movb   $0x0,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0x8,%eax
jge    1187 <loop+0x57>
mov    $0x0,%al
call   1050 <doSleep@plt>
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
jmp    1166 <loop+0x36>
jmp    1206 <loop+0xd6>
mov    -0x1(%rbp),%al
add    $0xff,%al
mov    %al,-0x1(%rbp)
movzbl %al,%eax
cmp    $0x0,%eax
jne    11d5 <loop+0xa5>
mov    $0x0,%al
call   1030 <doTick@plt>
movb   $0x0,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0x0,%eax
jge    11cc <loop+0x9c>
mov    $0x0,%al
call   1050 <doSleep@plt>
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    11ab <loop+0x7b>
movb   $0xa,-0x1(%rbp)
jmp    11dc <loop+0xac>
mov    $0x0,%al
call   1050 <doSleep@plt>
movb   $0x0,-0x4(%rbp)
movzbl -0x4(%rbp),%eax
cmp    $0x8,%eax
jge    1201 <loop+0xd1>
mov    $0x0,%al
call   1050 <doSleep@plt>
mov    -0x4(%rbp),%al
add    $0x1,%al
mov    %al,-0x4(%rbp)
jmp    11e0 <loop+0xb0>
jmp    1206 <loop+0xd6>
jmp    113c <loop+0xc>

x86 assembly (clang, -O2):
<loop>:
push   %rbx
mov    $0xa,%bl
jmp    117d <loop+0x4d>
cs nopw 0x0(%rax,%rax,1)
nop
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1030 <doTick@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
xor    %eax,%eax
call   1040 <q_random@plt>
test   $0x3,%al
jne    1145 <loop+0x15>
xor    %eax,%eax
add    $0xff,%bl
jne    1140 <loop+0x10>
call   1030 <doTick@plt>
mov    $0xa,%bl
jmp    1145 <loop+0x15>

LLVM IR (-O0):
define void @loop() {
%1 = alloca i8
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 10, i8* %1
br label %5
5: ; preds = %0, %52
%6 = call i32 (...) @doTick()
%7 = call i32 (...) @doSleep()
%8 = call i32 (...) @q_random()
%9 = srem i32 %8, 4
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %5
store i8 0, i8* %2
br label %12
12: ; preds = %18, %11
%13 = load i8, i8* %2
%14 = zext i8 %13 to i32
%15 = icmp slt i32 %14, 8
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = call i32 (...) @doSleep()
br label %18
18: ; preds = %16
%19 = load i8, i8* %2
%20 = add i8 %19, 1
store i8 %20, i8* %2
br label %12
21: ; preds = %12
br label %52
22: ; preds = %5
%23 = load i8, i8* %1
%24 = add i8 %23, -1
store i8 %24, i8* %1
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %39
27: ; preds = %22
%28 = call i32 (...) @doTick()
store i8 0, i8* %3
br label %29
29: ; preds = %35, %27
%30 = load i8, i8* %3
%31 = zext i8 %30 to i32
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %29
%34 = call i32 (...) @doSleep()
br label %35
35: ; preds = %33
%36 = load i8, i8* %3
%37 = add i8 %36, 1
store i8 %37, i8* %3
br label %29
38: ; preds = %29
store i8 10, i8* %1
br label %41
39: ; preds = %22
%40 = call i32 (...) @doSleep()
br label %41
41: ; preds = %39, %38
store i8 0, i8* %4
br label %42
42: ; preds = %48, %41
%43 = load i8, i8* %4
%44 = zext i8 %43 to i32
%45 = icmp slt i32 %44, 8
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = call i32 (...) @doSleep()
br label %48
48: ; preds = %46
%49 = load i8, i8* %4
%50 = add i8 %49, 1
store i8 %50, i8* %4
br label %42
51: ; preds = %42
br label %52
52: ; preds = %51, %21
br label %5
}

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