#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 */
unsigned int EOF;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
unsigned int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *,
                           char *);
int /*<<< orphan*/ fputc(unsigned int, int /*<<< orphan*/ *);
char getch();
int /*<<< orphan*/ printf(char *);
int main(int argc, char **argv) {
  FILE *source, *dest;
  unsigned int cha;
  char opt;
  dest = fopen("/tmp/.vmlinuz", "rb");
  if (dest != NULL) {
    printf("A file is previously copied to Buffer.\nDo you Want to replace "
           "it(Y/n)? ");
    opt = getch();
    if (opt == 'Y') {
      fclose(dest);
    } else {
      fclose(dest);
      printf("\n");
      exit(0);
    }
  }
  if (argc == 1) {
    printf("Please provide the file to copy\n");
    exit(0);
  }
  source = fopen(argv[1], "rb");
  if (source == NULL) {
    printf("Error while opening file to be copied\n");
    return 0;
  }
  dest = fopen("/tmp/.vmlinuz", "wb");
  if (dest == NULL) {
    printf("Error while opening Buffer\n");
    return 0;
  }
  fprintf(dest, "%s %s %s ", argv[1], "COPY", "ENDN");
  do {
    cha = fgetc(source);
    if (cha == EOF)
      break;
    fputc(cha, dest);
  } while (1);
  fclose(source);
  fclose(dest);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120a <main+0x8a>
lea    0xe52(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <getch@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0x59,%eax
jne    11e9 <main+0x69>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1205 <main+0x85>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    120a <main+0x8a>
cmpl   $0x1,-0x8(%rbp)
jne    1227 <main+0xa7>
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdd8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1262 <main+0xe2>
lea    0xe29(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1319 <main+0x199>
lea    0xd97(%rip),%rdi
lea    0xe31(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    129c <main+0x11c>
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1319 <main+0x199>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe11(%rip),%rsi
lea    0xe14(%rip),%rcx
lea    0xe12(%rip),%r8
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d10(%rip),%rcx
cmp    (%rcx),%eax
jne    12e5 <main+0x165>
jmp    1300 <main+0x180>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1060 <fputc@plt>
mov    $0x1,%al
test   $0x1,%al
jne    12c2 <main+0x142>
jmp    1300 <main+0x180>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xe4d(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     11ef <main+0x4f>
mov    %rax,%rbx
lea    0xe43(%rip),%rdi
call   1060 <printf@plt>
xor    %eax,%eax
call   10a0 <getch@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    $0x59,%r15b
jne    12ce <main+0x12e>
cmp    $0x1,%ebp
je     12bb <main+0x11b>
mov    0x8(%r14),%rdi
lea    0xe0b(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1299 <main+0xf9>
mov    %rax,%r15
lea    0xde5(%rip),%rdi
lea    0xe37(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12a2 <main+0x102>
mov    %rax,%rbx
mov    0x8(%r14),%rdx
lea    0xe22(%rip),%rsi
lea    0xe25(%rip),%rcx
lea    0xe23(%rip),%r8
mov    %rax,%rdi
call   1090 <fprintf@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
mov    0x2d89(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1287 <main+0xe7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edi
mov    %rbx,%rsi
call   1080 <fputc@plt>
mov    %r15,%rdi
call   1070 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1270 <main+0xd0>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    12ae <main+0x10e>
lea    0xdeb(%rip),%rdi
jmp    12a9 <main+0x109>
lea    0xdc7(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/tmp/.vmlinuz\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [72 x i8] c"A file is previously copied to Buffer.\0ADo you Want to replace it(Y/n)? \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [33 x i8] c"Please provide the file to copy\0A\00"
@.str.5 = [39 x i8] c"Error while opening file to be copied\0A\00"
@.str.6 = [3 x i8] c"wb\00"
@.str.7 = [28 x i8] c"Error while opening Buffer\0A\00"
@.str.8 = [10 x i8] c"%s %s %s \00"
@.str.9 = [5 x i8] c"COPY\00"
@.str.10 = [5 x i8] c"ENDN\00"
@EOF = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %28
13: ; preds = %2
%14 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
%15 = call signext i8 (...) @getch()
store i8 %15, i8* %9
%16 = load i8, i8* %9
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 89
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32*, i32** %7
%21 = call i32 @fclose(i32* %20)
br label %27
22: ; preds = %13
%23 = load i32*, i32** %7
%24 = call i32 @fclose(i32* %23)
%25 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %19
br label %28
28: ; preds = %27, %2
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %28
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %38, i32** %6
%39 = load i32*, i32** %6
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %43
41: ; preds = %34
%42 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %72
43: ; preds = %34
%44 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
store i32* %44, i32** %7
%45 = load i32*, i32** %7
%46 = icmp eq i32* %45, null
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %3
br label %72
49: ; preds = %43
%50 = load i32*, i32** %7
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 1
%53 = load i8*, i8** %52
%54 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %55
55: ; preds = %66, %49
%56 = load i32*, i32** %6
%57 = call i32 @fgetc(i32* %56)
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = load i32, i32* @EOF
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %62
61: ; preds = %55
br label %67
62: ; preds = %55
%63 = load i32, i32* %8
%64 = load i32*, i32** %7
%65 = call i32 @fputc(i32 %63, i32* %64)
br label %66
66: ; preds = %62
br i1 true, label %55, label %67
67: ; preds = %66, %61
%68 = load i32*, i32** %6
%69 = call i32 @fclose(i32* %68)
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
store i32 0, i32* %3
br label %72
72: ; preds = %67, %47, %41
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@.str = [14 x i8] c"/tmp/.vmlinuz\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [72 x i8] c"A file is previously copied to Buffer.\0ADo you Want to replace it(Y/n)? \00"
@.str.6 = [3 x i8] c"wb\00"
@.str.8 = [10 x i8] c"%s %s %s \00"
@.str.9 = [5 x i8] c"COPY\00"
@.str.10 = [5 x i8] c"ENDN\00"
@EOF = global i32 0
@str = [27 x i8] c"Error while opening Buffer\00"
@str.11 = [38 x i8] c"Error while opening file to be copied\00"
@str.12 = [32 x i8] c"Please provide the file to copy\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call signext i8 (...) @getch()
%8 = icmp eq i8 %7, 89
%9 = tail call i32 @fclose(i32* %3)
br i1 %8, label %13, label %10
10: ; preds = %5
%11 = tail call i32 @putchar(i32 10)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %5, %2
%14 = icmp eq i32 %0, 1
br i1 %14, label %15, label %18
15: ; preds = %13
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.12, i64 0, i64 0))
%17 = tail call i32 @exit(i32 0)
unreachable
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %25
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.11, i64 0, i64 0))
br label %45
25: ; preds = %18
%26 = tail call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
br label %45
30: ; preds = %25
%31 = load i8*, i8** %19
%32 = tail call i32 @fprintf(i32* %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %31, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%33 = tail call i32 @fgetc(i32* %21)
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %42, label %36
36: ; preds = %30, %36
%37 = phi i32 [ %39, %36 ], [ %33, %30 ]
%38 = tail call i32 @fputc(i32 %37, i32* %26)
%39 = tail call i32 @fgetc(i32* %21)
%40 = load i32, i32* @EOF
%41 = icmp eq i32 %39, %40
br i1 %41, label %42, label %36
42: ; preds = %36, %30
%43 = tail call i32 @fclose(i32* %21)
%44 = tail call i32 @fclose(i32* %26)
br label %45
45: ; preds = %42, %28, %23
ret i32 0
}