#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 */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ tocentry;
struct TYPE_3__ {
  int minute;
  int second;
  int frame;
};
struct TYPE_4__ {
  TYPE_1__ msf;
};
struct cdrom_tocentry {
  int cdte_track;
  int cdte_ctrl;
  TYPE_2__ cdte_addr;
  int /*<<< orphan*/ cdte_format;
};

/* Variables and functions */
int /*<<< orphan*/ CDROMREADTOCENTRY;
int /*<<< orphan*/ CDROM_MSF;
int ioctl(int, int /*<<< orphan*/, struct cdrom_tocentry *);
int /*<<< orphan*/ memset(struct cdrom_tocentry *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int read_cdrom_toc_entry(int fd, int track, int *track_mode,
                         int *first_frame_minute, int *first_frame_second,
                         int *first_frame_frame) {
  struct cdrom_tocentry tocentry;
  memset(&tocentry, 0, sizeof(tocentry));
  tocentry.cdte_track = track;
  tocentry.cdte_format = CDROM_MSF;
  if (ioctl(fd, CDROMREADTOCENTRY, &tocentry) == -1) {
    perror("CDROMREADTOCENTRY");
    return -1;
  }
  *track_mode = (tocentry.cdte_ctrl & 0x04) ? 1 : 0;
  *first_frame_minute = tocentry.cdte_addr.msf.minute;
  *first_frame_second = tocentry.cdte_addr.msf.second;
  *first_frame_frame = tocentry.cdte_addr.msf.frame;
  return 0;
}


x86 assembly (clang, -O0):
<read_cdrom_toc_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x48(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
lea    -0x48(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    11a6 <read_cdrom_toc_entry+0x76>
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e1 <read_cdrom_toc_entry+0xb1>
mov    -0x44(%rbp),%edx
and    $0x4,%edx
xor    %ecx,%ecx
mov    $0x1,%eax
cmp    $0x0,%edx
cmovne %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x40(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x3c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cdrom_toc_entry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,0x20(%rsp)
mov    %r8,0x18(%rsp)
mov    %rcx,%r13
mov    %rdx,%rbp
mov    %esi,%ebx
mov    %edi,%r14d
mov    %rsp,%r15
xor    %r12d,%r12d
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    %ebx,(%rsp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %r15,%rdx
call   1040 <ioctl@plt>
cmp    $0xffffffff,%eax
je     11ce <read_cdrom_toc_entry+0x9e>
mov    0x4(%rsp),%eax
shr    $0x2,%eax
and    $0x1,%eax
mov    %eax,0x0(%rbp)
mov    0x8(%rsp),%eax
mov    %eax,0x0(%r13)
mov    0xc(%rsp),%eax
mov    0x18(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x10(%rsp),%eax
mov    0x20(%rsp),%rcx
mov    %eax,(%rcx)
mov    %r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe2b(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%r12d
jmp    11bc <read_cdrom_toc_entry+0x8c>

LLVM IR (-O0):
%struct.cdrom_tocentry = type { i32, i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32, i32 }
@CDROM_MSF = global i32 0
@CDROMREADTOCENTRY = global i32 0
@.str = [18 x i8] c"CDROMREADTOCENTRY\00"
define i32 @read_cdrom_toc_entry(i32 %0, i32 %1, i32* %2, i32* %3, i32* %4, i32* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca %struct.cdrom_tocentry
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32* %2, i32** %10
store i32* %3, i32** %11
store i32* %4, i32** %12
store i32* %5, i32** %13
%15 = call i32 @memset(%struct.cdrom_tocentry* %14, i32 0, i32 24)
%16 = load i32, i32* %9
%17 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %14, i32 0, i32 0
store i32 %16, i32* %17
%18 = load i32, i32* @CDROM_MSF
%19 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %14, i32 0, i32 3
store i32 %18, i32* %19
%20 = load i32, i32* %8
%21 = load i32, i32* @CDROMREADTOCENTRY
%22 = call i32 @ioctl(i32 %20, i32 %21, %struct.cdrom_tocentry* %14)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %6
%25 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %7
br label %49
26: ; preds = %6
%27 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %14, i32 0, i32 1
%28 = load i32, i32* %27
%29 = and i32 %28, 4
%30 = icmp ne i32 %29, 0
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 1, i32 0
%33 = load i32*, i32** %10
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %14, i32 0, i32 2
%35 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %34, i32 0, i32 0
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load i32*, i32** %11
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %14, i32 0, i32 2
%40 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %39, i32 0, i32 0
%41 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %40, i32 0, i32 1
%42 = load i32, i32* %41
%43 = load i32*, i32** %12
store i32 %42, i32* %43
%44 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %14, i32 0, i32 2
%45 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %44, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 2
%47 = load i32, i32* %46
%48 = load i32*, i32** %13
store i32 %47, i32* %48
store i32 0, i32* %7
br label %49
49: ; preds = %26, %24
%50 = load i32, i32* %7
ret i32 %50
}

LLVM IR (-O2):
%struct.cdrom_tocentry = type { i32, i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32, i32, i32 }
@CDROM_MSF = global i32 0
@CDROMREADTOCENTRY = global i32 0
@.str = [18 x i8] c"CDROMREADTOCENTRY\00"
define i32 @read_cdrom_toc_entry(i32 %0, i32 %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3, i32* nocapture writeonly %4, i32* nocapture writeonly %5) {
%7 = alloca %struct.cdrom_tocentry
%8 = bitcast %struct.cdrom_tocentry* %7 to i8*
%9 = call i32 @memset(%struct.cdrom_tocentry* %7, i32 0, i32 24)
%10 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %7, i64 0, i32 0
store i32 %1, i32* %10
%11 = load i32, i32* @CDROM_MSF
%12 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %7, i64 0, i32 3
store i32 %11, i32* %12
%13 = load i32, i32* @CDROMREADTOCENTRY
%14 = call i32 @ioctl(i32 %0, i32 %13, %struct.cdrom_tocentry* %7)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %6
%17 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %29
18: ; preds = %6
%19 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %7, i64 0, i32 1
%20 = load i32, i32* %19
%21 = lshr i32 %20, 2
%22 = and i32 %21, 1
store i32 %22, i32* %2
%23 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %7, i64 0, i32 2, i32 0, i32 0
%24 = load i32, i32* %23
store i32 %24, i32* %3
%25 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %7, i64 0, i32 2, i32 0, i32 1
%26 = load i32, i32* %25
store i32 %26, i32* %4
%27 = getelementptr inbounds %struct.cdrom_tocentry, %struct.cdrom_tocentry* %7, i64 0, i32 2, i32 0, i32 2
%28 = load i32, i32* %27
store i32 %28, i32* %5
br label %29
29: ; preds = %18, %16
%30 = phi i32 [ -1, %16 ], [ 0, %18 ]
ret i32 %30
}