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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char *);
void printLines(FILE *input) {
  char *line;
  ssize_t read;
  size_t len;
  int l = 0;
  while ((read = getline(&line, &len, input)) != -1) {
    printf("%d:\t%s", l++, line);
  }
  if (line != NULL) {
    free(line);
  }
}


x86 assembly (clang, -O0):
<printLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1180 <printLines+0x50>
mov    -0x24(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe8a(%rip),%rdi
call   1040 <printf@plt>
jmp    1143 <printLines+0x13>
cmpq   $0x0,-0x10(%rbp)
je     1194 <printLines+0x64>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printLines>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     1194 <printLines+0x64>
xor    %esi,%esi
lea    0xea3(%rip),%r14
mov    %rsp,%r15
lea    0x8(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rsi),%ebp
mov    (%rsp),%rdx
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1050 <getline@plt>
mov    %ebp,%esi
cmp    $0xffffffff,%eax
jne    1170 <printLines+0x40>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11a2 <printLines+0x72>
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%d:\09%s\00"
define void @printLines(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %2
store i32 0, i32* %6
br label %7
7: ; preds = %11, %1
%8 = load i32*, i32** %2
%9 = call i32 @getline(i8** %3, i64* %5, i32* %8)
store i32 %9, i32* %4
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* %6
%13 = add nsw i32 %12, 1
store i32 %13, i32* %6
%14 = load i8*, i8** %3
%15 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %12, i8* %14)
br label %7
16: ; preds = %7
%17 = load i8*, i8** %3
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i32 @free(i8* %20)
br label %22
22: ; preds = %19, %16
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%d:\09%s\00"
define void @printLines(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
%5 = bitcast i64* %3 to i8*
%6 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %15, label %8
8: ; preds = %1, %8
%9 = phi i32 [ %10, %8 ], [ 0, %1 ]
%10 = add nuw nsw i32 %9, 1
%11 = load i8*, i8** %2
%12 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %9, i8* %11)
%13 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %8
15: ; preds = %8, %1
%16 = load i8*, i8** %2
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @free(i8* %16)
br label %20
20: ; preds = %18, %15
ret void
}