#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ copy(char *, char *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, char *);
scalar_t__ getline(char **, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char path[4096];
  char destPath[4096];
  printf("Please enter path to file: ");
  scanf("%s", path);
  printf("Please enter path to modified file:");
  scanf("%s", destPath);
  FILE *file = fopen(path, "r");
  FILE *destFile = fopen(destPath, "w+");
  char buffer[4096 + 1];
  if (file) {
    copy(path, destPath);
    int lineNumber = 0;
    int length = 0;
    char *line;
    while (!feof(file)) {
      ssize_t readBytes = getline(&line, &length, file);
      if (readBytes <= 0) {
        break;
      }
      fprintf(destFile, "%d %s", lineNumber, line);
      lineNumber++;
    }
    printf("Done!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3050,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
lea    -0x1010(%rbp),%rsi
lea    0xeac(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe74(%rip),%rdi
call   1030 <printf@plt>
lea    -0x2010(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x1010(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x2018(%rbp)
lea    -0x2010(%rbp),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x2020(%rbp)
cmpq   $0x0,-0x2018(%rbp)
je     12be <main+0x14e>
lea    -0x1010(%rbp),%rdi
lea    -0x2010(%rbp),%rsi
call   1040 <copy@plt>
movl   $0x0,-0x3034(%rbp)
movl   $0x0,-0x3038(%rbp)
mov    -0x2018(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124a <main+0xda>
jmp    12b2 <main+0x142>
mov    -0x2018(%rbp),%rdx
lea    -0x3040(%rbp),%rdi
lea    -0x3038(%rbp),%rsi
call   1090 <getline@plt>
mov    %rax,-0x3048(%rbp)
cmpq   $0x0,-0x3048(%rbp)
jg     127e <main+0x10e>
jmp    12b2 <main+0x142>
mov    -0x2020(%rbp),%rdi
mov    -0x3034(%rbp),%edx
mov    -0x3040(%rbp),%rcx
lea    0xdac(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x3034(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3034(%rbp)
jmp    1229 <main+0xb9>
lea    0xd92(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x3050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2018,%rsp
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
lea    0xea4(%rip),%rbx
lea    0x1010(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe5e(%rip),%rdi
call   1040 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <scanf@plt>
lea    0xe66(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
lea    0xe56(%rip),%rsi
mov    %rbp,%rdi
call   1090 <fopen@plt>
test   %rbx,%rbx
je     1280 <main+0x100>
mov    %rax,%r14
lea    0x1010(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <copy@plt>
movl   $0x0,0x4(%rsp)
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1274 <main+0xf4>
xor    %ebp,%ebp
lea    0x8(%rsp),%r15
lea    0x4(%rsp),%r12
lea    0xe0c(%rip),%r13
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
test   %rax,%rax
jle    1274 <main+0xf4>
mov    0x8(%rsp),%rcx
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1240 <main+0xc0>
lea    0xdd0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Please enter path to file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [36 x i8] c"Please enter path to modified file:\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [6 x i8] c"%d %s\00"
@.str.6 = [7 x i8] c"Done!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [4096 x i8]
%3 = alloca [4096 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca [4097 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
store i32 0, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %18, i32** %4
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %5
%21 = load i32*, i32** %4
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %47
23: ; preds = %0
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%26 = call i32 @copy(i8* %24, i8* %25)
store i32 0, i32* %7
store i32 0, i32* %8
br label %27
27: ; preds = %38, %23
%28 = load i32*, i32** %4
%29 = call i32 @feof(i32* %28)
%30 = icmp ne i32 %29, 0
%31 = xor i1 %30, true
br i1 %31, label %32, label %45
32: ; preds = %27
%33 = load i32*, i32** %4
%34 = call i64 @getline(i8** %9, i32* %8, i32* %33)
store i64 %34, i64* %10
%35 = load i64, i64* %10
%36 = icmp sle i64 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %32
br label %45
38: ; preds = %32
%39 = load i32*, i32** %5
%40 = load i32, i32* %7
%41 = load i8*, i8** %9
%42 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %40, i8* %41)
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
br label %27
45: ; preds = %37, %27
%46 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %45, %0
ret i32 0
}

LLVM IR (-O2):
@.str = [28 x i8] c"Please enter path to file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [36 x i8] c"Please enter path to modified file:\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [3 x i8] c"w+\00"
@.str.5 = [6 x i8] c"%d %s\00"
@str = [6 x i8] c"Done!\00"
define i32 @main() {
%1 = alloca [4096 x i8]
%2 = alloca [4096 x i8]
%3 = alloca i32
%4 = alloca i8*
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%11 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%13 = icmp eq i32* %11, null
br i1 %13, label %32, label %14
14: ; preds = %0
%15 = call i32 @copy(i8* %5, i8* %6)
%16 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%17 = bitcast i8** %4 to i8*
%18 = call i32 @feof(i32* %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %30
20: ; preds = %14, %24
%21 = phi i32 [ %27, %24 ], [ 0, %14 ]
%22 = call i64 @getline(i8** %4, i32* %3, i32* %11)
%23 = icmp slt i64 %22, 1
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %21, i8* %25)
%27 = add nuw nsw i32 %21, 1
%28 = call i32 @feof(i32* %11)
%29 = icmp eq i32 %28, 0
br i1 %29, label %20, label %30
30: ; preds = %24, %20, %14
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %30, %0
ret i32 0
}