#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 */
long CD_FRAMES;
long cd_disc_length_frames();
int /*<<< orphan*/ cd_present();
int cd_disc_length(void) {
  long frames = cd_disc_length_frames();
  int seconds = frames / CD_FRAMES;
  if (!cd_present())
    return 0;
  if ((frames % CD_FRAMES) > (CD_FRAMES / 2))
    seconds++;
  return seconds;
}


x86 assembly (clang, -O0):
<cd_disc_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <cd_disc_length_frames@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2ea2(%rip),%rcx
cqto
idivq  (%rcx)
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <cd_present@plt>
cmp    $0x0,%eax
jne    1162 <cd_disc_length+0x42>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <cd_disc_length+0x86>
mov    -0x10(%rbp),%rax
mov    0x2e73(%rip),%rcx
cqto
idivq  (%rcx)
mov    %rdx,-0x20(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    -0x20(%rbp),%rdx
cmp    %rax,%rdx
jle    11a0 <cd_disc_length+0x80>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd_disc_length>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <cd_disc_length_frames@plt>
mov    %rax,%rbx
mov    0x2ea6(%rip),%r14
mov    (%r14),%r15
xor    %eax,%eax
call   1040 <cd_present@plt>
test   %eax,%eax
je     11a1 <cd_disc_length+0x81>
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
je     1161 <cd_disc_length+0x41>
mov    %rbx,%rax
cqto
idiv   %r15
mov    %rax,%rcx
jmp    116a <cd_disc_length+0x4a>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%ecx
mov    (%r14),%rsi
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1183 <cd_disc_length+0x63>
mov    %rbx,%rax
cqto
idiv   %rsi
jmp    1189 <cd_disc_length+0x69>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
mov    %rsi,%rax
shr    $0x3f,%rax
add    %rsi,%rax
sar    %rax
xor    %ebp,%ebp
cmp    %rax,%rdx
setg   %bpl
add    %ecx,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CD_FRAMES = global i64 0
define i32 @cd_disc_length() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = call i64 (...) @cd_disc_length_frames()
store i64 %4, i64* %2
%5 = load i64, i64* %2
%6 = load i64, i64* @CD_FRAMES
%7 = sdiv i64 %5, %6
%8 = trunc i64 %7 to i32
store i32 %8, i32* %3
%9 = call i32 (...) @cd_present()
%10 = icmp ne i32 %9, 0
br i1 %10, label %12, label %11
11: ; preds = %0
store i32 0, i32* %1
br label %24
12: ; preds = %0
%13 = load i64, i64* %2
%14 = load i64, i64* @CD_FRAMES
%15 = srem i64 %13, %14
%16 = load i64, i64* @CD_FRAMES
%17 = sdiv i64 %16, 2
%18 = icmp sgt i64 %15, %17
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %22
22: ; preds = %19, %12
%23 = load i32, i32* %3
store i32 %23, i32* %1
br label %24
24: ; preds = %22, %11
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@CD_FRAMES = global i64 0
define i32 @cd_disc_length() {
%1 = tail call i64 (...) @cd_disc_length_frames()
%2 = load i64, i64* @CD_FRAMES
%3 = tail call i32 (...) @cd_present()
%4 = icmp eq i32 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %0
%6 = sdiv i64 %1, %2
%7 = trunc i64 %6 to i32
%8 = load i64, i64* @CD_FRAMES
%9 = srem i64 %1, %8
%10 = sdiv i64 %8, 2
%11 = icmp sgt i64 %9, %10
%12 = zext i1 %11 to i32
%13 = add nsw i32 %12, %7
br label %14
14: ; preds = %0, %5
%15 = phi i32 [ %13, %5 ], [ 0, %0 ]
ret i32 %15
}