#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*/ CopyFile(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *OpenUserFile(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
main() {
  FILE *infile, *outfile;
  printf("This program copies one file to another.\n");
  infile = OpenUserFile("Old file: ", "r");
  outfile = OpenUserFile("New file: ", "w");
  CopyFile(infile, outfile);
  fclose(infile);
  fclose(outfile);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
lea    0xed3(%rip),%rsi
call   1050 <OpenUserFile@plt>
mov    %rax,-0x8(%rbp)
lea    0xec5(%rip),%rdi
lea    0xec9(%rip),%rsi
call   1050 <OpenUserFile@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <CopyFile@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xecf(%rip),%rdi
call   1030 <puts@plt>
lea    0xea9(%rip),%rdi
lea    0xead(%rip),%rsi
call   1050 <OpenUserFile@plt>
mov    %rax,%r14
lea    0xea0(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1050 <OpenUserFile@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <CopyFile@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [42 x i8] c"This program copies one file to another.\0A\00"
@.str.1 = [11 x i8] c"Old file: \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [11 x i8] c"New file: \00"
@.str.4 = [2 x i8] c"w\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0))
%4 = call i32* @OpenUserFile(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %4, i32** %1
%5 = call i32* @OpenUserFile(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %5, i32** %2
%6 = load i32*, i32** %1
%7 = load i32*, i32** %2
%8 = call i32 @CopyFile(i32* %6, i32* %7)
%9 = load i32*, i32** %1
%10 = call i32 @fclose(i32* %9)
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"Old file: \00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [11 x i8] c"New file: \00"
@.str.4 = [2 x i8] c"w\00"
@str = [41 x i8] c"This program copies one file to another.\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str, i64 0, i64 0))
%2 = tail call i32* @OpenUserFile(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%3 = tail call i32* @OpenUserFile(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%4 = tail call i32 @CopyFile(i32* %2, i32* %3)
%5 = tail call i32 @fclose(i32* %2)
%6 = tail call i32 @fclose(i32* %3)
ret i32 0
}