#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_CUR;
scalar_t__ fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int const, int /*<<< orphan*/);
int file_input_func(void *user_data, unsigned char *buffer, const int count) {
  FILE *fp = (FILE *)user_data;
  if (buffer && count > 0) {
    return (int)fread(buffer, 1, (size_t)count, fp);
  } else if (fseek(fp, count, SEEK_CUR) == 0) {
    return count;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<file_input_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     116e <file_input_func+0x4e>
cmpl   $0x0,-0x1c(%rbp)
jle    116e <file_input_func+0x4e>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x4(%rbp)
jmp    119f <file_input_func+0x7f>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
call   1040 <fseek@plt>
cmp    $0x0,%rax
jne    1198 <file_input_func+0x78>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    119f <file_input_func+0x7f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_input_func>:
push   %rbx
mov    %edx,%ebx
mov    %rdi,%rcx
test   %rsi,%rsi
je     1140 <file_input_func+0x20>
test   %ebx,%ebx
jle    1140 <file_input_func+0x20>
mov    %ebx,%edx
mov    %rsi,%rdi
mov    $0x1,%esi
call   1030 <fread@plt>
pop    %rbx
ret
mov    0x2ea1(%rip),%rax
mov    (%rax),%edx
mov    %rcx,%rdi
mov    %ebx,%esi
call   1040 <fseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
cmove  %ebx,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @file_input_func(i8* nocapture %0, i8* %1, i32 %2) {
%4 = bitcast i8* %0 to i32*
%5 = icmp ne i8* %1, null
%6 = icmp sgt i32 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = zext i32 %2 to i64
%10 = tail call i64 @fread(i8* %1, i32 1, i64 %9, i32* %4)
%11 = trunc i64 %10 to i32
br label %17
12: ; preds = %3
%13 = load i32, i32* @SEEK_CUR
%14 = tail call i64 @fseek(i32* %4, i32 %2, i32 %13)
%15 = icmp eq i64 %14, 0
%16 = select i1 %15, i32 %2, i32 0
br label %17
17: ; preds = %12, %8
%18 = phi i32 [ %11, %8 ], [ %16, %12 ]
ret i32 %18
}