#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 long long off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int lseek(int, long long, int /*<<< orphan*/);
int /*<<< orphan*/ progressbar_error(char *, ...);
int read_bytes(int, void *, int);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int read_filesystem(int fd, long long byte, int bytes, void *buff) {
  off_t off = byte;
  ;
  if (lseek(fd, off, SEEK_SET) == -1) {
    do {
      progressbar_error(
          "read_filesystem: Lseek on destination failed because %s, "
          "offset=0x%llx\n",
          strerror(errno), off);
    } while (0);
    return 0;
  } else if (read_bytes(fd, buff, bytes) < bytes) {
    do {
      progressbar_error("Read on destination failed\n");
    } while (0);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_filesystem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11af <read_filesystem+0x6f>
jmp    1181 <read_filesystem+0x41>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%esi
mov    -0x28(%rbp),%rdx
lea    0xe64(%rip),%rdi
mov    $0x0,%al
call   1050 <progressbar_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <read_filesystem+0xb2>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <read_bytes@plt>
cmp    -0x14(%rbp),%eax
jge    11e6 <read_filesystem+0xa6>
jmp    11cc <read_filesystem+0x8c>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1050 <progressbar_error@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f2 <read_filesystem+0xb2>
jmp    11eb <read_filesystem+0xab>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_filesystem>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %edx,%ebp
mov    %rsi,%r14
mov    %edi,%ebx
mov    0x2e80(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     118b <read_filesystem+0x4b>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <read_bytes@plt>
mov    $0x1,%ebx
cmp    %ebp,%eax
jge    11ae <read_filesystem+0x6e>
lea    0xec8(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <progressbar_error@plt>
jmp    11ae <read_filesystem+0x6e>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe60(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <progressbar_error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [72 x i8] c"read_filesystem: Lseek on destination failed because %s, offset=0x%llx\0A\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"Read on destination failed\0A\00"
define i32 @read_filesystem(i32 %0, i64 %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 %0, i32* %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i64, i64* %7
store i64 %11, i64* %10
%12 = load i32, i32* %6
%13 = load i64, i64* %10
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %12, i64 %13, i32 %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %24
17: ; preds = %4
br label %18
18: ; preds = %17
%19 = load i32, i32* @errno
%20 = call i32 @strerror(i32 %19)
%21 = load i64, i64* %10
%22 = call i32 (i8*, ...) @progressbar_error(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %20, i64 %21)
br label %23
23: ; preds = %18
store i32 0, i32* %5
br label %37
24: ; preds = %4
%25 = load i32, i32* %6
%26 = load i8*, i8** %9
%27 = load i32, i32* %8
%28 = call i32 @read_bytes(i32 %25, i8* %26, i32 %27)
%29 = load i32, i32* %8
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %35
31: ; preds = %24
br label %32
32: ; preds = %31
%33 = call i32 (i8*, ...) @progressbar_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32
store i32 0, i32* %5
br label %37
35: ; preds = %24
br label %36
36: ; preds = %35
store i32 1, i32* %5
br label %37
37: ; preds = %36, %34, %23
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [72 x i8] c"read_filesystem: Lseek on destination failed because %s, offset=0x%llx\0A\00"
@errno = global i32 0
@.str.1 = [28 x i8] c"Read on destination failed\0A\00"
define i32 @read_filesystem(i32 %0, i64 %1, i32 %2, i8* %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @lseek(i32 %0, i64 %1, i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = load i32, i32* @errno
%10 = tail call i32 @strerror(i32 %9)
%11 = tail call i32 (i8*, ...) @progressbar_error(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %10, i64 %1)
br label %17
12: ; preds = %4
%13 = tail call i32 @read_bytes(i32 %0, i8* %3, i32 %2)
%14 = icmp slt i32 %13, %2
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 (i8*, ...) @progressbar_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %12, %15, %8
%18 = phi i32 [ 0, %8 ], [ 0, %15 ], [ 1, %12 ]
ret i32 %18
}