#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 EOF;
scalar_t__ ferror(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int putc(int, int /*<<< orphan*/ *);
int copynFile(FILE *origin, FILE *destination, int nBytes) {
  int totalBytes = 0;
  int outputByte = 0;
  int readByte = 0;
  if (origin == NULL) {
    return -1;
  }
  while ((totalBytes < nBytes) && (readByte = getc(origin)) != EOF) {
    if ((ferror(origin) != 0)) {
      return -1;
    }
    outputByte = putc(readByte, destination);
    if (outputByte == EOF) {
      return -1;
    }
    totalBytes++;
  }
  return totalBytes;
}


x86 assembly (clang, -O0):
<copynFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    116f <copynFile+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <copynFile+0xe0>
jmp    1174 <copynFile+0x44>
mov    -0x20(%rbp),%ecx
xor    %eax,%eax
cmp    -0x1c(%rbp),%ecx
mov    %al,-0x29(%rbp)
jge    11a0 <copynFile+0x70>
mov    -0x10(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e50(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11b0 <copynFile+0x80>
jmp    120a <copynFile+0xda>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11cf <copynFile+0x9f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <copynFile+0xe0>
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1040 <putc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e00(%rip),%rcx
cmp    (%rcx),%eax
jne    11fc <copynFile+0xcc>
movl   $0xffffffff,-0x4(%rbp)
jmp    1210 <copynFile+0xe0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1174 <copynFile+0x44>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copynFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11a5 <copynFile+0x75>
mov    %edx,%r12d
test   %edx,%edx
jle    1198 <copynFile+0x68>
mov    %rsi,%r15
mov    %rdi,%r13
xor    %ebx,%ebx
mov    0x2e8d(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <getc@plt>
cmp    (%r14),%eax
je     11a3 <copynFile+0x73>
mov    %eax,%ebp
mov    %r13,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    119c <copynFile+0x6c>
mov    %ebp,%edi
mov    %r15,%rsi
call   1040 <putc@plt>
cmp    (%r14),%eax
je     119c <copynFile+0x6c>
add    $0x1,%ebx
cmp    %ebx,%r12d
jne    1160 <copynFile+0x30>
mov    %r12d,%eax
jmp    11a5 <copynFile+0x75>
xor    %eax,%eax
jmp    11a5 <copynFile+0x75>
mov    $0xffffffff,%eax
jmp    11a5 <copynFile+0x75>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
define i32 @copynFile(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %44
14: ; preds = %3
br label %15
15: ; preds = %39, %14
%16 = load i32, i32* %8
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load i32*, i32** %5
%21 = call i32 @getc(i32* %20)
store i32 %21, i32* %10
%22 = load i32, i32* @EOF
%23 = icmp ne i32 %21, %22
br label %24
24: ; preds = %19, %15
%25 = phi i1 [ false, %15 ], [ %23, %19 ]
br i1 %25, label %26, label %42
26: ; preds = %24
%27 = load i32*, i32** %5
%28 = call i64 @ferror(i32* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %26
store i32 -1, i32* %4
br label %44
31: ; preds = %26
%32 = load i32, i32* %10
%33 = load i32*, i32** %6
%34 = call i32 @putc(i32 %32, i32* %33)
store i32 %34, i32* %9
%35 = load i32, i32* %9
%36 = load i32, i32* @EOF
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %39
38: ; preds = %31
store i32 -1, i32* %4
br label %44
39: ; preds = %31
%40 = load i32, i32* %8
%41 = add nsw i32 %40, 1
store i32 %41, i32* %8
br label %15
42: ; preds = %24
%43 = load i32, i32* %8
store i32 %43, i32* %4
br label %44
44: ; preds = %42, %38, %30, %13
%45 = load i32, i32* %4
ret i32 %45
}

LLVM IR (-O2):
@EOF = global i32 0
define i32 @copynFile(i32* %0, i32* nocapture %1, i32 %2) {
%4 = icmp eq i32* %0, null
br i1 %4, label %22, label %5
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %22
7: ; preds = %5, %19
%8 = phi i32 [ %20, %19 ], [ 0, %5 ]
%9 = tail call i32 @getc(i32* %0)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = tail call i64 @ferror(i32* %0)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %12
%16 = tail call i32 @putc(i32 %9, i32* %1)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = add nuw nsw i32 %8, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %7
22: ; preds = %12, %15, %19, %7, %5, %3
%23 = phi i32 [ -1, %3 ], [ 0, %5 ], [ -1, %12 ], [ -1, %15 ], [ %2, %19 ], [ %8, %7 ]
ret i32 %23
}