#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_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ ishex(char const);
char *strchr(char const *, char const);
scalar_t__ symbol_value(char const);
const char *parse_hex_until(const char *s, const char *delim, unsigned int *v,
                            const char *error_message, bool accept_zero) {
  unsigned int val = 0;
  const char *d;
  if (!ishex(*s))
    errx(EXIT_FAILURE, "%s: expect an hexadecimal value", error_message);
  for (; *s != '\0'; s++) {
    d = strchr(delim, *s);
    if (d)
      goto EXIT;
    if (!ishex(*s))
      errx(EXIT_FAILURE, "%s: expect an hexadecimal value", error_message);
    val <<= 4;
    val += symbol_value(*s);
  }
  if (!accept_zero)
    errx(EXIT_FAILURE, "%s: premature ending", error_message);
EXIT:
  *v = val;
  return s;
}


x86 assembly (clang, -O0):
<parse_hex_until>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ishex@plt>
cmp    $0x0,%eax
jne    1191 <parse_hex_until+0x51>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe74(%rip),%rsi
call   1040 <errx@plt>
jmp    1196 <parse_hex_until+0x56>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122a <parse_hex_until+0xea>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rax
movsbl (%rax),%esi
call   1050 <strchr@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11ca <parse_hex_until+0x8a>
jmp    1252 <parse_hex_until+0x112>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <ishex@plt>
cmp    $0x0,%eax
jne    11f8 <parse_hex_until+0xb8>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe0d(%rip),%rsi
call   1040 <errx@plt>
mov    -0x28(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1060 <symbol_value@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1196 <parse_hex_until+0x56>
cmpl   $0x0,-0x24(%rbp)
jne    124d <parse_hex_until+0x10d>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xdd8(%rip),%rsi
call   1040 <errx@plt>
jmp    1252 <parse_hex_until+0x112>
mov    -0x28(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_hex_until>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %rcx,%r15
mov    %rdx,%rbp
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <ishex@plt>
test   %eax,%eax
jne    1181 <parse_hex_until+0x41>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0xe87(%rip),%rsi
mov    %r15,%rdx
call   1040 <errx@plt>
mov    (%rbx),%al
test   %al,%al
mov    %rbp,0x10(%rsp)
mov    %r12d,0xc(%rsp)
je     11f8 <parse_hex_until+0xb8>
xor    %r13d,%r13d
jmp    11c1 <parse_hex_until+0x81>
cs nopw 0x0(%rax,%rax,1)
shl    $0x4,%r13d
movsbl (%rbx),%edi
call   1060 <symbol_value@plt>
mov    %rax,%r12
add    %r13d,%r12d
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
mov    %r12d,%r13d
test   %al,%al
je     11fb <parse_hex_until+0xbb>
movsbl %al,%ebp
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    1221 <parse_hex_until+0xe1>
mov    %ebp,%edi
call   1030 <ishex@plt>
test   %eax,%eax
jne    11a0 <parse_hex_until+0x60>
mov    0x2dfb(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
mov    %r15,%rdx
call   1040 <errx@plt>
jmp    11a0 <parse_hex_until+0x60>
xor    %r12d,%r12d
cmpl   $0x0,0xc(%rsp)
mov    0x10(%rsp),%rbp
jne    1229 <parse_hex_until+0xe9>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
mov    %r15,%rdx
call   1040 <errx@plt>
jmp    1229 <parse_hex_until+0xe9>
mov    %r13d,%r12d
mov    0x10(%rsp),%rbp
mov    %r12d,0x0(%rbp)
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [32 x i8] c"%s: expect an hexadecimal value\00"
@.str.1 = [21 x i8] c"%s: premature ending\00"
define i8* @parse_hex_until(i8* %0, i8* %1, i32* %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i8* %3, i8** %9
store i32 %4, i32* %10
store i32 0, i32* %11
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = call i32 @ishex(i8 signext %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %5
%18 = load i32, i32* @EXIT_FAILURE
%19 = load i8*, i8** %9
%20 = call i32 @errx(i32 %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %17, %5
br label %22
22: ; preds = %54, %21
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %57
27: ; preds = %22
%28 = load i8*, i8** %7
%29 = load i8*, i8** %6
%30 = load i8, i8* %29
%31 = call i8* @strchr(i8* %28, i8 signext %30)
store i8* %31, i8** %12
%32 = load i8*, i8** %12
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %35
34: ; preds = %27
br label %65
35: ; preds = %27
%36 = load i8*, i8** %6
%37 = load i8, i8* %36
%38 = call i32 @ishex(i8 signext %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %35
%41 = load i32, i32* @EXIT_FAILURE
%42 = load i8*, i8** %9
%43 = call i32 @errx(i32 %41, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %42)
br label %44
44: ; preds = %40, %35
%45 = load i32, i32* %11
%46 = shl i32 %45, 4
store i32 %46, i32* %11
%47 = load i8*, i8** %6
%48 = load i8, i8* %47
%49 = call i64 @symbol_value(i8 signext %48)
%50 = load i32, i32* %11
%51 = zext i32 %50 to i64
%52 = add nsw i64 %51, %49
%53 = trunc i64 %52 to i32
store i32 %53, i32* %11
br label %54
54: ; preds = %44
%55 = load i8*, i8** %6
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %6
br label %22
57: ; preds = %22
%58 = load i32, i32* %10
%59 = icmp ne i32 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %57
%61 = load i32, i32* @EXIT_FAILURE
%62 = load i8*, i8** %9
%63 = call i32 @errx(i32 %61, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %62)
br label %64
64: ; preds = %60, %57
br label %65
65: ; preds = %64, %34
%66 = load i32, i32* %11
%67 = load i32*, i32** %8
store i32 %66, i32* %67
%68 = load i8*, i8** %6
ret i8* %68
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [32 x i8] c"%s: expect an hexadecimal value\00"
@.str.1 = [21 x i8] c"%s: premature ending\00"
define i8* @parse_hex_until(i8* %0, i8* %1, i32* nocapture writeonly %2, i8* %3, i32 %4) {
%6 = load i8, i8* %0
%7 = tail call i32 @ishex(i8 signext %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @errx(i32 %10, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %12
12: ; preds = %9, %5
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 0
br i1 %14, label %36, label %15
15: ; preds = %12, %27
%16 = phi i8 [ %34, %27 ], [ %13, %12 ]
%17 = phi i8* [ %33, %27 ], [ %0, %12 ]
%18 = phi i32 [ %32, %27 ], [ 0, %12 ]
%19 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext %16)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %43
21: ; preds = %15
%22 = tail call i32 @ishex(i8 signext %16)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @errx(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %27
27: ; preds = %24, %21
%28 = shl i32 %18, 4
%29 = load i8, i8* %17
%30 = tail call i64 @symbol_value(i8 signext %29)
%31 = trunc i64 %30 to i32
%32 = add i32 %28, %31
%33 = getelementptr inbounds i8, i8* %17, i64 1
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %15
36: ; preds = %27, %12
%37 = phi i32 [ 0, %12 ], [ %32, %27 ]
%38 = phi i8* [ %0, %12 ], [ %33, %27 ]
%39 = icmp eq i32 %4, 0
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @EXIT_FAILURE
%42 = tail call i32 @errx(i32 %41, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %3)
br label %43
43: ; preds = %15, %36, %40
%44 = phi i32 [ %37, %36 ], [ %37, %40 ], [ %18, %15 ]
%45 = phi i8* [ %38, %36 ], [ %38, %40 ], [ %17, %15 ]
store i32 %44, i32* %2
ret i8* %45
}