#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_position = q_random() % (10);
    for (unsigned char i = 0; i < (10); i++)
      if (i == tick_position)
        doTick();
      else
        doSleep();
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <q_random@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %dl,%al
mov    %al,-0x1(%rbp)
movb   $0x0,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
cmp    $0xa,%eax
jge    1192 <loop+0x62>
movzbl -0x2(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jne    1179 <loop+0x49>
mov    $0x0,%al
call   1030 <doTick@plt>
jmp    1180 <loop+0x50>
mov    $0x0,%al
call   1050 <doSleep@plt>
jmp    1185 <loop+0x55>
mov    -0x2(%rbp),%al
add    $0x1,%al
mov    %al,-0x2(%rbp)
jmp    1150 <loop+0x20>
jmp    1138 <loop+0x8>

x86 assembly (clang, -O2):
<loop>:
push   %rbx
jmp    1184 <loop+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1030 <doTick@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   1050 <doSleep@plt>
xor    %eax,%eax
call   1040 <q_random@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
xor    %eax,%eax
test   %bl,%bl
je     1140 <loop+0x10>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x1,%bl
jne    11d0 <loop+0xa0>
call   1030 <doTick@plt>
jmp    114c <loop+0x1c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x2,%bl
jne    11e6 <loop+0xb6>
call   1030 <doTick@plt>
jmp    1153 <loop+0x23>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x3,%bl
jne    11fc <loop+0xcc>
call   1030 <doTick@plt>
jmp    115a <loop+0x2a>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x4,%bl
jne    1212 <loop+0xe2>
call   1030 <doTick@plt>
jmp    1161 <loop+0x31>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x5,%bl
jne    1228 <loop+0xf8>
call   1030 <doTick@plt>
jmp    1168 <loop+0x38>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x6,%bl
jne    123e <loop+0x10e>
call   1030 <doTick@plt>
jmp    116f <loop+0x3f>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x7,%bl
jne    1254 <loop+0x124>
call   1030 <doTick@plt>
jmp    1176 <loop+0x46>
call   1050 <doSleep@plt>
xor    %eax,%eax
cmp    $0x8,%bl
jne    126a <loop+0x13a>
call   1030 <doTick@plt>
jmp    117d <loop+0x4d>
call   1050 <doSleep@plt>
cmp    $0x9,%bl
jne    117d <loop+0x4d>
xor    %eax,%eax
call   1030 <doTick@plt>
jmp    1184 <loop+0x54>

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

LLVM IR (-O2):
define void @loop() {
br label %1
1: ; preds = %70, %0
%2 = tail call i32 (...) @q_random()
%3 = srem i32 %2, 10
%4 = trunc i32 %3 to i8
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = tail call i32 (...) @doTick()
%8 = tail call i32 (...) @doSleep()
br label %19
9: ; preds = %1
%10 = tail call i32 (...) @doSleep()
%11 = icmp eq i8 %4, 1
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 (...) @doTick()
br label %19
14: ; preds = %9
%15 = tail call i32 (...) @doSleep()
%16 = icmp eq i8 %4, 2
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = tail call i32 (...) @doTick()
br label %26
19: ; preds = %12, %6
%20 = tail call i32 (...) @doSleep()
br label %26
21: ; preds = %14
%22 = tail call i32 (...) @doSleep()
%23 = icmp eq i8 %4, 3
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = tail call i32 (...) @doTick()
br label %33
26: ; preds = %17, %19
%27 = tail call i32 (...) @doSleep()
br label %33
28: ; preds = %21
%29 = tail call i32 (...) @doSleep()
%30 = icmp eq i8 %4, 4
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = tail call i32 (...) @doTick()
br label %40
33: ; preds = %24, %26
%34 = tail call i32 (...) @doSleep()
br label %40
35: ; preds = %28
%36 = tail call i32 (...) @doSleep()
%37 = icmp eq i8 %4, 5
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = tail call i32 (...) @doTick()
br label %47
40: ; preds = %31, %33
%41 = tail call i32 (...) @doSleep()
br label %47
42: ; preds = %35
%43 = tail call i32 (...) @doSleep()
%44 = icmp eq i8 %4, 6
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = tail call i32 (...) @doTick()
br label %54
47: ; preds = %38, %40
%48 = tail call i32 (...) @doSleep()
br label %54
49: ; preds = %42
%50 = tail call i32 (...) @doSleep()
%51 = icmp eq i8 %4, 7
br i1 %51, label %52, label %56
52: ; preds = %49
%53 = tail call i32 (...) @doTick()
br label %61
54: ; preds = %45, %47
%55 = tail call i32 (...) @doSleep()
br label %61
56: ; preds = %49
%57 = tail call i32 (...) @doSleep()
%58 = icmp eq i8 %4, 8
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = tail call i32 (...) @doTick()
br label %66
61: ; preds = %52, %54
%62 = tail call i32 (...) @doSleep()
br label %66
63: ; preds = %56
%64 = tail call i32 (...) @doSleep()
%65 = icmp eq i8 %4, 9
br i1 %65, label %68, label %66
66: ; preds = %61, %59, %63
%67 = tail call i32 (...) @doSleep()
br label %70
68: ; preds = %63
%69 = tail call i32 (...) @doTick()
br label %70
70: ; preds = %68, %66
br label %1
}