#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*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
void read_file(FILE *file, char *buffer, size_t size) {
  int i;
  for (i = 0; !feof(file) && i < size; i++)
    buffer[i] = fgetc(file);
  buffer[i - 1] = '\0';
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1d(%rbp)
jne    1162 <read_file+0x42>
movslq -0x1c(%rbp),%rax
cmp    -0x18(%rbp),%rax
setb   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1172 <read_file+0x52>
jmp    1196 <read_file+0x76>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    113b <read_file+0x1b>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <feof@plt>
mov    $0xffffffffffffffff,%rbx
test   %eax,%eax
jne    119c <read_file+0x7c>
test   %r15,%r15
je     119c <read_file+0x7c>
movabs $0xffffffff00000000,%rbx
ff ff ff
mov    $0x1,%ebp
movabs $0x100000000,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %r13,%rbx
mov    %r12,%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1(%r14,%rbp,1)
mov    %r12,%rdi
call   1040 <feof@plt>
test   %eax,%eax
jne    1198 <read_file+0x78>
lea    0x1(%rbp),%rax
cmp    %r15,%rbp
mov    %rax,%rbp
jb     1170 <read_file+0x50>
sar    $0x20,%rbx
movb   $0x0,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @read_file(i32* %0, i8* %1, i64 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
br label %8
8: ; preds = %26, %3
%9 = load i32*, i32** %4
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8
%13 = load i32, i32* %7
%14 = sext i32 %13 to i64
%15 = load i64, i64* %6
%16 = icmp ult i64 %14, %15
br label %17
17: ; preds = %12, %8
%18 = phi i1 [ false, %8 ], [ %16, %12 ]
br i1 %18, label %19, label %29
19: ; preds = %17
%20 = load i32*, i32** %4
%21 = call signext i8 @fgetc(i32* %20)
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
br label %26
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %8
29: ; preds = %17
%30 = load i8*, i8** %5
%31 = load i32, i32* %7
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 0, i8* %34
ret void
}

LLVM IR (-O2):
define void @read_file(i32* nocapture %0, i8* nocapture writeonly %1, i64 %2) {
%4 = tail call i32 @feof(i32* %0)
%5 = icmp eq i32 %4, 0
%6 = icmp ne i64 %2, 0
%7 = and i1 %5, %6
br i1 %7, label %8, label %20
8: ; preds = %3, %8
%9 = phi i64 [ %12, %8 ], [ 0, %3 ]
%10 = tail call signext i8 @fgetc(i32* %0)
%11 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %10, i8* %11
%12 = add nuw i64 %9, 1
%13 = tail call i32 @feof(i32* %0)
%14 = icmp eq i32 %13, 0
%15 = icmp ult i64 %12, %2
%16 = select i1 %14, i1 %15, i1 false
br i1 %16, label %8, label %17
17: ; preds = %8
%18 = shl i64 %9, 32
%19 = ashr exact i64 %18, 32
br label %20
20: ; preds = %17, %3
%21 = phi i64 [ -1, %3 ], [ %19, %17 ]
%22 = getelementptr inbounds i8, i8* %1, i64 %21
store i8 0, i8* %22
ret void
}