#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;
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(unsigned char, int /*<<< orphan*/ *);
int copynFile(FILE *origin, FILE *destination, int nBytes) {
  int nCopy = 0;
  int c;
  while (nCopy < nBytes && (c = getc(origin)) != EOF) {
    putc((unsigned char)c, destination);
    nCopy++;
  }
  return (nCopy);
}


x86 assembly (clang, -O0):
<copynFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jge    1166 <copynFile+0x46>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e8a(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1176 <copynFile+0x56>
jmp    1193 <copynFile+0x73>
mov    -0x1c(%rbp),%eax
mov    -0x10(%rbp),%rsi
movzbl %al,%edi
call   1030 <putc@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113a <copynFile+0x1a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copynFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edx,%edx
jle    1164 <copynFile+0x44>
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
mov    0x2eab(%rip),%r12
nopl   (%rax)
mov    %r15,%rdi
call   1040 <getc@plt>
cmp    (%r12),%eax
je     1166 <copynFile+0x46>
movzbl %al,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1140 <copynFile+0x20>
mov    %ebp,%ebx
jmp    1166 <copynFile+0x46>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
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
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %20, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32*, i32** %4
%15 = call i32 @getc(i32* %14)
store i32 %15, i32* %8
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br label %18
18: ; preds = %13, %9
%19 = phi i1 [ false, %9 ], [ %17, %13 ]
br i1 %19, label %20, label %27
20: ; preds = %18
%21 = load i32, i32* %8
%22 = trunc i32 %21 to i8
%23 = load i32*, i32** %5
%24 = call i32 @putc(i8 zeroext %22, i32* %23)
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %9
27: ; preds = %18
%28 = load i32, i32* %7
ret i32 %28
}

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