#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 **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  FILE *fp;
  char *filename = "/etc/passwd";
  char *setmode = "r";
  char *line = NULL;
  size_t 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)
lea    0xe7a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe7b(%rip),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e7 <main+0x77>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11ec <main+0x7c>
mov    -0x10(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1221 <main+0xb1>
mov    -0x34(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xe06(%rip),%rdi
call   1050 <printf@plt>
jmp    11ec <main+0x7c>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d96(%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,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xe6c(%rip),%rdi
lea    0xe71(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1219 <main+0xa9>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     11f2 <main+0x82>
lea    0xe57(%rip),%r14
lea    0x8(%rsp),%r15
lea    0x10(%rsp),%r12
mov    0x8(%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    0x8(%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() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4
store i8* null, i8** %5
store i64 0, i64* %6
%8 = load i8*, i8** %3
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %8, i8* %9)
store i32* %10, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
br label %19
19: ; preds = %23, %18
%20 = load i32*, i32** %2
%21 = call i32 @getline(i8** %5, i64* %6, i32* %20)
store i32 %21, i32* %7
%22 = icmp ne i32 %21, -1
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* %7
%25 = load i8*, i8** %5
%26 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %25)
br label %19
27: ; preds = %19
%28 = load i8*, i8** %5
%29 = call i32 @free(i8* %28)
%30 = load i32*, i32** %2
%31 = call i32 @fclose(i32* %30)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}

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() {
%1 = alloca i8*
%2 = alloca i64
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = 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))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = call i32 @getline(i8** %1, i64* %2, i32* %5)
%9 = icmp eq i32 %8, -1
br i1 %9, label %21, label %15
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, 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))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %7, %15
%16 = phi i32 [ %19, %15 ], [ %8, %7 ]
%17 = load i8*, i8** %1
%18 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %16, i8* %17)
%19 = call i32 @getline(i8** %1, i64* %2, i32* %5)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %15
21: ; preds = %15, %7
%22 = load i8*, i8** %1
%23 = call i32 @free(i8* %22)
%24 = call i32 @fclose(i32* %5)
%25 = load i32, i32* @EXIT_SUCCESS
ret i32 %25
}