#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() {
  while (1) {
    unsigned char tick_count = (q_random() % 30) + 1;
    for (unsigned char i = 0; i < tick_count; i++) {
      doTick();
      doSleep();
    }
    for (unsigned char i = 0; i < tick_count * 8; i++)
      doSleep();
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <q_random@plt>
mov    $0x1e,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %dl,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jge    117e <loop+0x4e>
mov    $0x0,%al
call   1030 <doTick@plt>
mov    $0x0,%al
call   1050 <doSleep@plt>
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
jmp    1153 <loop+0x23>
movb   $0x0,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
movzbl -0x1(%rbp),%ecx
shl    $0x3,%ecx
cmp    %ecx,%eax
jge    11a9 <loop+0x79>
mov    $0x0,%al
call   1050 <doSleep@plt>
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    1182 <loop+0x52>
jmp    1138 <loop+0x8>

x86 assembly (clang, -O2):
<loop>:
push   %rbp
push   %rbx
push   %rax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <q_random@plt>
cltq
imul   $0xffffffff88888889,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x4,%ecx
add    %edx,%ecx
mov    %ecx,%edx
shl    $0x5,%edx
mov    %ecx,%esi
sub    %edx,%esi
add    %ecx,%esi
lea    (%rax,%rsi,1),%ebx
add    $0x1,%ebx
and    $0xff,%ebx
mov    %ebx,%ebp
je     1140 <loop+0x10>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <doTick@plt>
xor    %eax,%eax
call   1050 <doSleep@plt>
add    $0xffffffff,%ebp
jne    1180 <loop+0x50>
test   %ebx,%ebx
je     1140 <loop+0x10>
shl    $0x3,%ebx
mov    $0x1,%bpl
nopl   (%rax)
xor    %eax,%eax
call   1050 <doSleep@plt>
movzbl %bpl,%eax
lea    0x1(%rax),%ebp
cmp    %eax,%ebx
ja     11a0 <loop+0x70>
jmp    1140 <loop+0x10>

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

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