#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 */
scalar_t__ EINTR;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ errno;
long long fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long long fwrite(char *, int, long long, int /*<<< orphan*/ *);
void MITLogCopyFile(FILE *fromFP, FILE *toFP) {
  char buf[1024 * 10];
  long long nread;
  fseek(fromFP, 0L, SEEK_SET);
  while ((nread = fread(buf, sizeof(char), 1024 * 10, fromFP))) {
    char *outp = buf;
    long long nwritten;
    do {
      nwritten = fwrite(outp, sizeof(char), nread, toFP);
      if (nwritten >= 0) {
        nread -= nwritten;
        outp += nwritten;
      } else if (errno != EINTR) {
        break;
      }
    } while (nread > 0);
  }
}


x86 assembly (clang, -O0):
<MITLogCopyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1040 <fseek@plt>
lea    -0x2810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0x2800,%edx
call   1030 <fread@plt>
mov    %rax,-0x2818(%rbp)
cmp    $0x0,%rax
je     1231 <MITLogCopyFile+0x101>
lea    -0x2810(%rbp),%rax
mov    %rax,-0x2820(%rbp)
mov    -0x2820(%rbp),%rdi
mov    -0x2818(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %rax,-0x2828(%rbp)
cmpq   $0x0,-0x2828(%rbp)
jl     11f5 <MITLogCopyFile+0xc5>
mov    -0x2828(%rbp),%rcx
mov    -0x2818(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x2818(%rbp)
mov    -0x2828(%rbp),%rax
add    -0x2820(%rbp),%rax
mov    %rax,-0x2820(%rbp)
jmp    1219 <MITLogCopyFile+0xe9>
mov    0x2de4(%rip),%rax
mov    (%rax),%rax
mov    0x2dca(%rip),%rcx
cmp    (%rcx),%rax
je     1214 <MITLogCopyFile+0xe4>
jmp    122c <MITLogCopyFile+0xfc>
jmp    1219 <MITLogCopyFile+0xe9>
jmp    121e <MITLogCopyFile+0xee>
cmpq   $0x0,-0x2818(%rbp)
jg     1192 <MITLogCopyFile+0x62>
jmp    1159 <MITLogCopyFile+0x29>
add    $0x2830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MITLogCopyFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2808,%rsp
mov    %rsi,%r12
mov    %rdi,%rbx
mov    0x2e8a(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <fseek@plt>
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x2800,%edx
mov    %rbx,%r15
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11e2 <MITLogCopyFile+0xb2>
mov    %rax,%rbx
mov    0x2e62(%rip),%rbp
mov    0x2e4b(%rip),%r14
mov    %rsp,%r13
jmp    11b0 <MITLogCopyFile+0x80>
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x2800,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11e2 <MITLogCopyFile+0xb2>
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
mov    %r12,%rcx
call   1050 <fwrite@plt>
test   %rax,%rax
jns    11d8 <MITLogCopyFile+0xa8>
test   %rbx,%rbx
jle    118a <MITLogCopyFile+0x5a>
mov    (%r14),%rax
cmp    %rax,0x0(%rbp)
je     11b0 <MITLogCopyFile+0x80>
jmp    118a <MITLogCopyFile+0x5a>
add    %rax,%r13
sub    %rax,%rbx
jg     11b0 <MITLogCopyFile+0x80>
jmp    118a <MITLogCopyFile+0x5a>
add    $0x2808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define void @MITLogCopyFile(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca [10240 x i8]
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
store i32* %0, i32** %3
store i32* %1, i32** %4
%9 = load i32*, i32** %3
%10 = load i32, i32* @SEEK_SET
%11 = call i32 @fseek(i32* %9, i64 0, i32 %10)
br label %12
12: ; preds = %43, %2
%13 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i64 @fread(i8* %13, i32 1, i32 10240, i32* %14)
store i64 %15, i64* %6
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %44
17: ; preds = %12
%18 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
store i8* %18, i8** %7
br label %19
19: ; preds = %40, %17
%20 = load i8*, i8** %7
%21 = load i64, i64* %6
%22 = load i32*, i32** %4
%23 = call i64 @fwrite(i8* %20, i32 1, i64 %21, i32* %22)
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = icmp sge i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %19
%27 = load i64, i64* %8
%28 = load i64, i64* %6
%29 = sub nsw i64 %28, %27
store i64 %29, i64* %6
%30 = load i64, i64* %8
%31 = load i8*, i8** %7
%32 = getelementptr inbounds i8, i8* %31, i64 %30
store i8* %32, i8** %7
br label %39
33: ; preds = %19
%34 = load i64, i64* @errno
%35 = load i64, i64* @EINTR
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %38
37: ; preds = %33
br label %43
38: ; preds = %33
br label %39
39: ; preds = %38, %26
br label %40
40: ; preds = %39
%41 = load i64, i64* %6
%42 = icmp sgt i64 %41, 0
br i1 %42, label %19, label %43
43: ; preds = %40, %37
br label %12
44: ; preds = %12
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define void @MITLogCopyFile(i32* nocapture %0, i32* nocapture %1) {
%3 = alloca [10240 x i8]
%4 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @fseek(i32* %0, i64 0, i32 %5)
%7 = call i64 @fread(i8* %4, i32 1, i32 10240, i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %31, label %9
9: ; preds = %2, %20
%10 = phi i8* [ %21, %20 ], [ %4, %2 ]
%11 = phi i64 [ %22, %20 ], [ %7, %2 ]
%12 = icmp sgt i64 %11, 0
br label %13
13: ; preds = %9, %23
%14 = call i64 @fwrite(i8* %10, i32 1, i64 %11, i32* %1)
%15 = icmp sgt i64 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = sub nsw i64 %11, %14
%18 = getelementptr inbounds i8, i8* %10, i64 %14
%19 = icmp sgt i64 %17, 0
br i1 %19, label %20, label %28
20: ; preds = %16, %28
%21 = phi i8* [ %18, %16 ], [ %4, %28 ]
%22 = phi i64 [ %17, %16 ], [ %29, %28 ]
br label %9
23: ; preds = %13
%24 = load i64, i64* @errno
%25 = load i64, i64* @EINTR
%26 = icmp eq i64 %24, %25
%27 = and i1 %12, %26
br i1 %27, label %13, label %28
28: ; preds = %23, %16
%29 = call i64 @fread(i8* %4, i32 1, i32 10240, i32* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %20
31: ; preds = %28, %2
ret void
}