#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 */

/* Variables and functions */
int EOF;
int getchar();
char *malloc(int);
int /*<<< orphan*/ read_by_char(int, char **, int *, int *);
char *ask_for_file(void) {
  int c, charCount = 0, bytes = 1;
  char *filename;
  filename = malloc(sizeof(char) * bytes);
  while ((c = getchar()) != EOF && c != '\n')
    read_by_char(c, &filename, &charCount, &bytes);
  return filename;
}


x86 assembly (clang, -O0):
<ask_for_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x4(%rbp)
xor    %eax,%eax
mov    0x2e7a(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     1183 <ask_for_file+0x53>
cmpl   $0xa,-0x4(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1193 <ask_for_file+0x63>
jmp    11ac <ask_for_file+0x7c>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rcx
call   1050 <read_by_char@plt>
jmp    1159 <ask_for_file+0x29>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_for_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x0,0xc(%rsp)
movl   $0x1,0x8(%rsp)
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
mov    %rax,0x10(%rsp)
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     11b7 <ask_for_file+0x87>
mov    0x2e78(%rip),%r12
cmp    (%r12),%eax
je     11b7 <ask_for_file+0x87>
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1050 <read_by_char@plt>
xor    %eax,%eax
call   1030 <getchar@plt>
cmp    $0xa,%eax
je     11b2 <ask_for_file+0x82>
cmp    (%r12),%eax
jne    1190 <ask_for_file+0x60>
mov    0x10(%rsp),%rbx
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@EOF = global i32 0
define i8* @ask_for_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
store i32 0, i32* %2
store i32 1, i32* %3
%5 = load i32, i32* %3
%6 = sext i32 %5 to i64
%7 = mul i64 1, %6
%8 = trunc i64 %7 to i32
%9 = call i8* @malloc(i32 %8)
store i8* %9, i8** %4
br label %10
10: ; preds = %19, %0
%11 = call i32 (...) @getchar()
store i32 %11, i32* %1
%12 = load i32, i32* @EOF
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %1
%16 = icmp ne i32 %15, 10
br label %17
17: ; preds = %14, %10
%18 = phi i1 [ false, %10 ], [ %16, %14 ]
br i1 %18, label %19, label %22
19: ; preds = %17
%20 = load i32, i32* %1
%21 = call i32 @read_by_char(i32 %20, i8** %4, i32* %2, i32* %3)
br label %10
22: ; preds = %17
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
@EOF = global i32 0
define i8* @ask_for_file() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%5 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%6 = bitcast i8** %3 to i8*
%7 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8* %7, i8** %3
%8 = call i32 (...) @getchar()
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
%11 = icmp ne i32 %8, 10
%12 = and i1 %11, %10
br i1 %12, label %13, label %23
13: ; preds = %0, %13
%14 = phi i32 [ %16, %13 ], [ %8, %0 ]
%15 = call i32 @read_by_char(i32 %14, i8** %3, i32* %1, i32* %2)
%16 = call i32 (...) @getchar()
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
%19 = icmp ne i32 %16, 10
%20 = and i1 %19, %18
br i1 %20, label %13, label %21
21: ; preds = %13
%22 = load i8*, i8** %3
br label %23
23: ; preds = %21, %0
%24 = phi i8* [ %22, %21 ], [ %7, %0 ]
ret i8* %24
}