#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*/ free(char *);
scalar_t__ parse_eos(char const **);
char *pop_error_handling(int);
int /*<<< orphan*/ print_error(char *, char const *, char *, int, char const *);
bool report_parse_error(const char *message, bool ok, const char *start,
                        const char *end) {
  if (ok && parse_eos(&end)) {
    pop_error_handling(false);
    return true;
  } else {
    char *error_message = pop_error_handling(true);
    print_error("Error parsing %s: %s at offset %zd in \"%s\"", message,
                error_message, end - start + 1, start);
    free(error_message);
    return false;
  }
}


x86 assembly (clang, -O0):
<report_parse_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1187 <report_parse_error+0x47>
lea    -0x28(%rbp),%rdi
call   1060 <parse_eos@plt>
cmp    $0x0,%rax
je     1187 <report_parse_error+0x47>
xor    %edi,%edi
call   1050 <pop_error_handling@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ce <report_parse_error+0x8e>
mov    $0x1,%edi
call   1050 <pop_error_handling@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%ecx
mov    -0x20(%rbp),%r8
lea    0xe47(%rip),%rdi
call   1040 <print_error@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<report_parse_error>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rdi,%r14
mov    %rcx,0x8(%rsp)
test   %esi,%esi
je     1175 <report_parse_error+0x35>
lea    0x8(%rsp),%rdi
call   1060 <parse_eos@plt>
test   %rax,%rax
je     1175 <report_parse_error+0x35>
xor    %edi,%edi
call   1050 <pop_error_handling@plt>
mov    $0x1,%eax
jmp    11ab <report_parse_error+0x6b>
mov    $0x1,%edi
call   1050 <pop_error_handling@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%ecx
sub    %r15d,%ecx
add    $0x1,%ecx
lea    0xe6d(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %r15,%r8
call   1040 <print_error@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [43 x i8] c"Error parsing %s: %s at offset %zd in \22%s\22\00"
define i32 @report_parse_error(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%11 = load i32, i32* %7
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %4
%14 = call i64 @parse_eos(i8** %9)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i8* @pop_error_handling(i32 0)
store i32 1, i32* %5
br label %33
18: ; preds = %13, %4
%19 = call i8* @pop_error_handling(i32 1)
store i8* %19, i8** %10
%20 = load i8*, i8** %6
%21 = load i8*, i8** %10
%22 = load i8*, i8** %9
%23 = load i8*, i8** %8
%24 = ptrtoint i8* %22 to i64
%25 = ptrtoint i8* %23 to i64
%26 = sub i64 %24, %25
%27 = add nsw i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = load i8*, i8** %8
%30 = call i32 @print_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21, i32 %28, i8* %29)
%31 = load i8*, i8** %10
%32 = call i32 @free(i8* %31)
store i32 0, i32* %5
br label %33
33: ; preds = %18, %16
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@.str = [43 x i8] c"Error parsing %s: %s at offset %zd in \22%s\22\00"
define i32 @report_parse_error(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
store i8* %3, i8** %5
%6 = icmp eq i32 %1, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = call i64 @parse_eos(i8** %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i8* @pop_error_handling(i32 0)
br label %22
12: ; preds = %7, %4
%13 = call i8* @pop_error_handling(i32 1)
%14 = load i8*, i8** %5
%15 = ptrtoint i8* %14 to i64
%16 = ptrtoint i8* %2 to i64
%17 = sub i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = add i32 %18, 1
%20 = call i32 @print_error(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %13, i32 %19, i8* %2)
%21 = call i32 @free(i8* %13)
br label %22
22: ; preds = %12, %10
%23 = phi i32 [ 1, %10 ], [ 0, %12 ]
ret i32 %23
}