#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int main() {
  FILE *f1, *f2;
  char c;
  int n;
  f1 = fopen("source.txt", "r");
  f2 = fopen("dest.txt", "w");
  n = 1;
  while ((c = fgetc(f1)) != EOF) {
    if (n == 1) {
      fprintf(f2, "%06d ", n);
      n++;
    }
    if ((c == '\n')) {
      fputc(c, f2);
      fprintf(f2, "%06d ", n);
      n++;
    } else {
      fputc(c, f2);
    }
  }
  fclose(f1);
  fclose(f2);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe90(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2e3e(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     122c <main+0xdc>
cmpl   $0x1,-0x20(%rbp)
jne    11db <main+0x8b>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe4b(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0xa,%eax
jne    1218 <main+0xc8>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe13(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1227 <main+0xd7>
mov    -0x19(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
jmp    1194 <main+0x44>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rdi
lea    0xea2(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r14
lea    0xe95(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e52(%rip),%r13
cmp    0x0(%r13),%al
jne    11bd <main+0x6d>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%ebx
mov    $0x1,%ebp
lea    0xe4d(%rip),%r15
jmp    11eb <main+0x9b>
nopl   (%rax)
movsbl %bl,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%al
je     119c <main+0x4c>
cmp    $0x1,%ebp
je     1200 <main+0xb0>
cmp    $0xa,%bl
jne    11d0 <main+0x80>
jmp    121a <main+0xca>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1060 <fprintf@plt>
mov    $0x2,%ebp
cmp    $0xa,%bl
jne    11d0 <main+0x80>
mov    $0xa,%edi
mov    %r12,%rsi
call   1050 <fputc@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
add    $0x1,%ebp
jmp    11db <main+0x8b>

LLVM IR (-O0):
@.str = [11 x i8] c"source.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"dest.txt\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.4 = [6 x i8] c"%06d \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i8
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
%7 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %3
store i32 1, i32* %5
br label %8
8: ; preds = %41, %0
%9 = load i32*, i32** %2
%10 = call signext i8 @fgetc(i32* %9)
store i8 %10, i8* %4
%11 = sext i8 %10 to i32
%12 = load i8, i8* @EOF
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %11, %13
br i1 %14, label %15, label %42
15: ; preds = %8
%16 = load i32, i32* %5
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = call i32 @fprintf(i32* %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %24
24: ; preds = %18, %15
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 10
br i1 %27, label %28, label %37
28: ; preds = %24
%29 = load i8, i8* %4
%30 = load i32*, i32** %3
%31 = call i32 @fputc(i8 signext %29, i32* %30)
%32 = load i32*, i32** %3
%33 = load i32, i32* %5
%34 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %41
37: ; preds = %24
%38 = load i8, i8* %4
%39 = load i32*, i32** %3
%40 = call i32 @fputc(i8 signext %38, i32* %39)
br label %41
41: ; preds = %37, %28
br label %8
42: ; preds = %8
%43 = load i32*, i32** %2
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [11 x i8] c"source.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"dest.txt\00"
@.str.3 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.4 = [6 x i8] c"%06d \00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%3 = tail call signext i8 @fgetc(i32* %1)
%4 = load i8, i8* @EOF
%5 = icmp eq i8 %3, %4
br i1 %5, label %26, label %6
6: ; preds = %0, %21
%7 = phi i8 [ %23, %21 ], [ %3, %0 ]
%8 = phi i32 [ %22, %21 ], [ 1, %0 ]
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %12
12: ; preds = %10, %6
%13 = phi i32 [ 2, %10 ], [ %8, %6 ]
%14 = icmp eq i8 %7, 10
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = tail call i32 @fputc(i8 signext 10, i32* %2)
%17 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%18 = add nsw i32 %13, 1
br label %21
19: ; preds = %12
%20 = tail call i32 @fputc(i8 signext %7, i32* %2)
br label %21
21: ; preds = %19, %15
%22 = phi i32 [ %18, %15 ], [ %13, %19 ]
%23 = tail call signext i8 @fgetc(i32* %1)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %6
26: ; preds = %21, %0
%27 = tail call i32 @fclose(i32* %1)
%28 = tail call i32 @fclose(i32* %2)
ret i32 0
}