#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
scalar_t__ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdout;
void print_source() {
  FILE *source = fopen("echo.c", "r");
  if (source == NULL) {
    perror("fopen");
    printf("Unable to get source code!");
    return;
  }
  char *buf = NULL;
  size_t len = 0;
  while (getline(&buf, &len, source) > 0) {
    fputs(buf, stdout);
  }
  fclose(source);
}


x86 assembly (clang, -O0):
<print_source>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe91(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a7 <print_source+0x47>
lea    0xe78(%rip),%rdi
call   1070 <perror@plt>
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
jmp    11f2 <print_source+0x92>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
cmp    $0x0,%rax
jle    11e9 <print_source+0x89>
mov    -0x10(%rbp),%rdi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
call   1050 <fputs@plt>
jmp    11b7 <print_source+0x57>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_source>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe8e(%rip),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f5 <print_source+0x95>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
test   %rax,%rax
jle    11e1 <print_source+0x81>
mov    0x2e2a(%rip),%r12
lea    0x8(%rsp),%r14
lea    0x10(%rsp),%r15
mov    0x8(%rsp),%rdi
mov    (%r12),%esi
call   1050 <fputs@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
test   %rax,%rax
jg     11c0 <print_source+0x60>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
lea    0xe07(%rip),%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"echo.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [27 x i8] c"Unable to get source code!\00"
@stdout = global i32 0
define void @print_source() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i64
%4 = call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %22
10: ; preds = %0
store i8* null, i8** %2
store i64 0, i64* %3
br label %11
11: ; preds = %15, %10
%12 = load i32*, i32** %1
%13 = call i64 @getline(i8** %2, i64* %3, i32* %12)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = load i32, i32* @stdout
%18 = call i32 @fputs(i8* %16, i32 %17)
br label %11
19: ; preds = %11
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
br label %22
22: ; preds = %19, %7
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"echo.c\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [6 x i8] c"fopen\00"
@.str.3 = [27 x i8] c"Unable to get source code!\00"
@stdout = global i32 0
define void @print_source() {
%1 = alloca i8*
%2 = alloca i64
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
br label %21
8: ; preds = %0
%9 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%10 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%11 = call i64 @getline(i8** %1, i64* %2, i32* %3)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %8, %13
%14 = load i8*, i8** %1
%15 = load i32, i32* @stdout
%16 = call i32 @fputs(i8* %14, i32 %15)
%17 = call i64 @getline(i8** %1, i64* %2, i32* %3)
%18 = icmp sgt i64 %17, 0
br i1 %18, label %13, label %19
19: ; preds = %13, %8
%20 = call i32 @fclose(i32* %3)
br label %21
21: ; preds = %19, %5
ret void
}