#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 char uint8_t;

/* Variables and functions */
int read(int, char *, int);
int read_char_name(int fd, char *propname, int buf_size) {
  int offset = 0;
  uint8_t ch;
  while ((read(fd, &ch, 1)) == 1) {
    if (propname) {
      if (offset + 1 == buf_size) {
        propname[offset] = '\0';
        break;
      }
      propname[offset++] = ch;
    } else {
      offset++;
    }
    if (ch == 0)
      break;
  }
  return offset;
}


x86 assembly (clang, -O0):
<read_char_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    11ab <read_char_name+0x9b>
cmpq   $0x0,-0x10(%rbp)
je     118b <read_char_name+0x7b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cmp    -0x14(%rbp),%eax
jne    116e <read_char_name+0x5e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ab <read_char_name+0x9b>
mov    -0x19(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1194 <read_char_name+0x84>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
movsbl -0x19(%rbp),%eax
cmp    $0x0,%eax
jne    11a6 <read_char_name+0x96>
jmp    11ab <read_char_name+0x9b>
jmp    1129 <read_char_name+0x19>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_char_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
mov    %rsi,%r14
mov    %edi,%ebp
add    $0xffffffff,%r15d
xor    %ebx,%ebx
lea    0xf(%rsp),%r12
jmp    114d <read_char_name+0x3d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl 0xf(%rsp),%eax
add    $0x1,%rbx
test   %al,%al
je     117b <read_char_name+0x6b>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    117b <read_char_name+0x6b>
test   %r14,%r14
je     1140 <read_char_name+0x30>
cmp    %ebx,%r15d
je     1176 <read_char_name+0x66>
movzbl 0xf(%rsp),%eax
mov    %al,(%r14,%rbx,1)
jmp    1145 <read_char_name+0x35>
movb   $0x0,(%r14,%rbx,1)
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_char_name(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %41, %3
%10 = load i32, i32* %4
%11 = call i32 @read(i32 %10, i8* %8, i32 1)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %42
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %33
16: ; preds = %13
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = load i32, i32* %6
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 0, i8* %25
br label %42
26: ; preds = %16
%27 = load i8, i8* %8
%28 = load i8*, i8** %5
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
%31 = sext i32 %29 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 %27, i8* %32
br label %36
33: ; preds = %13
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %36
36: ; preds = %33, %26
%37 = load i8, i8* %8
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
br label %42
41: ; preds = %36
br label %9
42: ; preds = %40, %21, %9
%43 = load i32, i32* %7
ret i32 %43
}

LLVM IR (-O2):
define i32 @read_char_name(i32 %0, i8* writeonly %1, i32 %2) {
%4 = alloca i8
%5 = icmp eq i8* %1, null
br label %6
6: ; preds = %23, %3
%7 = phi i32 [ 0, %3 ], [ %11, %23 ]
%8 = call i32 @read(i32 %0, i8* %4, i32 1)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %26
10: ; preds = %6
%11 = add nuw nsw i32 %7, 1
br i1 %5, label %21, label %12
12: ; preds = %10
%13 = icmp eq i32 %11, %2
br i1 %13, label %14, label %17
14: ; preds = %12
%15 = zext i32 %7 to i64
%16 = getelementptr inbounds i8, i8* %1, i64 %15
store i8 0, i8* %16
br label %26
17: ; preds = %12
%18 = load i8, i8* %4
%19 = zext i32 %7 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
store i8 %18, i8* %20
br label %23
21: ; preds = %10
%22 = load i8, i8* %4
br label %23
23: ; preds = %21, %17
%24 = phi i8 [ %22, %21 ], [ %18, %17 ]
%25 = icmp eq i8 %24, 0
br i1 %25, label %26, label %6
26: ; preds = %23, %6, %14
%27 = phi i32 [ %7, %14 ], [ %7, %6 ], [ %11, %23 ]
ret i32 %27
}