#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*/ FILE;

/* Variables and functions */
scalar_t__ bcmp(char *, char *, int);
int /*<<< orphan*/ bzero(char *, size_t);
int /*<<< orphan*/ free(char *);
char *read_buf(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ rtrim(char *, size_t);
int /*<<< orphan*/ strlcpy(char *, char *, size_t);
int fstyp_cd9660(FILE *fp, char *label, size_t size) {
  char *sector, *volume;
  sector = read_buf(fp, 0x8000, 512);
  if (sector == NULL)
    return (1);
  if (bcmp(sector,
           "\x01"
           "CD001"
           "\x01\x00",
           sizeof("\x01"
                  "CD001"
                  "\x01\x00") -
               1) != 0) {
    free(sector);
    return (1);
  }
  volume = sector + 0x28;
  bzero(label, size);
  strlcpy(label, volume, (((size) < (32)) ? (size) : (32)));
  free(sector);
  rtrim(label, size);
  return (0);
}


x86 assembly (clang, -O0):
<fstyp_cd9660>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x8000,%esi
mov    $0x200,%edx
call   1040 <read_buf@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1192 <fstyp_cd9660+0x42>
movl   $0x1,-0x4(%rbp)
jmp    1248 <fstyp_cd9660+0xf8>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movabs $0x1313030444301,%rcx
sub    %rcx,%rax
setne  %al
movzbl %al,%eax
cmp    $0x0,%rax
je     11cb <fstyp_cd9660+0x7b>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    1248 <fstyp_cd9660+0xf8>
mov    -0x28(%rbp),%rax
add    $0x28,%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <bzero@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpq   $0x20,-0x20(%rbp)
jae    120c <fstyp_cd9660+0xbc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    121a <fstyp_cd9660+0xca>
mov    $0x20,%eax
mov    %rax,-0x48(%rbp)
jmp    121a <fstyp_cd9660+0xca>
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rdx
call   1060 <strlcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <rtrim@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fstyp_cd9660>:
push   %rax
mov    $0x8000,%esi
mov    $0x200,%edx
call   1040 <read_buf@plt>
test   %rax,%rax
je     113d <fstyp_cd9660+0x1d>
mov    %rax,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"\01CD001\01\00\00"
define i32 @fstyp_cd9660(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
%10 = load i32*, i32** %5
%11 = call i8* @read_buf(i32* %10, i32 32768, i32 512)
store i8* %11, i8** %8
%12 = load i8*, i8** %8
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %15
14: ; preds = %3
store i32 1, i32* %4
br label %43
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = call i64 @bcmp(i8* %16, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i8*, i8** %8
%21 = call i32 @free(i8* %20)
store i32 1, i32* %4
br label %43
22: ; preds = %15
%23 = load i8*, i8** %8
%24 = getelementptr inbounds i8, i8* %23, i64 40
store i8* %24, i8** %9
%25 = load i8*, i8** %6
%26 = load i64, i64* %7
%27 = call i32 @bzero(i8* %25, i64 %26)
%28 = load i8*, i8** %6
%29 = load i8*, i8** %9
%30 = load i64, i64* %7
%31 = icmp ult i64 %30, 32
br i1 %31, label %32, label %34
32: ; preds = %22
%33 = load i64, i64* %7
br label %35
34: ; preds = %22
br label %35
35: ; preds = %34, %32
%36 = phi i64 [ %33, %32 ], [ 32, %34 ]
%37 = call i32 @strlcpy(i8* %28, i8* %29, i64 %36)
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
%40 = load i8*, i8** %6
%41 = load i64, i64* %7
%42 = call i32 @rtrim(i8* %40, i64 %41)
store i32 0, i32* %4
br label %43
43: ; preds = %35, %19, %14
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
@.str = [9 x i8] c"\01CD001\01\00\00"
define i32 @fstyp_cd9660(i32* %0, i8* %1, i64 %2) {
%4 = tail call i8* @read_buf(i32* %0, i32 32768, i32 512)
%5 = icmp eq i8* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = tail call i64 @bcmp(i8* dereferenceable(8) %4, i8* dereferenceable(8) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 8)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call i32 @free(i8* %4)
br label %19
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %4, i64 40
%13 = tail call i32 @bzero(i8* %1, i64 %2)
%14 = icmp ult i64 %2, 32
%15 = select i1 %14, i64 %2, i64 32
%16 = tail call i32 @strlcpy(i8* %1, i8* %12, i64 %15)
%17 = tail call i32 @free(i8* %4)
%18 = tail call i32 @rtrim(i8* %1, i64 %2)
br label %19
19: ; preds = %3, %11, %9
%20 = phi i32 [ 1, %9 ], [ 0, %11 ], [ 1, %3 ]
ret i32 %20
}