#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 uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int iso9660_dir(int /*<<< orphan*/ *, int, int, char *);
int iso9660_serial(const char *path, char *serial, uint32_t ssize,
                   uint32_t offset) {
  FILE *file;
  uint32_t dir_size;
  uint32_t dir_offset;
  uint8_t vds_type;
  int status = 1;
  if ((file = fopen(path, "rb")) == NULL)
    return 1;
  if (fseek(file, offset + ssize * 16, SEEK_CUR))
    goto cleanup;
  while (!feof(file) && !ferror(file)) {
    if (fread(&vds_type, 1, 1, file) != 1)
      goto cleanup;
    switch (vds_type) {
    case 0x01:
      if (fseek(file, 0x9E - 1, SEEK_CUR))
        goto cleanup;
      if (fread(&dir_offset, 4, 1, file) != 1)
        goto cleanup;
      if (fseek(file, 4, SEEK_CUR))
        goto cleanup;
      if (fread(&dir_size, 4, 1, file) != 1)
        goto cleanup;
      dir_offset *= ssize;
      if (fseek(file, offset + dir_offset, SEEK_SET))
        goto cleanup;
      status = iso9660_dir(file, dir_size, ssize, serial);
      goto cleanup;
    case 0xFF:
      goto cleanup;
    default:
      if (fseek(file, ssize - 1, SEEK_CUR))
        goto cleanup;
      break;
    }
  }
cleanup:
  fclose(file);
  return status;
}


