#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 EXIT_SUCCESS;
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int main() {
  char *srcFileName = "Nature-HD-Wallpapers.jpg";
  char *destFileName = "Copy_of_Nature-HD-Wallpapers.jpg";
  FILE *srcFile = fopen(srcFileName, "r");
  if (!srcFile) {
    error(srcFileName);
  }
  FILE *dest = fopen(destFileName, "w");
  if (!dest) {
    error(destFileName);
  }
  char buffer[256];
  size_t byteRead;
  while (!feof(srcFile)) {
    byteRead = fread(buffer, 1, 256, srcFile);
    fwrite(buffer, 1, byteRead, dest);
  }
  printf("Done...");
  fclose(srcFile);
  fclose(dest);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7f(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe6c(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <main+0x50>
mov    -0x10(%rbp),%rdi
call   1070 <error@plt>
mov    -0x18(%rbp),%rdi
lea    0xe58(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e8 <main+0x78>
mov    -0x18(%rbp),%rdi
call   1070 <error@plt>
jmp    11ed <main+0x7d>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    120b <main+0x9b>
jmp    124d <main+0xdd>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x100,%edx
call   1030 <fread@plt>
mov    %rax,-0x138(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x138(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
jmp    11ed <main+0x7d>
lea    0xdd1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe85(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a3 <main+0x33>
lea    0xe6a(%rip),%rdi
call   1070 <error@plt>
lea    0xe56(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11ca <main+0x5a>
lea    0xe3b(%rip),%rdi
call   1070 <error@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    1214 <main+0xa4>
mov    %rsp,%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x100,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1090 <fwrite@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11e0 <main+0x70>
lea    0xe0a(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Nature-HD-Wallpapers.jpg\00"
@.str.1 = [33 x i8] c"Copy_of_Nature-HD-Wallpapers.jpg\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [8 x i8] c"Done...\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i64
store i32 0, i32* %1
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8** %3
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %0
%13 = load i8*, i8** %2
%14 = call i32 @error(i8* %13)
br label %15
15: ; preds = %12, %0
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %17, i32** %5
%18 = load i32*, i32** %5
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = call i32 @error(i8* %21)
br label %23
23: ; preds = %20, %15
br label %24
24: ; preds = %29, %23
%25 = load i32*, i32** %4
%26 = call i32 @feof(i32* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%31 = load i32*, i32** %4
%32 = call i64 @fread(i8* %30, i32 1, i32 256, i32* %31)
store i64 %32, i64* %7
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%34 = load i64, i64* %7
%35 = load i32*, i32** %5
%36 = call i32 @fwrite(i8* %33, i32 1, i64 %34, i32* %35)
br label %24
37: ; preds = %24
%38 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32*, i32** %4
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* @EXIT_SUCCESS
ret i32 %43
}

LLVM IR (-O2):
@.str = [25 x i8] c"Nature-HD-Wallpapers.jpg\00"
@.str.1 = [33 x i8] c"Copy_of_Nature-HD-Wallpapers.jpg\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [8 x i8] c"Done...\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [256 x i8]
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @error(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %0
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%13 = tail call i32 @feof(i32* %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11, %15
%16 = call i64 @fread(i8* %12, i32 1, i32 256, i32* %2)
%17 = call i32 @fwrite(i8* %12, i32 1, i64 %16, i32* %7)
%18 = tail call i32 @feof(i32* %2)
%19 = icmp eq i32 %18, 0
br i1 %19, label %15, label %20
20: ; preds = %15, %11
%21 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 @fclose(i32* %2)
%23 = tail call i32 @fclose(i32* %7)
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}