#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_tochdr {
  int cdth_trk0;
  int cdth_trk1;
};

/* Variables and functions */
int /*<<< orphan*/ CDROMREADTOCHDR;
int ioctl(int, int /*<<< orphan*/, struct cdrom_tochdr *);
int /*<<< orphan*/ perror(char *);
int read_cdrom_toc_header(int fd, int *first_track, int *last_track) {
  struct cdrom_tochdr tochdr;
  if (ioctl(fd, CDROMREADTOCHDR, &tochdr) == -1) {
    perror("CDROMREADTOCHDR");
    return -1;
  }
  *first_track = tochdr.cdth_trk0;
  *last_track = tochdr.cdth_trk1;
  return 0;
}


x86 assembly (clang, -O0):
<read_cdrom_toc_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1169 <read_cdrom_toc_header+0x49>
lea    0xea8(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1182 <read_cdrom_toc_header+0x62>
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_cdrom_toc_header>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    0x2eaf(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
call   1030 <ioctl@plt>
cmp    $0xffffffff,%eax
je     1156 <read_cdrom_toc_header+0x36>
mov    (%rsp),%eax
mov    %eax,(%rbx)
mov    0x4(%rsp),%eax
mov    %eax,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xea3(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    114e <read_cdrom_toc_header+0x2e>

LLVM IR (-O0):
%struct.cdrom_tochdr = type { i32, i32 }
@CDROMREADTOCHDR = global i32 0
@.str = [16 x i8] c"CDROMREADTOCHDR\00"
define i32 @read_cdrom_toc_header(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca %struct.cdrom_tochdr
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%9 = load i32, i32* %5
%10 = load i32, i32* @CDROMREADTOCHDR
%11 = call i32 @ioctl(i32 %9, i32 %10, %struct.cdrom_tochdr* %8)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %22
15: ; preds = %3
%16 = getelementptr inbounds %struct.cdrom_tochdr, %struct.cdrom_tochdr* %8, i32 0, i32 0
%17 = load i32, i32* %16
%18 = load i32*, i32** %6
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.cdrom_tochdr, %struct.cdrom_tochdr* %8, i32 0, i32 1
%20 = load i32, i32* %19
%21 = load i32*, i32** %7
store i32 %20, i32* %21
store i32 0, i32* %4
br label %22
22: ; preds = %15, %13
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.cdrom_tochdr = type { i32, i32 }
@CDROMREADTOCHDR = global i32 0
@.str = [16 x i8] c"CDROMREADTOCHDR\00"
define i32 @read_cdrom_toc_header(i32 %0, i32* nocapture writeonly %1, i32* nocapture writeonly %2) {
%4 = alloca %struct.cdrom_tochdr
%5 = bitcast %struct.cdrom_tochdr* %4 to i8*
%6 = load i32, i32* @CDROMREADTOCHDR
%7 = call i32 @ioctl(i32 %0, i32 %6, %struct.cdrom_tochdr* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
11: ; preds = %3
%12 = getelementptr inbounds %struct.cdrom_tochdr, %struct.cdrom_tochdr* %4, i64 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %1
%14 = getelementptr inbounds %struct.cdrom_tochdr, %struct.cdrom_tochdr* %4, i64 0, i32 1
%15 = load i32, i32* %14
store i32 %15, i32* %2
br label %16
16: ; preds = %11, %9
%17 = phi i32 [ -1, %9 ], [ 0, %11 ]
ret i32 %17
}