#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
void main() {
  char filename[20];
  FILE *fptr_R = NULL;
  FILE *fptr_w = NULL;
  int carrier = 0;
  printf("kindly write the name of the file you want to copy ::");
  scanf("%s", filename);
  printf("printing file :%s ......\n", filename);
  fptr_R = fopen(filename, "r");
  if (fptr_R == NULL) {
    printf("....Error Cannot open file \n");
    exit(EXIT_FAILURE);
  }
  printf("kindly write the name of the New ::");
  scanf("%s", filename);
  fptr_w = fopen(filename, "w");
  if (fptr_w == NULL) {
    printf("Cannot Create the New file \n");
    exit(EXIT_FAILURE);
  }
  while ((carrier = fgetc(fptr_R)) != EOF)
    carrier = fputc(carrier, fptr_w);
  printf("File copied Successfuly \n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe9e(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ea <main+0x8a>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x20(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1243 <main+0xe3>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
jmp    1248 <main+0xe8>
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d8d(%rip),%rcx
cmp    (%rcx),%eax
je     1277 <main+0x117>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
call   1050 <fputc@plt>
mov    %eax,-0x34(%rbp)
jmp    1248 <main+0xe8>
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea8(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe99(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     123d <main+0xcd>
mov    %rax,%r14
lea    0xe8d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe60(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe91(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1246 <main+0xd6>
mov    %rax,%rbx
mov    %r14,%rdi
call   1050 <fgetc@plt>
mov    0x2de1(%rip),%r15
cmp    (%r15),%eax
je     1227 <main+0xb7>
nopl   0x0(%rax)
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1050 <fgetc@plt>
cmp    (%r15),%eax
jne    1210 <main+0xa0>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe6c(%rip),%rdi
jmp    124d <main+0xdd>
lea    0xe47(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"kindly write the name of the file you want to copy ::\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [26 x i8] c"printing file :%s ......\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [29 x i8] c"....Error Cannot open file \0A\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [36 x i8] c"kindly write the name of the New ::\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [29 x i8] c"Cannot Create the New file \0A\00"
@EOF = global i32 0
@.str.8 = [26 x i8] c"File copied Successfuly \0A\00"
define void @main() {
%1 = alloca [20 x i8]
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32* null, i32** %2
store i32* null, i32** %3
store i32 0, i32* %4
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %11, i32** %2
%12 = load i32*, i32** %2
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %23, i32** %3
%24 = load i32*, i32** %3
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
br label %31
31: ; preds = %36, %30
%32 = load i32*, i32** %2
%33 = call i32 @fgetc(i32* %32)
store i32 %33, i32* %4
%34 = load i32, i32* @EOF
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32, i32* %4
%38 = load i32*, i32** %3
%39 = call i32 @fputc(i32 %37, i32* %38)
store i32 %39, i32* %4
br label %31
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"kindly write the name of the file you want to copy ::\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [26 x i8] c"printing file :%s ......\0A\00"
@.str.3 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [36 x i8] c"kindly write the name of the New ::\00"
@.str.6 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [25 x i8] c"File copied Successfuly \00"
@str.9 = [28 x i8] c"Cannot Create the New file \00"
@str.10 = [28 x i8] c"....Error Cannot open file \00"
define void @main() {
%1 = alloca [20 x i8]
%2 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%6 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %12
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.10, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%15 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = call i32 @fgetc(i32* %6)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %31, label %25
21: ; preds = %12
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str.9, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %17, %25
%26 = phi i32 [ %28, %25 ], [ %18, %17 ]
%27 = call i32 @fputc(i32 %26, i32* %15)
%28 = call i32 @fgetc(i32* %6)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %25
31: ; preds = %25, %17
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
ret void
}