#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int ReadName(int bfd, char *name) {
  name[0] = '\0';
  char c[1];
  int cnt;
  for (cnt = 0; read(bfd, c, 1) > 0; cnt++) {
    if (cnt == 2048) {
      fprintf(stderr, "error finding name %s\n", name);
      exit(1);
    }
    name[cnt] = c[0];
    if (c[0] == '\0') {
      return strlen(name);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ReadName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
cmp    $0x0,%rax
jle    11e7 <ReadName+0xa7>
cmpl   $0x800,-0x18(%rbp)
jne    11a8 <ReadName+0x68>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    11d4 <ReadName+0x94>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
jmp    11ee <ReadName+0xae>
jmp    11d9 <ReadName+0x99>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115d <ReadName+0x1d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadName>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
movb   $0x0,(%rsi)
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jle    119e <ReadName+0x5e>
xor    %ebx,%ebx
lea    0x7(%rsp),%r14
nopw   0x0(%rax,%rax,1)
cmp    $0x800,%rbx
je     11bd <ReadName+0x7d>
movzbl 0x7(%rsp),%eax
mov    %al,(%r15,%rbx,1)
test   %al,%al
je     11ab <ReadName+0x6b>
add    $0x1,%rbx
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     1170 <ReadName+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strlen@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"error finding name %s\0A\00"
define i32 @ReadName(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 0, i8* %9
store i32 0, i32* %7
br label %10
10: ; preds = %38, %2
%11 = load i32, i32* %4
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%13 = call i64 @read(i32 %11, i8* %12, i32 1)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %41
15: ; preds = %10
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, 2048
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %15
%24 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%25 = load i8, i8* %24
%26 = load i8*, i8** %5
%27 = load i32, i32* %7
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 %25, i8* %29
%30 = getelementptr inbounds [1 x i8], [1 x i8]* %6, i64 0, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %23
%35 = load i8*, i8** %5
%36 = call i32 @strlen(i8* %35)
store i32 %36, i32* %3
br label %42
37: ; preds = %23
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %10
41: ; preds = %10
store i32 0, i32* %3
br label %42
42: ; preds = %41, %34
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"error finding name %s\0A\00"
define i32 @ReadName(i32 %0, i8* %1) {
%3 = alloca [1 x i8]
store i8 0, i8* %1
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = call i64 @read(i32 %0, i8* %4, i32 1)
%6 = icmp sgt i64 %5, 0
br i1 %6, label %11, label %24
7: ; preds = %18
%8 = add nuw nsw i64 %12, 1
%9 = call i64 @read(i32 %0, i8* %4, i32 1)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %24
11: ; preds = %2, %7
%12 = phi i64 [ %8, %7 ], [ 0, %2 ]
%13 = icmp eq i64 %12, 2048
br i1 %13, label %14, label %18
14: ; preds = %11
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i8, i8* %4
%20 = getelementptr inbounds i8, i8* %1, i64 %12
store i8 %19, i8* %20
%21 = icmp eq i8 %19, 0
br i1 %21, label %22, label %7
22: ; preds = %18
%23 = tail call i32 @strlen(i8* %1)
br label %24
24: ; preds = %7, %2, %22
%25 = phi i32 [ %23, %22 ], [ 0, %2 ], [ 0, %7 ]
ret i32 %25
}