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

/* Variables and functions */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_END;
scalar_t__ fflush(int /*<<< orphan*/ *);
int filecopy(int, int);
int fileno(int /*<<< orphan*/ *);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
ssize_t ffilecopy(FILE *here, FILE *there) {
  int i, herefile, therefile;
  herefile = fileno(here);
  therefile = fileno(there);
  if (fflush(there) == EOF)
    return EOF;
  ;
  i = filecopy(herefile, therefile);
  if (i < 0)
    return EOF;
  (void)fseeko(here, (off_t)0, SEEK_END);
  ;
  return 0;
}


x86 assembly (clang, -O0):
<ffilecopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fileno@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <fflush@plt>
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <ffilecopy+0x54>
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11db <ffilecopy+0x9b>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1030 <filecopy@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11bf <ffilecopy+0x7f>
mov    0x2e2d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11db <ffilecopy+0x9b>
mov    -0x10(%rbp),%rdi
mov    0x2e1e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseeko@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ffilecopy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbp
mov    %rdi,%rbx
call   1040 <fileno@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1040 <fileno@plt>
mov    %eax,%r15d
mov    %rbp,%rdi
call   1050 <fflush@plt>
mov    %rax,%rbp
mov    0x2e6d(%rip),%r12
cmp    (%r12),%rax
je     11a3 <ffilecopy+0x63>
mov    %r14d,%edi
mov    %r15d,%esi
call   1030 <filecopy@plt>
test   %eax,%eax
js     119f <ffilecopy+0x5f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseeko@plt>
jmp    11a3 <ffilecopy+0x63>
mov    (%r12),%rbp
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i64 0
@SEEK_END = global i32 0
define i64 @ffilecopy(i32* %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %4
%10 = call i32 @fileno(i32* %9)
store i32 %10, i32* %7
%11 = load i32*, i32** %5
%12 = call i32 @fileno(i32* %11)
store i32 %12, i32* %8
%13 = load i32*, i32** %5
%14 = call i64 @fflush(i32* %13)
%15 = load i64, i64* @EOF
%16 = icmp eq i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = load i64, i64* @EOF
store i64 %18, i64* %3
br label %31
19: ; preds = %2
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = call i32 @filecopy(i32 %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = load i64, i64* @EOF
store i64 %26, i64* %3
br label %31
27: ; preds = %19
%28 = load i32*, i32** %4
%29 = load i32, i32* @SEEK_END
%30 = call i32 @fseeko(i32* %28, i32 0, i32 %29)
store i64 0, i64* %3
br label %31
31: ; preds = %27, %25, %17
%32 = load i64, i64* %3
ret i64 %32
}

LLVM IR (-O2):
@EOF = global i64 0
@SEEK_END = global i32 0
define i64 @ffilecopy(i32* nocapture %0, i32* nocapture %1) {
%3 = tail call i32 @fileno(i32* %0)
%4 = tail call i32 @fileno(i32* %1)
%5 = tail call i64 @fflush(i32* %1)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %16, label %8
8: ; preds = %2
%9 = tail call i32 @filecopy(i32 %3, i32 %4)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = load i64, i64* @EOF
br label %16
13: ; preds = %8
%14 = load i32, i32* @SEEK_END
%15 = tail call i32 @fseeko(i32* %0, i32 0, i32 %14)
br label %16
16: ; preds = %2, %13, %11
%17 = phi i64 [ %12, %11 ], [ 0, %13 ], [ %5, %2 ]
ret i64 %17
}