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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int getDiskSize(int);
int lseek(int, int, int /*<<< orphan*/);
int read(int, void *, int);
int readBlock(int disk, int bNum, void *block) {
  int diskSize = -1;
  if (disk < 0 || bNum < 0 || block == NULL) {
    return -1;
  }
  if ((diskSize = getDiskSize(disk)) == -1) {
    return -1;
  }
  if (((bNum * 256) + 256) > diskSize) {
    return -1;
  }
  if (lseek(disk, bNum * 256, SEEK_SET) != (bNum * 256)) {
    return -1;
  }
  if (read(disk, block, 256) == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<readBlock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     1168 <readBlock+0x38>
cmpl   $0x0,-0xc(%rbp)
jl     1168 <readBlock+0x38>
cmpq   $0x0,-0x18(%rbp)
jne    1174 <readBlock+0x44>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <readBlock+0xe2>
mov    -0x8(%rbp),%edi
call   1050 <getDiskSize@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1194 <readBlock+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <readBlock+0xe2>
mov    -0xc(%rbp),%eax
shl    $0x8,%eax
add    $0x100,%eax
cmp    -0x1c(%rbp),%eax
jle    11b4 <readBlock+0x84>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <readBlock+0xe2>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
shl    $0x8,%esi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
mov    -0xc(%rbp),%ecx
shl    $0x8,%ecx
cmp    %ecx,%eax
je     11e5 <readBlock+0xb5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <readBlock+0xe2>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
jne    120b <readBlock+0xdb>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <readBlock+0xe2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBlock>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%eax
or     %edi,%eax
mov    $0xffffffff,%r15d
js     1198 <readBlock+0x68>
mov    %rdx,%r14
test   %rdx,%rdx
je     1198 <readBlock+0x68>
mov    %esi,%ebx
mov    %edi,%ebp
call   1050 <getDiskSize@plt>
cmp    $0xffffffff,%eax
je     1198 <readBlock+0x68>
shl    $0x8,%ebx
lea    0x100(%rbx),%ecx
cmp    %eax,%ecx
jg     1198 <readBlock+0x68>
mov    0x2e73(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %ebx,%esi
call   1030 <lseek@plt>
cmp    %ebx,%eax
jne    1198 <readBlock+0x68>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x100,%edx
call   1040 <read@plt>
xor    %r15d,%r15d
cmp    $0xffffffff,%eax
sete   %r15b
neg    %r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @readBlock(i32 %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 -1, i32* %8
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %3
store i32 -1, i32* %4
br label %47
18: ; preds = %14
%19 = load i32, i32* %5
%20 = call i32 @getDiskSize(i32 %19)
store i32 %20, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %4
br label %47
23: ; preds = %18
%24 = load i32, i32* %6
%25 = mul nsw i32 %24, 256
%26 = add nsw i32 %25, 256
%27 = load i32, i32* %8
%28 = icmp sgt i32 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 -1, i32* %4
br label %47
30: ; preds = %23
%31 = load i32, i32* %5
%32 = load i32, i32* %6
%33 = mul nsw i32 %32, 256
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @lseek(i32 %31, i32 %33, i32 %34)
%36 = load i32, i32* %6
%37 = mul nsw i32 %36, 256
%38 = icmp ne i32 %35, %37
br i1 %38, label %39, label %40
39: ; preds = %30
store i32 -1, i32* %4
br label %47
40: ; preds = %30
%41 = load i32, i32* %5
%42 = load i8*, i8** %7
%43 = call i32 @read(i32 %41, i8* %42, i32 256)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 -1, i32* %4
br label %47
46: ; preds = %40
store i32 0, i32* %4
br label %47
47: ; preds = %46, %45, %39, %29, %22, %17
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @readBlock(i32 %0, i32 %1, i8* %2) {
%4 = or i32 %1, %0
%5 = icmp slt i32 %4, 0
%6 = icmp eq i8* %2, null
%7 = or i1 %5, %6
br i1 %7, label %23, label %8
8: ; preds = %3
%9 = tail call i32 @getDiskSize(i32 %0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %23, label %11
11: ; preds = %8
%12 = shl nsw i32 %1, 8
%13 = add nsw i32 %12, 256
%14 = icmp sgt i32 %13, %9
br i1 %14, label %23, label %15
15: ; preds = %11
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @lseek(i32 %0, i32 %12, i32 %16)
%18 = icmp eq i32 %17, %12
br i1 %18, label %19, label %23
19: ; preds = %15
%20 = tail call i32 @read(i32 %0, i8* %2, i32 256)
%21 = icmp eq i32 %20, -1
%22 = sext i1 %21 to i32
br label %23
23: ; preds = %19, %15, %11, %8, %3
%24 = phi i32 [ -1, %3 ], [ -1, %8 ], [ -1, %11 ], [ -1, %15 ], [ %22, %19 ]
ret i32 %24
}