#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 readbyte(int, char *);
void getfilename(int fd, char *name) {
  char ch;
  int ret;
  do {
    ret = readbyte(fd, &ch);
  } while (ch == ' ' && ret == 1);
  while (ret == 1 && ch > ' ') {
    *name++ = ch;
    ret = readbyte(fd, &ch);
  }
  *name++ = 0;
}


x86 assembly (clang, -O0):
<getfilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
call   1030 <readbyte@plt>
mov    %eax,-0x18(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0x20,%ecx
mov    %al,-0x19(%rbp)
jne    114a <getfilename+0x3a>
cmpl   $0x1,-0x18(%rbp)
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    111f <getfilename+0xf>
jmp    115a <getfilename+0x4a>
xor    %eax,%eax
cmpl   $0x1,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
jne    1176 <getfilename+0x66>
movsbl -0x11(%rbp),%eax
cmp    $0x20,%eax
setg   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%al
test   $0x1,%al
jne    1186 <getfilename+0x76>
jmp    11ae <getfilename+0x9e>
mov    -0x11(%rbp),%cl
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x10(%rbp)
mov    %cl,(%rax)
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
call   1030 <readbyte@plt>
mov    %eax,-0x18(%rbp)
jmp    115a <getfilename+0x4a>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getfilename>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xf(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <readbyte@plt>
movzbl 0xf(%rsp),%ecx
cmp    $0x20,%cl
jne    1149 <getfilename+0x39>
cmp    $0x1,%eax
je     1130 <getfilename+0x20>
cmp    $0x1,%eax
jne    117f <getfilename+0x6f>
cmp    $0x21,%cl
jl     117f <getfilename+0x6f>
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %cl,(%rbx)
add    $0x1,%rbx
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <readbyte@plt>
cmp    $0x1,%eax
jne    117f <getfilename+0x6f>
movzbl 0xf(%rsp),%ecx
cmp    $0x20,%cl
jg     1160 <getfilename+0x50>
movb   $0x0,(%rbx)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @getfilename(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
br label %7
7: ; preds = %17, %2
%8 = load i32, i32* %3
%9 = call i32 @readbyte(i32 %8, i8* %5)
store i32 %9, i32* %6
br label %10
10: ; preds = %7
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 32
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, 1
br label %17
17: ; preds = %14, %10
%18 = phi i1 [ false, %10 ], [ %16, %14 ]
br i1 %18, label %7, label %19
19: ; preds = %17
br label %20
20: ; preds = %29, %19
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 1
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load i8, i8* %5
%25 = sext i8 %24 to i32
%26 = icmp sgt i32 %25, 32
br label %27
27: ; preds = %23, %20
%28 = phi i1 [ false, %20 ], [ %26, %23 ]
br i1 %28, label %29, label %35
29: ; preds = %27
%30 = load i8, i8* %5
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
store i8 %30, i8* %31
%33 = load i32, i32* %3
%34 = call i32 @readbyte(i32 %33, i8* %5)
store i32 %34, i32* %6
br label %20
35: ; preds = %27
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
store i8 0, i8* %36
ret void
}

LLVM IR (-O2):
define void @getfilename(i32 %0, i8* nocapture writeonly %1) {
%3 = alloca i8
br label %4
4: ; preds = %4, %2
%5 = call i32 @readbyte(i32 %0, i8* %3)
%6 = load i8, i8* %3
%7 = icmp eq i8 %6, 32
%8 = icmp eq i32 %5, 1
%9 = select i1 %7, i1 %8, i1 false
br i1 %9, label %4, label %10
10: ; preds = %4
%11 = icmp sgt i8 %6, 32
%12 = select i1 %8, i1 %11, i1 false
br i1 %12, label %13, label %22
13: ; preds = %10, %13
%14 = phi i8 [ %19, %13 ], [ %6, %10 ]
%15 = phi i8* [ %16, %13 ], [ %1, %10 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 %14, i8* %15
%17 = call i32 @readbyte(i32 %0, i8* %3)
%18 = icmp eq i32 %17, 1
%19 = load i8, i8* %3
%20 = icmp sgt i8 %19, 32
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %13, label %22
22: ; preds = %13, %10
%23 = phi i8* [ %1, %10 ], [ %16, %13 ]
store i8 0, i8* %23
ret void
}