#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 */
struct cdrom_tocentry {
  int cdte_ctrl;
};

/* Variables and functions */
int CDROM_DATA_TRACK;
scalar_t__ cd_get_tracks(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ get_tocentry(int, struct cdrom_tocentry *);
int cd_is_audio(int track) {
  struct cdrom_tocentry e;
  if ((cd_get_tracks(0, 0) < 0) || (get_tocentry(track, &e) < 0))
    return -1;
  return (e.cdte_ctrl & CDROM_DATA_TRACK) ? 0 : 1;
}


x86 assembly (clang, -O0):
<cd_is_audio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
xor    %esi,%esi
mov    %esi,%edi
call   1040 <cd_get_tracks@plt>
cmp    $0x0,%rax
jl     1154 <cd_is_audio+0x34>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <get_tocentry@plt>
cmp    $0x0,%rax
jge    1160 <cd_is_audio+0x40>
movl   $0xffffffff,-0x4(%rbp)
jmp    117c <cd_is_audio+0x5c>
mov    -0x10(%rbp),%edx
mov    0x2e7e(%rip),%rax
and    (%rax),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cd_is_audio>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %edi,%edi
xor    %esi,%esi
call   1040 <cd_get_tracks@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
js     1158 <cd_is_audio+0x38>
mov    %rsp,%rsi
mov    %ebp,%edi
call   1030 <get_tocentry@plt>
test   %rax,%rax
js     1158 <cd_is_audio+0x38>
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
xor    %ebx,%ebx
test   %eax,(%rsp)
sete   %bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.cdrom_tocentry = type { i32 }
@CDROM_DATA_TRACK = global i32 0
define i32 @cd_is_audio(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.cdrom_tocentry
store i32 %0, i32* %3
%5 = call i64 @cd_get_tracks(i32 0, i32 0)
%6 = icmp slt i64 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i32, i32* %3
%9 = call i64 @get_tocentry(i32 %8, %struct.cdrom_tocentry* %4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %7, %1
store i32 -1, i32* %2
br label %20
12: ; preds = %7
%13 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = load i32, i32* @CDROM_DATA_TRACK
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
%18 = zext i1 %17 to i64
%19 = select i1 %17, i32 0, i32 1
store i32 %19, i32* %2
br label %20
20: ; preds = %12, %11
%21 = load i32, i32* %2
ret i32 %21
}

LLVM IR (-O2):
%struct.cdrom_tocentry = type { i32 }
@CDROM_DATA_TRACK = global i32 0
define i32 @cd_is_audio(i32 %0) {
%2 = alloca %struct.cdrom_tocentry
%3 = bitcast %struct.cdrom_tocentry* %2 to i8*
%4 = tail call i64 @cd_get_tracks(i32 0, i32 0)
%5 = icmp slt i64 %4, 0
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = call i64 @get_tocentry(i32 %0, %struct.cdrom_tocentry* %2)
%8 = icmp slt i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = load i32, i32* @CDROM_DATA_TRACK
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %1, %6, %9
%17 = phi i32 [ %15, %9 ], [ -1, %6 ], [ -1, %1 ]
ret i32 %17
}