#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 */
long CD_FRAMES;
int /*<<< orphan*/ cd_present();
long cd_track_length_frames(int /*<<< orphan*/);
int cd_track_length(u_char trknum) {
  long frames = cd_track_length_frames(trknum);
  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_track_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <cd_track_length_frames@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e9e(%rip),%rcx
cqto
idivq  (%rcx)
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <cd_present@plt>
cmp    $0x0,%eax
jne    1166 <cd_track_length+0x46>
movl   $0x0,-0x4(%rbp)
jmp    11aa <cd_track_length+0x8a>
mov    -0x10(%rbp),%rax
mov    0x2e6f(%rip),%rcx
cqto
idivq  (%rcx)
mov    %rdx,-0x20(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    -0x20(%rbp),%rdx
cmp    %rax,%rdx
jle    11a4 <cd_track_length+0x84>
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_track_length>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
call   1040 <cd_track_length_frames@plt>
mov    %rax,%rbx
mov    0x2eaa(%rip),%r14
mov    (%r14),%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <cd_present@plt>
test   %eax,%eax
je     119f <cd_track_length+0x7f>
mov    %rbx,%rax
or     %r15,%rax
shr    $0x20,%rax
je     115f <cd_track_length+0x3f>
mov    %rbx,%rax
cqto
idiv   %r15
mov    %rax,%rcx
jmp    1168 <cd_track_length+0x48>
mov    %ebx,%eax
xor    %edx,%edx
div    %r15d
mov    %eax,%ecx
mov    (%r14),%rsi
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1181 <cd_track_length+0x61>
mov    %rbx,%rax
cqto
idiv   %rsi
jmp    1187 <cd_track_length+0x67>
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_track_length(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i64 @cd_track_length_frames(i32 %6)
store i64 %7, i64* %4
%8 = load i64, i64* %4
%9 = load i64, i64* @CD_FRAMES
%10 = sdiv i64 %8, %9
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = call i32 (...) @cd_present()
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %1
store i32 0, i32* %2
br label %27
15: ; preds = %1
%16 = load i64, i64* %4
%17 = load i64, i64* @CD_FRAMES
%18 = srem i64 %16, %17
%19 = load i64, i64* @CD_FRAMES
%20 = sdiv i64 %19, 2
%21 = icmp sgt i64 %18, %20
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %25
25: ; preds = %22, %15
%26 = load i32, i32* %5
store i32 %26, i32* %2
br label %27
27: ; preds = %25, %14
%28 = load i32, i32* %2
ret i32 %28
}

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