#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*/ *fidopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int LineEnum(size_t argc, const char **argv) {
  char c;
  FILE *fin = fidopen(0, "r");
  FILE *fout = fidopen(1, "w");
  int atend = 1;
  size_t count = 0;
  while ((c = fgetc(fin)) != EOF) {
    if (atend) {
      count++;
      fprintf(fout, "%6zu: ", count);
      atend = 0;
    }
    fputc(c, fout);
    if (c == '\n')
      atend = 1;
  }
  fclose(fin);
  fclose(fout);
  return 0;
}


x86 assembly (clang, -O0):
<LineEnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %edi,%edi
lea    0xe97(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x1,%edi
lea    0xe84(%rip),%rsi
call   1070 <fidopen@plt>
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    0x2e3c(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1210 <LineEnum+0xc0>
cmpl   $0x0,-0x2c(%rbp)
je     11e8 <LineEnum+0x98>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rdx
lea    0xe28(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x11(%rbp),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    120b <LineEnum+0xbb>
movl   $0x1,-0x2c(%rbp)
jmp    1196 <LineEnum+0x46>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LineEnum>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9e(%rip),%rsi
xor    %edi,%edi
call   1070 <fidopen@plt>
mov    %rax,%r14
lea    0xe8f(%rip),%rsi
mov    $0x1,%r12d
mov    $0x1,%edi
call   1070 <fidopen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e53(%rip),%rbp
cmp    0x0(%rbp),%al
jne    11bb <LineEnum+0x6b>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%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
xor    %r13d,%r13d
jmp    11f6 <LineEnum+0xa6>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %bl,%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   1050 <fputc@plt>
xor    %r12d,%r12d
cmp    $0xa,%bl
sete   %r12b
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    %eax,%ebx
cmp    0x0(%rbp),%al
je     119a <LineEnum+0x4a>
test   %r12d,%r12d
je     11d0 <LineEnum+0x80>
add    $0x1,%r13
mov    %r15,%rdi
lea    0xdfb(%rip),%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
jmp    11d0 <LineEnum+0x80>

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

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