#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 */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
void trd_get_data(FILE *file, char *buf, int trk, int sec, int len, int dt) {
  if ((dt == 0x18) || (dt == 0x19)) {
    fseek(file, ((trk << 5) | (sec & 0x0f)) << 8, SEEK_SET);
    char *ptr = buf;
    while (len > 0) {
      fread(ptr, 0x100, 1, file);
      if ((ftell(file) & 0xfff) == 0) {
        fseek(file, 0x1000, SEEK_CUR);
      }
      ptr += 0x100;
      len--;
    }
  } else {
    fseek(file, ((trk << 4) | (sec & 0x0f)) << 8, SEEK_SET);
    fread(buf, len << 8, 1, file);
  }
}


x86 assembly (clang, -O0):
<trd_get_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    %r9d,-0x20(%rbp)
cmpl   $0x18,-0x20(%rbp)
je     1162 <trd_get_data+0x32>
cmpl   $0x19,-0x20(%rbp)
jne    11fd <trd_get_data+0xcd>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x5,%esi
mov    -0x18(%rbp),%eax
and    $0xf,%eax
or     %eax,%esi
shl    $0x8,%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11f8 <trd_get_data+0xc8>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x8(%rbp),%rdi
call   1040 <ftell@plt>
and    $0xfff,%eax
cmp    $0x0,%eax
jne    11dc <trd_get_data+0xac>
mov    -0x8(%rbp),%rdi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
mov    $0x1000,%esi
call   1050 <fseek@plt>
mov    -0x28(%rbp),%rax
add    $0x100,%rax
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    118d <trd_get_data+0x5d>
jmp    1238 <trd_get_data+0x108>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
shl    $0x4,%esi
mov    -0x18(%rbp),%eax
and    $0xf,%eax
or     %eax,%esi
shl    $0x8,%esi
mov    0x2dbf(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
shl    $0x8,%esi
mov    -0x8(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trd_get_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
and    $0xfffffffe,%r9d
cmp    $0x18,%r9d
jne    11c5 <trd_get_data+0x95>
shl    $0xd,%edx
and    $0xf,%ecx
shl    $0x8,%ecx
or     %edx,%ecx
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ecx,%esi
call   1050 <fseek@plt>
test   %ebp,%ebp
jle    1202 <trd_get_data+0xd2>
add    $0x1,%ebp
mov    0x2e6e(%rip),%r15
jmp    118f <trd_get_data+0x5f>
nopl   0x0(%rax)
add    $0x100,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    1202 <trd_get_data+0xd2>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %r14,%rdi
call   1040 <ftell@plt>
test   $0xfff,%eax
jne    1180 <trd_get_data+0x50>
mov    (%r15),%edx
mov    %r14,%rdi
mov    $0x1000,%esi
call   1050 <fseek@plt>
jmp    1180 <trd_get_data+0x50>
shl    $0xc,%edx
and    $0xf,%ecx
shl    $0x8,%ecx
or     %edx,%ecx
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ecx,%esi
call   1050 <fseek@plt>
shl    $0x8,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fread@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define void @trd_get_data(i32* %0, i8* %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
%14 = load i32, i32* %12
%15 = icmp eq i32 %14, 24
br i1 %15, label %19, label %16
16: ; preds = %6
%17 = load i32, i32* %12
%18 = icmp eq i32 %17, 25
br i1 %18, label %19, label %51
19: ; preds = %16, %6
%20 = load i32*, i32** %7
%21 = load i32, i32* %9
%22 = shl i32 %21, 5
%23 = load i32, i32* %10
%24 = and i32 %23, 15
%25 = or i32 %22, %24
%26 = shl i32 %25, 8
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %20, i32 %26, i32 %27)
%29 = load i8*, i8** %8
store i8* %29, i8** %13
br label %30
30: ; preds = %45, %19
%31 = load i32, i32* %11
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %50
33: ; preds = %30
%34 = load i8*, i8** %13
%35 = load i32*, i32** %7
%36 = call i32 @fread(i8* %34, i32 256, i32 1, i32* %35)
%37 = load i32*, i32** %7
%38 = call i32 @ftell(i32* %37)
%39 = and i32 %38, 4095
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %33
%42 = load i32*, i32** %7
%43 = load i32, i32* @SEEK_CUR
%44 = call i32 @fseek(i32* %42, i32 4096, i32 %43)
br label %45
45: ; preds = %41, %33
%46 = load i8*, i8** %13
%47 = getelementptr inbounds i8, i8* %46, i64 256
store i8* %47, i8** %13
%48 = load i32, i32* %11
%49 = add nsw i32 %48, -1
store i32 %49, i32* %11
br label %30
50: ; preds = %30
br label %66
51: ; preds = %16
%52 = load i32*, i32** %7
%53 = load i32, i32* %9
%54 = shl i32 %53, 4
%55 = load i32, i32* %10
%56 = and i32 %55, 15
%57 = or i32 %54, %56
%58 = shl i32 %57, 8
%59 = load i32, i32* @SEEK_SET
%60 = call i32 @fseek(i32* %52, i32 %58, i32 %59)
%61 = load i8*, i8** %8
%62 = load i32, i32* %11
%63 = shl i32 %62, 8
%64 = load i32*, i32** %7
%65 = call i32 @fread(i8* %61, i32 %63, i32 1, i32* %64)
br label %66
66: ; preds = %51, %50
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
define void @trd_get_data(i32* nocapture %0, i8* nocapture %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = and i32 %5, -2
%8 = icmp eq i32 %7, 24
br i1 %8, label %9, label %31
9: ; preds = %6
%10 = shl i32 %2, 13
%11 = shl i32 %3, 8
%12 = and i32 %11, 3840
%13 = or i32 %12, %10
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %0, i32 %13, i32 %14)
%16 = icmp sgt i32 %4, 0
br i1 %16, label %17, label %40
17: ; preds = %9, %27
%18 = phi i8* [ %28, %27 ], [ %1, %9 ]
%19 = phi i32 [ %29, %27 ], [ %4, %9 ]
%20 = tail call i32 @fread(i8* %18, i32 256, i32 1, i32* %0)
%21 = tail call i32 @ftell(i32* %0)
%22 = and i32 %21, 4095
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %17
%25 = load i32, i32* @SEEK_CUR
%26 = tail call i32 @fseek(i32* %0, i32 4096, i32 %25)
br label %27
27: ; preds = %24, %17
%28 = getelementptr inbounds i8, i8* %18, i64 256
%29 = add nsw i32 %19, -1
%30 = icmp sgt i32 %19, 1
br i1 %30, label %17, label %40
31: ; preds = %6
%32 = shl i32 %2, 12
%33 = shl i32 %3, 8
%34 = and i32 %33, 3840
%35 = or i32 %34, %32
%36 = load i32, i32* @SEEK_SET
%37 = tail call i32 @fseek(i32* %0, i32 %35, i32 %36)
%38 = shl i32 %4, 8
%39 = tail call i32 @fread(i8* %1, i32 %38, i32 1, i32* %0)
br label %40
40: ; preds = %27, %9, %31
ret void
}