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

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int readBytes(unsigned char *ptr, size_t size, FILE *stream) {
  size_t bytesread;
  if (ptr == NULL) {
    fseeko(stream, (off_t)size, SEEK_CUR);
    return 0;
  }
  bytesread = fread(ptr, 1, size, stream);
  if (bytesread < size)
    return 6;
  return 0;
}


x86 assembly (clang, -O0):
<readBytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <readBytes+0x43>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %eax,%esi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
call   1040 <fseeko@plt>
movl   $0x0,-0x4(%rbp)
jmp    119e <readBytes+0x7e>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1197 <readBytes+0x77>
movl   $0x6,-0x4(%rbp)
jmp    119e <readBytes+0x7e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readBytes>:
push   %rbx
mov    %rdx,%rcx
mov    %rsi,%rbx
test   %rdi,%rdi
je     1148 <readBytes+0x28>
mov    $0x1,%esi
mov    %rbx,%rdx
call   1030 <fread@plt>
xor    %ecx,%ecx
cmp    %rbx,%rax
mov    $0x6,%eax
cmovae %ecx,%eax
pop    %rbx
ret
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
mov    %rcx,%rdi
mov    %ebx,%esi
call   1040 <fseeko@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @readBytes(i8* %0, i64 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load i32*, i32** %7
%13 = load i64, i64* %6
%14 = trunc i64 %13 to i32
%15 = load i32, i32* @SEEK_CUR
%16 = call i32 @fseeko(i32* %12, i32 %14, i32 %15)
store i32 0, i32* %4
br label %27
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = load i32*, i32** %7
%21 = call i64 @fread(i8* %18, i32 1, i64 %19, i32* %20)
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = load i64, i64* %6
%24 = icmp ult i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %17
store i32 6, i32* %4
br label %27
26: ; preds = %17
store i32 0, i32* %4
br label %27
27: ; preds = %26, %25, %11
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @readBytes(i8* %0, i64 %1, i32* nocapture %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %9
5: ; preds = %3
%6 = trunc i64 %1 to i32
%7 = load i32, i32* @SEEK_CUR
%8 = tail call i32 @fseeko(i32* %2, i32 %6, i32 %7)
br label %13
9: ; preds = %3
%10 = tail call i64 @fread(i8* %0, i32 1, i64 %1, i32* %2)
%11 = icmp ult i64 %10, %1
%12 = select i1 %11, i32 6, i32 0
br label %13
13: ; preds = %9, %5
%14 = phi i32 [ 0, %5 ], [ %12, %9 ]
ret i32 %14
}