#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdin;
int main() {
  unsigned int position = 1;
  char *line = NULL;
  size_t size;
  while (getline(&line, &size, stdin) != -1) {
    printf("%04u: %s", position++, line);
  }
  if (line)
    free(line);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0x2e93(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     118d <main+0x5d>
mov    -0x8(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rdx
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
jmp    114e <main+0x1e>
cmpq   $0x0,-0x10(%rbp)
je     11a1 <main+0x71>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
mov    0x2e9d(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11a5 <main+0x75>
mov    $0x1,%esi
lea    0xe93(%rip),%r14
mov    %rsp,%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x1(%rsi),%ebp
mov    (%rsp),%rdx
mov    %r14,%rdi
call   1040 <printf@plt>
mov    (%r12),%edx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <getline@plt>
mov    %ebp,%esi
cmp    $0xffffffff,%eax
jne    1180 <main+0x50>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11b3 <main+0x83>
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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