#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 getc(int /*<<< orphan*/ *);
char *ReadName(FILE *fp, char *name) {
  int l = 32;
  int c;
  char *p;
  p = name;
  while ((c = getc(fp)) && (l--)) {
    *p++ = c;
  }
  *p = 0;
  return name;
}


x86 assembly (clang, -O0):
<ReadName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x20,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     115f <ReadName+0x4f>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    116f <ReadName+0x5f>
jmp    118a <ReadName+0x7a>
mov    -0x18(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    112f <ReadName+0x1f>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadName>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <getc@plt>
mov    %r14,%rcx
test   %eax,%eax
je     114f <ReadName+0x3f>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %al,(%r14,%rbx,1)
mov    %r15,%rdi
call   1030 <getc@plt>
lea    0x1(%rbx),%rcx
test   %eax,%eax
je     114c <ReadName+0x3c>
cmp    $0x1f,%ebx
mov    %rcx,%rbx
jne    1130 <ReadName+0x20>
add    %r14,%rcx
movb   $0x0,(%rcx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @ReadName(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 32, i32* %5
%8 = load i8*, i8** %4
store i8* %8, i8** %7
br label %9
9: ; preds = %19, %2
%10 = load i32*, i32** %3
%11 = call i32 @getc(i32* %10)
store i32 %11, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %9
%14 = load i32, i32* %5
%15 = add nsw i32 %14, -1
store i32 %15, i32* %5
%16 = icmp ne i32 %14, 0
br label %17
17: ; preds = %13, %9
%18 = phi i1 [ false, %9 ], [ %16, %13 ]
br i1 %18, label %19, label %24
19: ; preds = %17
%20 = load i32, i32* %6
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %7
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %7
store i8 %21, i8* %22
br label %9
24: ; preds = %17
%25 = load i8*, i8** %7
store i8 0, i8* %25
%26 = load i8*, i8** %4
ret i8* %26
}

LLVM IR (-O2):
define i8* @ReadName(i32* nocapture %0, i8* returned writeonly %1) {
%3 = tail call i32 @getc(i32* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2, %5
%6 = phi i32 [ %12, %5 ], [ %3, %2 ]
%7 = phi i8* [ %11, %5 ], [ %1, %2 ]
%8 = phi i32 [ %9, %5 ], [ 32, %2 ]
%9 = add nsw i32 %8, -1
%10 = trunc i32 %6 to i8
%11 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %10, i8* %7
%12 = tail call i32 @getc(i32* %0)
%13 = icmp eq i32 %12, 0
%14 = icmp eq i32 %9, 0
%15 = select i1 %13, i1 true, i1 %14
br i1 %15, label %16, label %5
16: ; preds = %5, %2
%17 = phi i8* [ %1, %2 ], [ %11, %5 ]
store i8 0, i8* %17
ret i8* %1
}