#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;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  while ((read = getline(&line, &len, stdin)) != -1) {
    printf("Retrieved line of length %zu :\n", read);
    printf("%s", line);
  }
  if (line) {
    free(line);
  }
  exit(EXIT_SUCCESS);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11b0 <main+0x70>
mov    -0x24(%rbp),%esi
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1166 <main+0x26>
cmpq   $0x0,-0x18(%rbp)
je     11c4 <main+0x84>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e83(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
je     11ce <main+0x8e>
lea    0xe7e(%rip),%r14
lea    0xe97(%rip),%r15
mov    %rsp,%r12
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rsp),%rsi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x0(%r13),%edx
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <getline@plt>
cmp    $0xffffffff,%eax
jne    11a0 <main+0x60>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11dc <main+0x9c>
call   1030 <free@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stdin = global i32 0
@.str = [32 x i8] c"Retrieved line of length %zu :\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
br label %9
9: ; preds = %13, %2
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %6, i64* %7, i32 %10)
store i32 %11, i32* %8
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load i32, i32* %8
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %9
18: ; preds = %9
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = call i32 @free(i8* %22)
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [32 x i8] c"Retrieved line of length %zu :\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %3, i64* %4, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %18, label %10
10: ; preds = %2, %10
%11 = phi i32 [ %16, %10 ], [ %8, %2 ]
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %3
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @stdin
%16 = call i32 @getline(i8** %3, i64* %4, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %10
18: ; preds = %10, %2
%19 = load i8*, i8** %3
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %18
%22 = call i32 @free(i8* %19)
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* @EXIT_SUCCESS
%25 = call i32 @exit(i32 %24)
unreachable
}