#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_SET;
int fread(void *, int, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *lwwire_fetch_drive_fp(int);
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int lwwire_fetch_sector(int dn, int lsn, void *buf) {
  FILE *fp;
  int rc;
  fp = lwwire_fetch_drive_fp(dn);
  if (!fp)
    return 0xF6;
  if (fseek(fp, lsn * 256, SEEK_SET) < 0)
    return 0xF4;
  rc = fread(buf, 1, 256, fp);
  if (rc < 256) {
    memset(buf + rc, 0, 256 - rc);
  }
  return 0;
}


x86 assembly (clang, -O0):
<lwwire_fetch_sector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <lwwire_fetch_drive_fp@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1175 <lwwire_fetch_sector+0x35>
movl   $0xf6,-0x4(%rbp)
jmp    11eb <lwwire_fetch_sector+0xab>
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
shl    $0x8,%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
cmp    $0x0,%rax
jge    11a3 <lwwire_fetch_sector+0x63>
movl   $0xf4,-0x4(%rbp)
jmp    11eb <lwwire_fetch_sector+0xab>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x100,-0x24(%rbp)
jge    11e4 <lwwire_fetch_sector+0xa4>
mov    -0x18(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    $0x100,%edx
sub    -0x24(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lwwire_fetch_sector>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
call   1060 <lwwire_fetch_drive_fp@plt>
test   %rax,%rax
je     11ac <lwwire_fetch_sector+0x6c>
mov    %rax,%rbx
shl    $0x8,%ebp
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <fseek@plt>
test   %rax,%rax
js     11b3 <lwwire_fetch_sector+0x73>
mov    $0x100,%ebp
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %ebx,%ebx
cmp    $0xff,%eax
jg     11b8 <lwwire_fetch_sector+0x78>
movslq %eax,%rcx
add    %rcx,%r14
sub    %eax,%ebp
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
jmp    11b8 <lwwire_fetch_sector+0x78>
mov    $0xf6,%ebx
jmp    11b8 <lwwire_fetch_sector+0x78>
mov    $0xf4,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @lwwire_fetch_sector(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i32, i32* %5
%11 = call i32* @lwwire_fetch_drive_fp(i32 %10)
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 246, i32* %4
br label %38
15: ; preds = %3
%16 = load i32*, i32** %8
%17 = load i32, i32* %6
%18 = mul nsw i32 %17, 256
%19 = load i32, i32* @SEEK_SET
%20 = call i64 @fseek(i32* %16, i32 %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 244, i32* %4
br label %38
23: ; preds = %15
%24 = load i8*, i8** %7
%25 = load i32*, i32** %8
%26 = call i32 @fread(i8* %24, i32 1, i32 256, i32* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 256
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr i8, i8* %30, i64 %32
%34 = load i32, i32* %9
%35 = sub nsw i32 256, %34
%36 = call i32 @memset(i8* %33, i32 0, i32 %35)
br label %37
37: ; preds = %29, %23
store i32 0, i32* %4
br label %38
38: ; preds = %37, %22, %14
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @lwwire_fetch_sector(i32 %0, i32 %1, i8* %2) {
%4 = tail call i32* @lwwire_fetch_drive_fp(i32 %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = shl nsw i32 %1, 8
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @fseek(i32* %4, i32 %7, i32 %8)
%10 = icmp slt i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %6
%12 = tail call i32 @fread(i8* %2, i32 1, i32 256, i32* %4)
%13 = icmp slt i32 %12, 256
br i1 %13, label %14, label %19
14: ; preds = %11
%15 = sext i32 %12 to i64
%16 = getelementptr i8, i8* %2, i64 %15
%17 = sub nsw i32 256, %12
%18 = tail call i32 @memset(i8* %16, i32 0, i32 %17)
br label %19
19: ; preds = %11, %14, %6, %3
%20 = phi i32 [ 246, %3 ], [ 244, %6 ], [ 0, %14 ], [ 0, %11 ]
ret i32 %20
}