#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 */
struct buffer {
  int dummy;
};

/* Variables and functions */
int EOF;
int /*<<< orphan*/ add1_buffer(struct buffer *, char);
int add_then_next(struct buffer *, int);
int in_nonblank();
struct buffer *init_buffer();
struct buffer *read_filename(void) {
  struct buffer *b;
  int ch;
  b = init_buffer();
  ch = in_nonblank();
  while (ch != EOF && ch != '\n') {
    ch = add_then_next(b, ch);
  }
  add1_buffer(b, '\0');
  return b;
}


x86 assembly (clang, -O0):
<read_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <init_buffer@plt>
mov    %rax,-0x8(%rbp)
mov    $0x0,%al
call   1060 <in_nonblank@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
mov    0x2e7f(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xd(%rbp)
je     117e <read_filename+0x3e>
cmpl   $0xa,-0xc(%rbp)
setne  %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    118e <read_filename+0x4e>
jmp    11a2 <read_filename+0x62>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <add_then_next@plt>
mov    %eax,-0xc(%rbp)
jmp    115d <read_filename+0x1d>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1050 <add1_buffer@plt>
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_filename>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <init_buffer@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1060 <in_nonblank@plt>
cmp    $0xa,%eax
je     1184 <read_filename+0x44>
mov    0x2e87(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    (%r14),%eax
je     1184 <read_filename+0x44>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <add_then_next@plt>
cmp    $0xa,%eax
jne    1170 <read_filename+0x30>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <add1_buffer@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
@EOF = global i32 0
define %struct.buffer* @read_filename() {
%1 = alloca %struct.buffer*
%2 = alloca i32
%3 = call %struct.buffer* (...) @init_buffer()
store %struct.buffer* %3, %struct.buffer** %1
%4 = call i32 (...) @in_nonblank()
store i32 %4, i32* %2
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %2
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 10
br label %12
12: ; preds = %9, %5
%13 = phi i1 [ false, %5 ], [ %11, %9 ]
br i1 %13, label %14, label %18
14: ; preds = %12
%15 = load %struct.buffer*, %struct.buffer** %1
%16 = load i32, i32* %2
%17 = call i32 @add_then_next(%struct.buffer* %15, i32 %16)
store i32 %17, i32* %2
br label %5
18: ; preds = %12
%19 = load %struct.buffer*, %struct.buffer** %1
%20 = call i32 @add1_buffer(%struct.buffer* %19, i8 signext 0)
%21 = load %struct.buffer*, %struct.buffer** %1
ret %struct.buffer* %21
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
@EOF = global i32 0
define %struct.buffer* @read_filename() {
%1 = tail call %struct.buffer* (...) @init_buffer()
%2 = tail call i32 (...) @in_nonblank()
%3 = load i32, i32* @EOF
%4 = icmp ne i32 %2, %3
%5 = icmp ne i32 %2, 10
%6 = and i1 %5, %4
br i1 %6, label %7, label %14
7: ; preds = %0, %7
%8 = phi i32 [ %9, %7 ], [ %2, %0 ]
%9 = tail call i32 @add_then_next(%struct.buffer* %1, i32 %8)
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
%12 = icmp ne i32 %9, 10
%13 = and i1 %12, %11
br i1 %13, label %7, label %14
14: ; preds = %7, %0
%15 = tail call i32 @add1_buffer(%struct.buffer* %1, i8 signext 0)
ret %struct.buffer* %1
}