#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_SET;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int cl_fcopy(char *dest, size_t size, FILE *src) {
  size_t i;
  long pos = ftell(src);
  for (i = 0; i < size && !feof(src); i++)
    dest[i] = fgetc(src);
  fseek(src, pos, SEEK_SET);
  return 0;
}


x86 assembly (clang, -O0):
<cl_fcopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ftell@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
xor    %eax,%eax
cmp    -0x10(%rbp),%rcx
mov    %al,-0x29(%rbp)
jae    1190 <cl_fcopy+0x50>
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a0 <cl_fcopy+0x60>
jmp    11c7 <cl_fcopy+0x87>
mov    -0x18(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1169 <cl_fcopy+0x29>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2e0a(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cl_fcopy>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
call   1040 <ftell@plt>
mov    %rax,%r15
test   %r14,%r14
je     1191 <cl_fcopy+0x51>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r13,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    1191 <cl_fcopy+0x51>
mov    %r13,%rdi
call   1030 <fgetc@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1170 <cl_fcopy+0x30>
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %r13,%rdi
mov    %r15,%rsi
call   1060 <fseek@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @cl_fcopy(i8* nocapture writeonly %0, i64 %1, i32* nocapture %2) {
%4 = tail call i64 @ftell(i32* %2)
%5 = icmp eq i64 %1, 0
br i1 %5, label %15, label %6
6: ; preds = %3, %10
%7 = phi i64 [ %13, %10 ], [ 0, %3 ]
%8 = tail call i32 @feof(i32* %2)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %6
%11 = tail call signext i8 @fgetc(i32* %2)
%12 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 %11, i8* %12
%13 = add nuw i64 %7, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %6
15: ; preds = %6, %10, %3
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @fseek(i32* %2, i64 %4, i32 %16)
ret i32 0
}