#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 errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int);
void do_paste(const char *path) {
  FILE *file = fopen(path, "r");
  char *line = NULL;
  size_t len = 0;
  ssize_t read = 0;
  if (file) {
    while ((read = getline(&line, &len, file)) != -1) {
      printf("%s\n", line);
    }
    if (line) {
      free(line);
    }
    fflush(file);
    fclose(file);
  } else {
    if (errno != 2) {
      printf("error: %d : %s\n", errno, strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<do_paste>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1216 <do_paste+0xa6>
jmp    11b7 <do_paste+0x47>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     11eb <do_paste+0x7b>
mov    -0x18(%rbp),%rsi
lea    0xe2f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11b7 <do_paste+0x47>
cmpq   $0x0,-0x18(%rbp)
je     11ff <do_paste+0x8f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1259 <do_paste+0xe9>
mov    0x2dc3(%rip),%rax
cmpl   $0x2,(%rax)
je     1254 <do_paste+0xe4>
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x28(%rbp),%esi
mov    %rax,%rdx
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1259 <do_paste+0xe9>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_paste>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xe70(%rip),%rsi
call   1080 <fopen@plt>
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
test   %rax,%rax
je     120c <do_paste+0x8c>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
je     11ec <do_paste+0x6c>
mov    %rsp,%r14
lea    0x8(%rsp),%r15
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <getline@plt>
cmp    $0xffffffff,%eax
jne    11d0 <do_paste+0x50>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11fa <do_paste+0x7a>
call   1030 <free@plt>
mov    %rbx,%rdi
call   1070 <fflush@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    121a <do_paste+0x9a>
mov    0x2dcd(%rip),%rax
mov    (%rax),%ebx
cmp    $0x2,%ebx
jne    1224 <do_paste+0xa4>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %ebx,%edi
call   10a0 <strerror@plt>
lea    0xdd0(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <printf@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"error: %d : %s\0A\00"
define void @do_paste(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
store i8* null, i8** %4
store i64 0, i64* %5
store i32 0, i32* %6
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %30
11: ; preds = %1
br label %12
12: ; preds = %16, %11
%13 = load i32*, i32** %3
%14 = call i32 @getline(i8** %4, i64* %5, i32* %13)
store i32 %14, i32* %6
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %12
19: ; preds = %12
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %22, %19
%26 = load i32*, i32** %3
%27 = call i32 @fflush(i32* %26)
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
br label %39
30: ; preds = %1
%31 = load i32, i32* @errno
%32 = icmp ne i32 %31, 2
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %34, i8* %36)
br label %38
38: ; preds = %33, %30
br label %39
39: ; preds = %38, %25
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@errno = global i32 0
@.str.2 = [16 x i8] c"error: %d : %s\0A\00"
define void @do_paste(i8* nocapture %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = icmp eq i32* %4, null
br i1 %7, label %24, label %8
8: ; preds = %1
%9 = call i32 @getline(i8** %2, i64* %3, i32* %4)
%10 = icmp eq i32 %9, -1
br i1 %10, label %16, label %11
11: ; preds = %8, %11
%12 = load i8*, i8** %2
%13 = call i32 @puts(i8* dereferenceable(1) %12)
%14 = call i32 @getline(i8** %2, i64* %3, i32* %4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %11
16: ; preds = %11, %8
%17 = load i8*, i8** %2
%18 = icmp eq i8* %17, null
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = call i32 @free(i8* %17)
br label %21
21: ; preds = %19, %16
%22 = call i32 @fflush(i32* %4)
%23 = call i32 @fclose(i32* %4)
br label %30
24: ; preds = %1
%25 = load i32, i32* @errno
%26 = icmp eq i32 %25, 2
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = tail call i8* @strerror(i32 %25)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %25, i8* %28)
br label %30
30: ; preds = %24, %27, %21
ret void
}