#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 string {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ string_append_char(struct string *, char const);
size_t load_macro_name(const char *cstr, size_t start, char end_char,
                       struct string *output) {
  size_t i = start;
  while (cstr[i] && cstr[i] != end_char) {
    string_append_char(output, cstr[i]);
    ++i;
  }
  if (!cstr[i]) {
    fprintf(stderr, "Unclosed macro name\n");
    return (0);
  }
  return (i);
}


x86 assembly (clang, -O0):
<load_macro_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x31(%rbp)
je     1173 <load_macro_name+0x53>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x19(%rbp),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1183 <load_macro_name+0x63>
jmp    11a9 <load_macro_name+0x89>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1030 <string_append_char@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1141 <load_macro_name+0x21>
mov    -0x10(%rbp),%rax
mov    -0x30(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
jne    11dd <load_macro_name+0xbd>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e5 <load_macro_name+0xc5>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_macro_name>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%rbx
mov    (%rdi,%rsi,1),%cl
test   %cl,%cl
sete   %al
je     1170 <load_macro_name+0x50>
mov    %edx,%r15d
cmp    %r15b,%cl
je     1170 <load_macro_name+0x50>
mov    %rdi,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %cl,%esi
mov    %r14,%rdi
call   1030 <string_append_char@plt>
movzbl 0x1(%rbp,%rbx,1),%ecx
add    $0x1,%rbx
test   %cl,%cl
sete   %al
je     1170 <load_macro_name+0x50>
cmp    %r15b,%cl
jne    1150 <load_macro_name+0x30>
test   %al,%al
je     118b <load_macro_name+0x6b>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.string = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Unclosed macro name\0A\00"
define i64 @load_macro_name(i8* %0, i64 %1, i8 signext %2, %struct.string* %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8
%9 = alloca %struct.string*
%10 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8 %2, i8* %8
store %struct.string* %3, %struct.string** %9
%11 = load i64, i64* %7
store i64 %11, i64* %10
br label %12
12: ; preds = %30, %4
%13 = load i8*, i8** %6
%14 = load i64, i64* %10
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = load i64, i64* %10
%22 = getelementptr inbounds i8, i8* %20, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = load i8, i8* %8
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %24, %26
br label %28
28: ; preds = %19, %12
%29 = phi i1 [ false, %12 ], [ %27, %19 ]
br i1 %29, label %30, label %39
30: ; preds = %28
%31 = load %struct.string*, %struct.string** %9
%32 = load i8*, i8** %6
%33 = load i64, i64* %10
%34 = getelementptr inbounds i8, i8* %32, i64 %33
%35 = load i8, i8* %34
%36 = call i32 @string_append_char(%struct.string* %31, i8 signext %35)
%37 = load i64, i64* %10
%38 = add i64 %37, 1
store i64 %38, i64* %10
br label %12
39: ; preds = %28
%40 = load i8*, i8** %6
%41 = load i64, i64* %10
%42 = getelementptr inbounds i8, i8* %40, i64 %41
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %5
br label %50
48: ; preds = %39
%49 = load i64, i64* %10
store i64 %49, i64* %5
br label %50
50: ; preds = %48, %45
%51 = load i64, i64* %5
ret i64 %51
}

LLVM IR (-O2):
%struct.string = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Unclosed macro name\0A\00"
define i64 @load_macro_name(i8* nocapture %0, i64 %1, i8 signext %2, %struct.string* %3) {
%5 = getelementptr inbounds i8, i8* %0, i64 %1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = icmp eq i8 %6, %2
%9 = or i1 %7, %8
br i1 %9, label %20, label %10
10: ; preds = %4, %10
%11 = phi i8 [ %16, %10 ], [ %6, %4 ]
%12 = phi i64 [ %14, %10 ], [ %1, %4 ]
%13 = tail call i32 @string_append_char(%struct.string* %3, i8 signext %11)
%14 = add i64 %12, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
%18 = icmp eq i8 %16, %2
%19 = or i1 %17, %18
br i1 %19, label %20, label %10
20: ; preds = %10, %4
%21 = phi i64 [ %1, %4 ], [ %14, %10 ]
%22 = phi i1 [ %7, %4 ], [ %17, %10 ]
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %26
26: ; preds = %20, %23
%27 = phi i64 [ 0, %23 ], [ %21, %20 ]
ret i64 %27
}