#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_END;
char *calloc(size_t, int);
int /*<<< orphan*/ fread(char *, size_t, int, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *fcat(FILE *file) {
  if (fseek(file, 0, SEEK_END))
    return NULL;
  long size = ftell(file);
  char *content = calloc((size_t)size + 1, sizeof(char));
  if (content == NULL)
    return NULL;
  rewind(file);
  fread(content, (size_t)size, 1, file);
  content[size] = '\0';
  return content;
}


x86 assembly (clang, -O0):
<fcat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
cmp    $0x0,%rax
je     1187 <fcat+0x37>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <fcat+0xa5>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c2 <fcat+0x72>
movq   $0x0,-0x8(%rbp)
jmp    11f5 <fcat+0xa5>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fcat>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    0x2e89(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
xor    %esi,%esi
call   1070 <fseek@plt>
test   %rax,%rax
jne    11b4 <fcat+0x64>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
test   %rax,%rax
je     11b2 <fcat+0x62>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <rewind@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    11b4 <fcat+0x64>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@SEEK_END = global i32 0
define i8* @fcat(i32* nocapture %0) {
%2 = load i32, i32* @SEEK_END
%3 = tail call i64 @fseek(i32* %0, i32 0, i32 %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1
%6 = tail call i64 @ftell(i32* %0)
%7 = add i64 %6, 1
%8 = tail call i8* @calloc(i64 %7, i32 1)
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %5
%11 = tail call i32 @rewind(i32* %0)
%12 = tail call i32 @fread(i8* %8, i64 %6, i32 1, i32* %0)
%13 = getelementptr inbounds i8, i8* %8, i64 %6
store i8 0, i8* %13
br label %14
14: ; preds = %10, %5, %1
%15 = phi i8* [ null, %1 ], [ %8, %10 ], [ null, %5 ]
ret i8* %15
}