#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*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  fp = fopen("/etc/motd", "r");
  line = (char *)malloc(1024 * sizeof(char));
  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,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe73(%rip),%rdi
lea    0xe76(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     11f5 <main+0x95>
mov    -0x2c(%rbp),%esi
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ab <main+0x4b>
cmpq   $0x0,-0x20(%rbp)
je     1209 <main+0xa9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe83(%rip),%rdi
lea    0xe86(%rip),%rsi
call   1060 <fopen@plt>
mov    $0x400,%edi
call   1050 <malloc@plt>
mov    %rax,(%rsp)
mov    0x2e4a(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1070 <getline@plt>
cmp    $0xffffffff,%eax
je     11fe <main+0x9e>
lea    0xe51(%rip),%r14
lea    0xe6a(%rip),%r15
mov    %rsp,%r12
lea    0x8(%rsp),%rbx
nopw   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   1070 <getline@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x70>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     120c <main+0xac>
call   1030 <free@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/etc/motd\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [32 x i8] c"Retrieved line of length %zu :\0A\00"
@.str.3 = [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 i32*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
store i64 0, i64* %8
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %6
%11 = call i64 @malloc(i32 1024)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
br label %13
13: ; preds = %17, %2
%14 = load i32, i32* @stdin
%15 = call i32 @getline(i8** %7, i64* %8, i32 %14)
store i32 %15, i32* %9
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load i8*, i8** %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20)
br label %13
22: ; preds = %13
%23 = load i8*, i8** %7
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %7
%27 = call i32 @free(i8* %26)
br label %28
28: ; preds = %25, %22
%29 = load i32, i32* @EXIT_SUCCESS
%30 = call i32 @exit(i32 %29)
unreachable
}

LLVM IR (-O2):
@.str = [10 x i8] c"/etc/motd\00"
@.str.1 = [2 x i8] c"r\00"
@stdin = global i32 0
@.str.2 = [32 x i8] c"Retrieved line of length %zu :\0A\00"
@.str.3 = [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*
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i64 @malloc(i32 1024)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %3, i64* %4, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %21, label %13
13: ; preds = %2, %13
%14 = phi i32 [ %19, %13 ], [ %11, %2 ]
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @stdin
%19 = call i32 @getline(i8** %3, i64* %4, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %13
21: ; preds = %13, %2
%22 = load i8*, i8** %3
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = call i32 @free(i8* %22)
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
}