#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 /*<<< orphan*/ remove(char *);
int main(int argc, char **argv) {
  FILE *source, *dest;
  unsigned int cha;
  char opt;
  if (argc == 1) {
    printf("Please provide the file to cut\n");
    exit(0);
  }
  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);
    }
  }
  source = fopen(argv[1], "rb");
  dest = fopen("/tmp/.vmlinuz", "wb");
  if (dest == NULL) {
    printf("Error while opening Buffer to write\n");
    return 0;
  }
  fprintf(dest, "%s %s %s ", argv[1], "CUT", "ENDN");
  do {
    cha = fgetc(source);
    if (cha == EOF)
      break;
    fputc(cha, dest);
  } while (1);
  fclose(source);
  fclose(dest);
  remove(argv[1]);
  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)
cmpl   $0x1,-0x8(%rbp)
jne    11c3 <main+0x33>
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xe56(%rip),%rdi
lea    0xe5d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1237 <main+0xa7>
lea    0xe45(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1090 <getch@plt>
mov    %al,-0x25(%rbp)
movsbl -0x25(%rbp),%eax
cmp    $0x59,%eax
jne    1216 <main+0x86>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1232 <main+0xa2>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe79(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
jmp    1237 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xde8(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    0xdca(%rip),%rdi
lea    0xe1c(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1289 <main+0xf9>
lea    0xe04(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1313 <main+0x183>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe05(%rip),%rsi
lea    0xe08(%rip),%rcx
lea    0xe05(%rip),%r8
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2d23(%rip),%rcx
cmp    (%rcx),%eax
jne    12d2 <main+0x142>
jmp    12ed <main+0x15d>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1070 <fputc@plt>
mov    $0x1,%al
test   $0x1,%al
jne    12af <main+0x11f>
jmp    12ed <main+0x15d>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <remove@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
cmp    $0x1,%edi
je     12bb <main+0x10b>
mov    %rsi,%r14
lea    0xe36(%rip),%rdi
lea    0xe3d(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1205 <main+0x55>
mov    %rax,%rbx
lea    0xe2c(%rip),%rdi
call   1070 <printf@plt>
xor    %eax,%eax
call   10b0 <getch@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
cmp    $0x59,%bpl
jne    12ce <main+0x11e>
mov    0x8(%r14),%rdi
lea    0xdfe(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r15
lea    0xde1(%rip),%rdi
lea    0xe33(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12a2 <main+0xf2>
mov    %rax,%rbx
mov    0x8(%r14),%rdx
lea    0xe1e(%rip),%rsi
lea    0xe21(%rip),%rcx
lea    0xe1e(%rip),%r8
mov    %rax,%rdi
call   10a0 <fprintf@plt>
mov    %r15,%rdi
call   1080 <fgetc@plt>
mov    0x2d85(%rip),%rbp
cmp    0x0(%rbp),%eax
je     1287 <main+0xd7>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %rbx,%rsi
call   1090 <fputc@plt>
mov    %r15,%rdi
call   1080 <fgetc@plt>
cmp    0x0(%rbp),%eax
jne    1270 <main+0xc0>
mov    %r15,%rdi
call   1060 <fclose@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x8(%r14),%rdi
call   1040 <remove@plt>
jmp    12ae <main+0xfe>
lea    0xdc6(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdd1(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

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

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