#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 /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int readf(void) {
  FILE *fp;
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  char input[256];
  printf("\n file destination:");
  scanf("%s", input);
  fp = fopen(input, "r");
  if (fp == NULL)
    exit(EXIT_FAILURE);
  while ((read = getline(&line, &len, fp)) != -1) {
    printf("%s", line);
  }
  fclose(fp);
  if (line)
    free(line);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<readf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x120(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11dc <readf+0x6c>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    11e1 <readf+0x71>
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1215 <readf+0xa5>
mov    -0x10(%rbp),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11e1 <readf+0x71>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x10(%rbp)
je     1232 <readf+0xc2>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<readf>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe6a(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe5f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
jne    11d3 <readf+0x63>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     1221 <readf+0xb1>
lea    0xe22(%rip),%r14
mov    %rsp,%r15
lea    0x8(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
jne    1200 <readf+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1237 <readf+0xc7>
call   1030 <free@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"\0A file destination:\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @readf() {
%1 = alloca i32*
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
%5 = alloca [256 x i8]
store i8* null, i8** %2
store i64 0, i64* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %10, i32** %1
%11 = load i32*, i32** %1
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %0
br label %17
17: ; preds = %21, %16
%18 = load i32*, i32** %1
%19 = call i32 @getline(i8** %2, i64* %3, i32* %18)
store i32 %19, i32* %4
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i8*, i8** %2
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %17
24: ; preds = %17
%25 = load i32*, i32** %1
%26 = call i32 @fclose(i32* %25)
%27 = load i8*, i8** %2
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i8*, i8** %2
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %29, %24
%33 = load i32, i32* @EXIT_SUCCESS
%34 = call i32 @exit(i32 %33)
unreachable
}

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