#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_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 *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <file>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  FILE *stream = fopen(argv[1], "r");
  if (stream == NULL) {
    perror("fopen");
    exit(EXIT_FAILURE);
  }
  char *line = NULL;
  size_t len = 0;
  ssize_t nread;
  while ((nread = getline(&line, &len, stream)) != -1) {
    printf("[%zu] '", nread);
    fwrite(line, nread, 1, stdout);
    printf("'\n");
  }
  free(line);
  fclose(stream);
  return EXIT_SUCCESS;
}


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)
cmpl   $0x2,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe29(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1217 <main+0x87>
lea    0xe10(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1090 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
je     1282 <main+0xf2>
mov    -0x2c(%rbp),%esi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x2d6d(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1227 <main+0x97>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    128b <main+0xeb>
mov    0x8(%rsi),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a5 <main+0x105>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   10a0 <getline@plt>
cmp    $0xffffffff,%eax
je     1261 <main+0xc1>
mov    %eax,%ebp
mov    0x2dcb(%rip),%r14
lea    0xe14(%rip),%r15
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
lea    0xdf3(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rsp),%rdi
mov    (%r14),%ecx
mov    %ebp,%esi
mov    $0x1,%edx
call   10c0 <fwrite@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1220 <main+0x80>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd62(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12b1 <main+0x111>
lea    0xd68(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [8 x i8] c"[%zu] '\00"
@stdout = global i32 0
@.str.4 = [3 x i8] c"'\0A\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
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %20
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %20
store i8* null, i8** %7
store i64 0, i64* %8
br label %32
32: ; preds = %36, %31
%33 = load i32*, i32** %6
%34 = call i32 @getline(i8** %7, i64* %8, i32* %33)
store i32 %34, i32* %9
%35 = icmp ne i32 %34, -1
br i1 %35, label %36, label %44
36: ; preds = %32
%37 = load i32, i32* %9
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %7
%40 = load i32, i32* %9
%41 = load i32, i32* @stdout
%42 = call i32 @fwrite(i8* %39, i32 %40, i32 1, i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %32
44: ; preds = %32
%45 = load i8*, i8** %7
%46 = call i32 @free(i8* %45)
%47 = load i32*, i32** %6
%48 = call i32 @fclose(i32* %47)
%49 = load i32, i32* @EXIT_SUCCESS
ret i32 %49
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <file>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [8 x i8] c"[%zu] '\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [2 x i8] c"'\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = icmp eq i32 %0, 2
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = tail call i32 @exit(i32 %19)
unreachable
21: ; preds = %12
%22 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%23 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%24 = call i32 @getline(i8** %3, i64* %4, i32* %15)
%25 = icmp eq i32 %24, -1
br i1 %25, label %35, label %26
26: ; preds = %21, %26
%27 = phi i32 [ %33, %26 ], [ %24, %21 ]
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %3
%30 = load i32, i32* @stdout
%31 = call i32 @fwrite(i8* %29, i32 %27, i32 1, i32 %30)
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%33 = call i32 @getline(i8** %3, i64* %4, i32* %15)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %26
35: ; preds = %26, %21
%36 = load i8*, i8** %3
%37 = call i32 @free(i8* %36)
%38 = call i32 @fclose(i32* %15)
%39 = load i32, i32* @EXIT_SUCCESS
ret i32 %39
}