#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
unsigned int getline(char **, int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  FILE *fp;
  char *filename = "/etc/passwd";
  char *setmode = "r";
  char *line = NULL;
  int len = 0;
  unsigned int read;
  if ((fp = fopen(filename, setmode)) == NULL) {
    fprintf(stderr, "%s: Open file\n", filename);
    exit(EXIT_FAILURE);
  }
  while ((read = getline(&line, &len, fp)) != -1)
    printf("(len: %u) %s", read, line);
  free(line);
  fclose(fp);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe74(%rip),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ed <main+0x7d>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe34(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11f2 <main+0x82>
mov    -0x18(%rbp),%rdx
lea    -0x30(%rbp),%rdi
lea    -0x34(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
je     1227 <main+0xb7>
mov    -0x38(%rbp),%esi
mov    -0x30(%rbp),%rdx
lea    0xe00(%rip),%rdi
call   1050 <printf@plt>
jmp    11f2 <main+0x82>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xe6d(%rip),%rdi
lea    0xe72(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1219 <main+0xa9>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     11f2 <main+0x82>
lea    0xe58(%rip),%r14
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%r12
nop
mov    0x10(%rsp),%rdx
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x60>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
lea    0xdd0(%rip),%rdx
call   1060 <fprintf@plt>
mov    0x2d9c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"%s: Open file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"(len: %u) %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 i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* null, i8** %9
store i32 0, i32* %10
%12 = load i8*, i8** %7
%13 = load i8*, i8** %8
%14 = call i32* @fopen(i8* %12, i8* %13)
store i32* %14, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %7
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
br label %23
23: ; preds = %27, %22
%24 = load i32*, i32** %6
%25 = call i32 @getline(i8** %9, i32* %10, i32* %24)
store i32 %25, i32* %11
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %23
%28 = load i32, i32* %11
%29 = load i8*, i8** %9
%30 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %28, i8* %29)
br label %23
31: ; preds = %23
%32 = load i8*, i8** %9
%33 = call i32 @free(i8* %32)
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}

LLVM IR (-O2):
@.str = [12 x i8] c"/etc/passwd\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [15 x i8] c"%s: Open file\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [13 x i8] c"(len: %u) %s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%7 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @getline(i8** %3, i32* %4, i32* %7)
%11 = icmp eq i32 %10, -1
br i1 %11, label %23, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %9, %17
%18 = phi i32 [ %21, %17 ], [ %10, %9 ]
%19 = load i8*, i8** %3
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %18, i8* %19)
%21 = call i32 @getline(i8** %3, i32* %4, i32* %7)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %17
23: ; preds = %17, %9
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = call i32 @fclose(i32* %7)
%27 = load i32, i32* @EXIT_SUCCESS
ret i32 %27
}