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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ libewf_fatal_print(char *, ...);
int /*<<< orphan*/ libewf_verbose_print(char *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int read(int, int /*<<< orphan*/ *, size_t);
ssize_t ewf_sectors_chunk_read(uint8_t *sectors_chunk, int file_descriptor,
                               off_t offset, size_t size) {
  ssize_t count;
  if (sectors_chunk == NULL) {
    libewf_verbose_print("ewf_sectors_chunk_read: invalid sectors_chunk.\n");
    return (-1);
  }
  if (lseek(file_descriptor, offset, SEEK_SET) < 0) {
    libewf_fatal_print("ewf_sectors_chunk_read: cannot find offset: %ld.\n",
                       offset);
  }
  count = read(file_descriptor, sectors_chunk, size);
  if (count < size) {
    libewf_fatal_print(
        "ewf_sectors_chunk_read: unable to read sectors_chunk.\n");
  }
  return (count);
}


x86 assembly (clang, -O0):
<ewf_sectors_chunk_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1179 <ewf_sectors_chunk_read+0x39>
lea    0xe98(%rip),%rdi
call   1030 <libewf_verbose_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <ewf_sectors_chunk_read+0x9d>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2e5a(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    11a8 <ewf_sectors_chunk_read+0x68>
mov    -0x18(%rbp),%esi
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <libewf_fatal_print@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <read@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    11d7 <ewf_sectors_chunk_read+0x97>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1040 <libewf_fatal_print@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ewf_sectors_chunk_read>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a6 <ewf_sectors_chunk_read+0x66>
mov    %rcx,%r14
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    %esi,%edi
mov    %r15d,%esi
call   1050 <lseek@plt>
test   %rax,%rax
jns    1180 <ewf_sectors_chunk_read+0x40>
lea    0xeba(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <libewf_fatal_print@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1060 <read@plt>
mov    %eax,%ebx
cltq
cmp    %r14,%rax
jae    11b7 <ewf_sectors_chunk_read+0x77>
lea    0xec5(%rip),%rdi
xor    %eax,%eax
call   1040 <libewf_fatal_print@plt>
jmp    11b7 <ewf_sectors_chunk_read+0x77>
lea    0xe53(%rip),%rdi
call   1030 <libewf_verbose_print@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [48 x i8] c"ewf_sectors_chunk_read: invalid sectors_chunk.\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [50 x i8] c"ewf_sectors_chunk_read: cannot find offset: %ld.\0A\00"
@.str.2 = [55 x i8] c"ewf_sectors_chunk_read: unable to read sectors_chunk.\0A\00"
define i32 @ewf_sectors_chunk_read(i32* %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%11 = load i32*, i32** %6
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %4
%14 = call i32 @libewf_verbose_print(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %5
br label %37
15: ; preds = %4
%16 = load i32, i32* %7
%17 = load i32, i32* %8
%18 = load i32, i32* @SEEK_SET
%19 = call i64 @lseek(i32 %16, i32 %17, i32 %18)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = load i32, i32* %8
%23 = call i32 (i8*, ...) @libewf_fatal_print(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %21, %15
%25 = load i32, i32* %7
%26 = load i32*, i32** %6
%27 = load i64, i64* %9
%28 = call i32 @read(i32 %25, i32* %26, i64 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = sext i32 %29 to i64
%31 = load i64, i64* %9
%32 = icmp ult i64 %30, %31
br i1 %32, label %33, label %35
33: ; preds = %24
%34 = call i32 (i8*, ...) @libewf_fatal_print(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %24
%36 = load i32, i32* %10
store i32 %36, i32* %5
br label %37
37: ; preds = %35, %13
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@.str = [48 x i8] c"ewf_sectors_chunk_read: invalid sectors_chunk.\0A\00"
@SEEK_SET = global i32 0
@.str.1 = [50 x i8] c"ewf_sectors_chunk_read: cannot find offset: %ld.\0A\00"
@.str.2 = [55 x i8] c"ewf_sectors_chunk_read: unable to read sectors_chunk.\0A\00"
define i32 @ewf_sectors_chunk_read(i32* %0, i32 %1, i32 %2, i64 %3) {
%5 = icmp eq i32* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 @libewf_verbose_print(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %4
%9 = load i32, i32* @SEEK_SET
%10 = tail call i64 @lseek(i32 %1, i32 %2, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 (i8*, ...) @libewf_fatal_print(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %2)
br label %14
14: ; preds = %12, %8
%15 = tail call i32 @read(i32 %1, i32* %0, i64 %3)
%16 = sext i32 %15 to i64
%17 = icmp ult i64 %16, %3
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = tail call i32 (i8*, ...) @libewf_fatal_print(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %14, %18, %6
%21 = phi i32 [ -1, %6 ], [ %15, %18 ], [ %15, %14 ]
ret i32 %21
}