#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 state = 99;
  unsigned long current_cycle_position = 99;
  unsigned long current_cycle_length = 0;
  char current_cycle_magnitude = 0;
  while (1) {
    if (current_cycle_position++ >= current_cycle_length) {
      if (++state > 3)
        state = 0;
      current_cycle_position = 0;
      switch (state) {
      case 0:
      case 2:
        current_cycle_length = 30 + (q_random() % 30);
        current_cycle_magnitude = (0);
        break;
      case 1:
        current_cycle_length = (60L * 50);
        current_cycle_magnitude = (-2);
        break;
      case 3:
        current_cycle_length = ((60L * 50) * 2);
        current_cycle_magnitude = -((-2) / 2);
        break;
      }
    }
    for (unsigned char i = 0; i < (10) + current_cycle_magnitude; i++) {
      if (i == 0)
        doTick();
      else
        doSleep();
    }
  }
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movb   $0x63,-0x1(%rbp)
movq   $0x63,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
cmp    -0x18(%rbp),%rax
jb     11f3 <loop+0xc3>
mov    -0x1(%rbp),%al
add    $0x1,%al
mov    %al,-0x1(%rbp)
movzbl %al,%eax
cmp    $0x3,%eax
jle    1181 <loop+0x51>
movb   $0x0,-0x1(%rbp)
movq   $0x0,-0x10(%rbp)
movzbl -0x1(%rbp),%eax
mov    %rax,-0x28(%rbp)
sub    $0x3,%rax
ja     11ee <loop+0xbe>
mov    -0x28(%rbp),%rax
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1040 <q_random@plt>
mov    $0x1e,%ecx
cltd
idiv   %ecx
add    $0x1e,%edx
movslq %edx,%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
jmp    11ee <loop+0xbe>
movq   $0xbb8,-0x18(%rbp)
movb   $0xfe,-0x19(%rbp)
jmp    11ee <loop+0xbe>
movq   $0x1770,-0x18(%rbp)
movb   $0x1,-0x19(%rbp)
jmp    11f3 <loop+0xc3>
movb   $0x0,-0x1a(%rbp)
movzbl -0x1a(%rbp),%eax
movsbl -0x19(%rbp),%ecx
add    $0xa,%ecx
cmp    %ecx,%eax
jge    123c <loop+0x10c>
movzbl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jne    1223 <loop+0xf3>
mov    $0x0,%al
call   1030 <doTick@plt>
jmp    122a <loop+0xfa>
mov    $0x0,%al
call   1050 <doSleep@plt>
jmp    122f <loop+0xff>
mov    -0x1a(%rbp),%al
add    $0x1,%al
mov    %al,-0x1a(%rbp)
jmp    11f7 <loop+0xc7>
jmp    1150 <loop+0x20>

x86 assembly (clang, -O2):
<loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x63,%ebp
mov    $0x63,%bl
mov    $0xf7,%r15d
xor    %r12d,%r12d
xor    %r13d,%r13d
xchg   %ax,%ax
cmp    %r12,%rbp
jae    1160 <loop+0x30>
add    $0x1,%rbp
jmp    11e0 <loop+0xb0>
xchg   %ax,%ax
add    $0x1,%bl
xor    %ebp,%ebp
cmp    $0x4,%bl
movzbl %bl,%ebx
cmovae %ebp,%ebx
cmp    $0x3,%bl
ja     11c0 <loop+0x90>
movzbl %bl,%eax
lea    0xe83(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %ebp,%ebp
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),%r12d
add    $0x1e,%r12d
xor    %r13d,%r13d
jmp    11e0 <loop+0xb0>
xor    %ebx,%ebx
jmp    11e0 <loop+0xb0>
mov    $0xfe,%r13b
mov    $0xbb8,%r12d
jmp    11d8 <loop+0xa8>
mov    $0x1,%r13b
mov    $0x1770,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movzbl %r13b,%eax
cmp    $0xf8,%al
cmovl  %r15d,%eax
movsbl %al,%r14d
xor    %eax,%eax
call   1030 <doTick@plt>
add    $0x9,%r14d
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <doSleep@plt>
add    $0xffffffff,%r14d
jne    1200 <loop+0xd0>
jmp    1150 <loop+0x20>

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

LLVM IR (-O2):
define void @loop() {
br label %1
1: ; preds = %28, %0
%2 = phi i8 [ 99, %0 ], [ %20, %28 ]
%3 = phi i64 [ 99, %0 ], [ %21, %28 ]
%4 = phi i64 [ 0, %0 ], [ %22, %28 ]
%5 = phi i8 [ 0, %0 ], [ %23, %28 ]
%6 = add i64 %3, 1
%7 = icmp ult i64 %3, %4
br i1 %7, label %19, label %8
8: ; preds = %1
%9 = add i8 %2, 1
%10 = icmp ugt i8 %9, 3
%11 = select i1 %10, i8 0, i8 %9
switch i8 %11, label %19 [
i8 0, label %12
i8 2, label %12
i8 1, label %17
i8 3, label %18
]
12: ; preds = %8, %8
%13 = tail call i32 (...) @q_random()
%14 = srem i32 %13, 30
%15 = add nsw i32 %14, 30
%16 = zext i32 %15 to i64
br label %19
17: ; preds = %8
br label %19
18: ; preds = %8
br label %19
19: ; preds = %12, %17, %18, %8, %1
%20 = phi i8 [ 0, %8 ], [ %11, %18 ], [ %11, %17 ], [ %11, %12 ], [ %2, %1 ]
%21 = phi i64 [ 0, %8 ], [ 0, %18 ], [ 0, %17 ], [ 0, %12 ], [ %6, %1 ]
%22 = phi i64 [ %4, %8 ], [ 6000, %18 ], [ 3000, %17 ], [ %16, %12 ], [ %4, %1 ]
%23 = phi i8 [ %5, %8 ], [ 1, %18 ], [ -2, %17 ], [ 0, %12 ], [ %5, %1 ]
%24 = call i8 @llvm.smax.i8(i8 %23, i8 -9)
%25 = sext i8 %24 to i32
%26 = tail call i32 (...) @doTick()
%27 = add nsw i32 %25, 9
br label %28
28: ; preds = %19, %28
%29 = phi i32 [ 1, %19 ], [ %31, %28 ]
%30 = tail call i32 (...) @doSleep()
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %29, %27
br i1 %32, label %1, label %28
}