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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fread(void *, int, size_t, int /*<<< orphan*/ *);
ssize_t response_callback(void *cls, void *buffer, size_t max, bool *more) {
  FILE *fd = (FILE *)cls;
  int ret = fread(buffer, 1, max, fd);
  *more = feof(fd) == 0;
  if (!(*more))
    fclose(fd);
  return ret;
}


x86 assembly (clang, -O0):
<response_callback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0x0,(%rax)
jne    119a <response_callback+0x6a>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<response_callback>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <feof@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
mov    %ecx,(%r14)
je     1169 <response_callback+0x39>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @response_callback(i8* nocapture %0, i8* nocapture %1, i64 %2, i32* nocapture writeonly %3) {
%5 = bitcast i8* %0 to i32*
%6 = tail call i32 @fread(i8* %1, i32 1, i64 %2, i32* %5)
%7 = tail call i64 @feof(i32* %5)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
store i32 %9, i32* %3
br i1 %8, label %12, label %10
10: ; preds = %4
%11 = tail call i32 @fclose(i32* %5)
br label %12
12: ; preds = %10, %4
ret i32 %6
}