x86 assembly (clang, -O0):
<iso9660_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x1,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11b7 <iso9660_serial+0x47>
movl   $0x1,-0x4(%rbp)
jmp    139a <iso9660_serial+0x22a>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
add    %eax,%esi
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     11e3 <iso9660_serial+0x73>
jmp    138b <iso9660_serial+0x21b>
jmp    11e8 <iso9660_serial+0x78>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x39(%rbp)
jne    1215 <iso9660_serial+0xa5>
mov    -0x28(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    1225 <iso9660_serial+0xb5>
jmp    1386 <iso9660_serial+0x216>
mov    -0x28(%rbp),%rcx
lea    -0x34(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1247 <iso9660_serial+0xd7>
jmp    138b <iso9660_serial+0x21b>
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x1,%eax
je     126e <iso9660_serial+0xfe>
jmp    125b <iso9660_serial+0xeb>
mov    -0x40(%rbp),%eax
sub    $0xff,%eax
je     1350 <iso9660_serial+0x1e0>
jmp    1355 <iso9660_serial+0x1e5>
mov    -0x28(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
mov    $0x9d,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     1294 <iso9660_serial+0x124>
jmp    138b <iso9660_serial+0x21b>
mov    -0x28(%rbp),%rcx
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     12b9 <iso9660_serial+0x149>
jmp    138b <iso9660_serial+0x21b>
mov    -0x28(%rbp),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     12df <iso9660_serial+0x16f>
jmp    138b <iso9660_serial+0x21b>
mov    -0x28(%rbp),%rcx
lea    -0x2c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1304 <iso9660_serial+0x194>
jmp    138b <iso9660_serial+0x21b>
mov    -0x1c(%rbp),%eax
imul   -0x30(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    -0x30(%rbp),%esi
mov    0x2cb9(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     1335 <iso9660_serial+0x1c5>
jmp    138b <iso9660_serial+0x21b>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1090 <iso9660_dir@plt>
mov    %eax,-0x38(%rbp)
jmp    138b <iso9660_serial+0x21b>
jmp    138b <iso9660_serial+0x21b>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
mov    0x2c82(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     137c <iso9660_serial+0x20c>
jmp    138b <iso9660_serial+0x21b>
jmp    1381 <iso9660_serial+0x211>
jmp    11e8 <iso9660_serial+0x78>
jmp    138b <iso9660_serial+0x21b>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iso9660_serial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %edx,%r15d
mov    %rsi,%r14
lea    0xe73(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11c9 <iso9660_serial+0x59>
mov    %rax,%rbx
mov    %r15d,%esi
shl    $0x4,%esi
add    %ebp,%esi
mov    0x2e3f(%rip),%r12
mov    (%r12),%edx
mov    %rax,%rdi
call   1070 <fseek@plt>
test   %rax,%rax
je     11df <iso9660_serial+0x6f>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11ce <iso9660_serial+0x5e>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,0x4(%rsp)
mov    %r14,0x10(%rsp)
lea    -0x1(%r15),%r13d
lea    0x8(%rsp),%r14
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11ba <iso9660_serial+0x4a>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %eax,%eax
jne    11ba <iso9660_serial+0x4a>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11bf <iso9660_serial+0x4f>
mov    0x8(%rsp),%eax
cmp    $0xff,%eax
je     11bf <iso9660_serial+0x4f>
cmp    $0x1,%eax
je     125b <iso9660_serial+0xeb>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    %r13d,%esi
call   1070 <fseek@plt>
test   %rax,%rax
je     1200 <iso9660_serial+0x90>
jmp    11bf <iso9660_serial+0x4f>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x9d,%esi
call   1070 <fseek@plt>
test   %rax,%rax
jne    11bf <iso9660_serial+0x4f>
mov    %rsp,%rdi
mov    $0x1,%ebp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11bf <iso9660_serial+0x4f>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1070 <fseek@plt>
test   %rax,%rax
jne    11bf <iso9660_serial+0x4f>
lea    0xc(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    11bf <iso9660_serial+0x4f>
mov    (%rsp),%esi
imul   %r15d,%esi
mov    %esi,(%rsp)
add    0x4(%rsp),%esi
mov    0x2cec(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
call   1070 <fseek@plt>
test   %rax,%rax
jne    11bf <iso9660_serial+0x4f>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r15d,%edx
mov    0x10(%rsp),%rcx
call   1090 <iso9660_dir@plt>
mov    %eax,%ebp
jmp    11bf <iso9660_serial+0x4f>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i32 @iso9660_serial(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 1, i32* %14
%15 = load i8*, i8** %6
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %10
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %4
store i32 1, i32* %5
br label %104
19: ; preds = %4
%20 = load i32*, i32** %10
%21 = load i32, i32* %9
%22 = load i32, i32* %8
%23 = mul nsw i32 %22, 16
%24 = add nsw i32 %21, %23
%25 = load i32, i32* @SEEK_CUR
%26 = call i64 @fseek(i32* %20, i32 %24, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %19
br label %100
29: ; preds = %19
br label %30
30: ; preds = %98, %29
%31 = load i32*, i32** %10
%32 = call i32 @feof(i32* %31)
%33 = icmp ne i32 %32, 0
br i1 %33, label %39, label %34
34: ; preds = %30
%35 = load i32*, i32** %10
%36 = call i32 @ferror(i32* %35)
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br label %39
39: ; preds = %34, %30
%40 = phi i1 [ false, %30 ], [ %38, %34 ]
br i1 %40, label %41, label %99
41: ; preds = %39
%42 = load i32*, i32** %10
%43 = call i32 @fread(i32* %13, i32 1, i32 1, i32* %42)
%44 = icmp ne i32 %43, 1
br i1 %44, label %45, label %46
45: ; preds = %41
br label %100
46: ; preds = %41
%47 = load i32, i32* %13
switch i32 %47, label %89 [
i32 1, label %48
i32 255, label %88
]
48: ; preds = %46
%49 = load i32*, i32** %10
%50 = load i32, i32* @SEEK_CUR
%51 = call i64 @fseek(i32* %49, i32 157, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
br label %100
54: ; preds = %48
%55 = load i32*, i32** %10
%56 = call i32 @fread(i32* %12, i32 4, i32 1, i32* %55)
%57 = icmp ne i32 %56, 1
br i1 %57, label %58, label %59
58: ; preds = %54
br label %100
59: ; preds = %54
%60 = load i32*, i32** %10
%61 = load i32, i32* @SEEK_CUR
%62 = call i64 @fseek(i32* %60, i32 4, i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %59
br label %100
65: ; preds = %59
%66 = load i32*, i32** %10
%67 = call i32 @fread(i32* %11, i32 4, i32 1, i32* %66)
%68 = icmp ne i32 %67, 1
br i1 %68, label %69, label %70
69: ; preds = %65
br label %100
70: ; preds = %65
%71 = load i32, i32* %8
%72 = load i32, i32* %12
%73 = mul nsw i32 %72, %71
store i32 %73, i32* %12
%74 = load i32*, i32** %10
%75 = load i32, i32* %9
%76 = load i32, i32* %12
%77 = add nsw i32 %75, %76
%78 = load i32, i32* @SEEK_SET
%79 = call i64 @fseek(i32* %74, i32 %77, i32 %78)
%80 = icmp ne i64 %79, 0
br i1 %80, label %81, label %82
81: ; preds = %70
br label %100
82: ; preds = %70
%83 = load i32*, i32** %10
%84 = load i32, i32* %11
%85 = load i32, i32* %8
%86 = load i8*, i8** %7
%87 = call i32 @iso9660_dir(i32* %83, i32 %84, i32 %85, i8* %86)
store i32 %87, i32* %14
br label %100
88: ; preds = %46
br label %100
89: ; preds = %46
%90 = load i32*, i32** %10
%91 = load i32, i32* %8
%92 = sub nsw i32 %91, 1
%93 = load i32, i32* @SEEK_CUR
%94 = call i64 @fseek(i32* %90, i32 %92, i32 %93)
%95 = icmp ne i64 %94, 0
br i1 %95, label %96, label %97
96: ; preds = %89
br label %100
97: ; preds = %89
br label %98
98: ; preds = %97
br label %30
99: ; preds = %39
br label %100
100: ; preds = %99, %96, %88, %82, %81, %69, %64, %58, %53, %45, %28
%101 = load i32*, i32** %10
%102 = call i32 @fclose(i32* %101)
%103 = load i32, i32* %14
store i32 %103, i32* %5
br label %104
104: ; preds = %100, %18
%105 = load i32, i32* %5
ret i32 %105
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_CUR = global i32 0
@SEEK_SET = global i32 0
define i32 @iso9660_serial(i8* nocapture %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i32* %5 to i8*
%9 = bitcast i32* %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %63, label %13
13: ; preds = %4
%14 = shl nsw i32 %2, 4
%15 = add nsw i32 %14, %3
%16 = load i32, i32* @SEEK_CUR
%17 = tail call i64 @fseek(i32* %11, i32 %15, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %60
19: ; preds = %13
%20 = add nsw i32 %2, -1
br label %21
21: ; preds = %19, %56
%22 = tail call i32 @feof(i32* %11)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %60
24: ; preds = %21
%25 = tail call i32 @ferror(i32* %11)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %60
27: ; preds = %24
%28 = call i32 @fread(i32* %7, i32 1, i32 1, i32* %11)
%29 = icmp eq i32 %28, 1
br i1 %29, label %30, label %60
30: ; preds = %27
%31 = load i32, i32* %7
switch i32 %31, label %56 [
i32 1, label %32
i32 255, label %60
]
32: ; preds = %30
%33 = load i32, i32* @SEEK_CUR
%34 = tail call i64 @fseek(i32* %11, i32 157, i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %60
36: ; preds = %32
%37 = call i32 @fread(i32* %6, i32 4, i32 1, i32* %11)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %60
39: ; preds = %36
%40 = load i32, i32* @SEEK_CUR
%41 = tail call i64 @fseek(i32* %11, i32 4, i32 %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %60
43: ; preds = %39
%44 = call i32 @fread(i32* %5, i32 4, i32 1, i32* %11)
%45 = icmp eq i32 %44, 1
br i1 %45, label %46, label %60
46: ; preds = %43
%47 = load i32, i32* %6
%48 = mul nsw i32 %47, %2
store i32 %48, i32* %6
%49 = add nsw i32 %48, %3
%50 = load i32, i32* @SEEK_SET
%51 = tail call i64 @fseek(i32* %11, i32 %49, i32 %50)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %46
%54 = load i32, i32* %5
%55 = tail call i32 @iso9660_dir(i32* %11, i32 %54, i32 %2, i8* %1)
br label %60
56: ; preds = %30
%57 = load i32, i32* @SEEK_CUR
%58 = tail call i64 @fseek(i32* %11, i32 %20, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %21, label %60
60: ; preds = %24, %21, %56, %30, %27, %46, %43, %39, %36, %32, %13, %53
%61 = phi i32 [ 1, %13 ], [ 1, %32 ], [ 1, %36 ], [ 1, %39 ], [ 1, %43 ], [ 1, %46 ], [ %55, %53 ], [ 1, %27 ], [ 1, %30 ], [ 1, %56 ], [ 1, %21 ], [ 1, %24 ]
%62 = tail call i32 @fclose(i32* %11)
br label %63
63: ; preds = %4, %60
%64 = phi i32 [ %61, %60 ], [ 1, %4 ]
ret i32 %64
}