#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 */
typedef int /*<<< orphan*/ u_char;

/* Variables and functions */
int /*<<< orphan*/ alarm(scalar_t__);
int /*<<< orphan*/ cd_data_track(int);
int cd_last_track();
int /*<<< orphan*/ cd_play_track(int /*<<< orphan*/);
scalar_t__ cd_track_length(int);
int /*<<< orphan*/ pause();
int rand();
void shuffle_disc(void) {
  int tn = 0, playing = 0;
  while (1) {
    while ((tn == playing) & (!cd_data_track(tn)))
      tn = 1 + (int)(rand() % cd_last_track());
    cd_play_track((u_char)tn);
    playing = tn;
    alarm(cd_track_length(tn) + 0);
    pause();
  }
}


x86 assembly (clang, -O0):
<shuffle_disc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
jmp    118b <shuffle_disc+0x1b>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <cd_data_track@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
cmp    $0x0,%ecx
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11e7 <shuffle_disc+0x77>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <cd_last_track@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x4(%rbp)
jmp    118b <shuffle_disc+0x1b>
mov    -0x4(%rbp),%edi
call   1060 <cd_play_track@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <cd_track_length@plt>
mov    %rax,%rdi
add    $0x0,%rdi
call   1050 <alarm@plt>
mov    $0x0,%al
call   1070 <pause@plt>
jmp    1186 <shuffle_disc+0x16>

x86 assembly (clang, -O2):
<shuffle_disc>:
push   %rbp
push   %rbx
push   %rax
xor    %ebx,%ebx
jmp    11a1 <shuffle_disc+0x31>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%ebp
mov    %ebp,%edi
call   1060 <cd_play_track@plt>
mov    %ebp,%edi
call   1030 <cd_track_length@plt>
mov    %rax,%rdi
call   1050 <alarm@plt>
xor    %eax,%eax
call   1070 <pause@plt>
mov    %ebp,%ebx
mov    %ebx,%edi
call   1040 <cd_data_track@plt>
test   %eax,%eax
jne    1180 <shuffle_disc+0x10>
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <cd_last_track@plt>
mov    %eax,%ecx
mov    %ebp,%eax
cltd
idiv   %ecx
mov    %edx,%ebp
add    $0x1,%ebp
mov    %ebp,%edi
call   1040 <cd_data_track@plt>
cmp    %ebx,%ebp
jne    1182 <shuffle_disc+0x12>
test   %eax,%eax
je     11b0 <shuffle_disc+0x40>
jmp    1182 <shuffle_disc+0x12>

LLVM IR (-O0):
define void @shuffle_disc() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %0, %21
br label %4
4: ; preds = %16, %3
%5 = load i32, i32* %1
%6 = load i32, i32* %2
%7 = icmp eq i32 %5, %6
%8 = zext i1 %7 to i32
%9 = load i32, i32* %1
%10 = call i32 @cd_data_track(i32 %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
%13 = zext i1 %12 to i32
%14 = and i32 %8, %13
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = call i32 (...) @rand()
%18 = call i32 (...) @cd_last_track()
%19 = srem i32 %17, %18
%20 = add nsw i32 1, %19
store i32 %20, i32* %1
br label %4
21: ; preds = %4
%22 = load i32, i32* %1
%23 = call i32 @cd_play_track(i32 %22)
%24 = load i32, i32* %1
store i32 %24, i32* %2
%25 = load i32, i32* %1
%26 = call i64 @cd_track_length(i32 %25)
%27 = add nsw i64 %26, 0
%28 = call i32 @alarm(i64 %27)
%29 = call i32 (...) @pause()
br label %3
}

LLVM IR (-O2):
define void @shuffle_disc() {
br label %1
1: ; preds = %14, %0
%2 = phi i32 [ 0, %0 ], [ %15, %14 ]
%3 = tail call i32 @cd_data_track(i32 %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1, %5
%6 = tail call i32 (...) @rand()
%7 = tail call i32 (...) @cd_last_track()
%8 = srem i32 %6, %7
%9 = add nsw i32 %8, 1
%10 = icmp eq i32 %9, %2
%11 = tail call i32 @cd_data_track(i32 %9)
%12 = icmp eq i32 %11, 0
%13 = and i1 %10, %12
br i1 %13, label %5, label %14
14: ; preds = %5, %1
%15 = phi i32 [ %2, %1 ], [ %9, %5 ]
%16 = tail call i32 @cd_play_track(i32 %15)
%17 = tail call i64 @cd_track_length(i32 %15)
%18 = tail call i32 @alarm(i64 %17)
%19 = tail call i32 (...) @pause()
br label %1
}