#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*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, size_t, ...);
int main(int argc, char *argv[]) {
  char buf[1024] = {0};
  FILE *file = fopen("test_freadreturn.c", "r");
  if (file) {
    size_t ret = fread(buf, 1024, 1, file);
    printf("fread ret = %d, buf = \n{\n%s\n}\n", ret, buf);
    ret = fread(buf, 400, 1, file);
    printf("fread ret = %d\n", ret);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xe8d(%rip),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     120d <main+0xcd>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rcx
mov    $0x400,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rsi
lea    -0x410(%rbp),%rdx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rcx
mov    $0x190,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xea0(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11c6 <main+0x86>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x400,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
lea    0xe82(%rip),%rdi
mov    %rax,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    $0x190,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"test_freadreturn.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"fread ret = %d, buf = \0A{\0A%s\0A}\0A\00"
@.str.3 = [16 x i8] c"fread ret = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [1024 x i8]* %6 to i8*
%10 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %25
13: ; preds = %2
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%15 = load i32*, i32** %7
%16 = call i64 @fread(i8* %14, i32 1024, i32 1, i32* %15)
store i64 %16, i64* %8
%17 = load i64, i64* %8
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%19 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %17, i8* %18)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = load i32*, i32** %7
%22 = call i64 @fread(i8* %20, i32 400, i32 1, i32* %21)
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %23)
br label %25
25: ; preds = %13, %2
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"test_freadreturn.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"fread ret = %d, buf = \0A{\0A%s\0A}\0A\00"
@.str.3 = [16 x i8] c"fread ret = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = call i64 @fread(i8* %4, i32 1024, i32 1, i32* %5)
%9 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i64 %8, i8* %4)
%10 = call i64 @fread(i8* %4, i32 400, i32 1, i32* %5)
%11 = call i32 (i8*, i64, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i64 %10)
br label %12
12: ; preds = %7, %2
ret i32 0
}