#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 */
scalar_t__ errno;
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int strtol(unsigned char *, int /*<<< orphan*/ *, int);
int convert_html_entity(const unsigned char *beg, const unsigned char *end,
                        int base) {
  int len = (int)(end - beg);
  unsigned char buf[32];
  if (len <= 0 || len > 31)
    return -1;
  memcpy(buf, beg, len);
  buf[len] = 0;
  errno = 0;
  int value = strtol(buf, NULL, base);
  if (errno || value < 0 || value >= 0x10000)
    return -1;
  return value;
}


x86 assembly (clang, -O0):
<convert_html_entity>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    1155 <convert_html_entity+0x35>
cmpl   $0x1f,-0x20(%rbp)
jle    1161 <convert_html_entity+0x41>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <convert_html_entity+0xb5>
lea    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <memcpy@plt>
movslq -0x20(%rbp),%rax
movb   $0x0,-0x40(%rbp,%rax,1)
mov    0x2e5f(%rip),%rax
movq   $0x0,(%rax)
lea    -0x40(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1030 <strtol@plt>
mov    %eax,-0x44(%rbp)
mov    0x2e3e(%rip),%rax
cmpq   $0x0,(%rax)
jne    11c3 <convert_html_entity+0xa3>
cmpl   $0x0,-0x44(%rbp)
jl     11c3 <convert_html_entity+0xa3>
cmpl   $0x10000,-0x44(%rbp)
jl     11cf <convert_html_entity+0xaf>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d5 <convert_html_entity+0xb5>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_html_entity>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
sub    %rdi,%rbx
lea    -0x20(%rbx),%ecx
mov    $0xffffffff,%eax
cmp    $0xffffffe1,%ecx
jb     118e <convert_html_entity+0x6e>
mov    %edx,%ebp
mov    %rdi,%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%rsp,%rax,1)
mov    0x2e83(%rip),%rbx
movq   $0x0,(%rbx)
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <strtol@plt>
cmp    $0x10000,%eax
mov    $0xffffffff,%ecx
mov    %eax,%edx
cmovge %ecx,%edx
test   %eax,%eax
cmovs  %ecx,%edx
cmp    (%rbx),%r15
sbb    %eax,%eax
or     %edx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
define i32 @convert_html_entity(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [32 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%11 = load i8*, i8** %6
%12 = load i8*, i8** %5
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp sle i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %3
%20 = load i32, i32* %8
%21 = icmp sgt i32 %20, 31
br i1 %21, label %22, label %23
22: ; preds = %19, %3
store i32 -1, i32* %4
br label %45
23: ; preds = %19
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%25 = load i8*, i8** %5
%26 = load i32, i32* %8
%27 = call i32 @memcpy(i8* %24, i8* %25, i32 %26)
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 %29
store i8 0, i8* %30
store i64 0, i64* @errno
%31 = getelementptr inbounds [32 x i8], [32 x i8]* %9, i64 0, i64 0
%32 = load i32, i32* %7
%33 = call i32 @strtol(i8* %31, i32* null, i32 %32)
store i32 %33, i32* %10
%34 = load i64, i64* @errno
%35 = icmp ne i64 %34, 0
br i1 %35, label %42, label %36
36: ; preds = %23
%37 = load i32, i32* %10
%38 = icmp slt i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load i32, i32* %10
%41 = icmp sge i32 %40, 65536
br i1 %41, label %42, label %43
42: ; preds = %39, %36, %23
store i32 -1, i32* %4
br label %45
43: ; preds = %39
%44 = load i32, i32* %10
store i32 %44, i32* %4
br label %45
45: ; preds = %43, %42, %22
%46 = load i32, i32* %4
ret i32 %46
}

LLVM IR (-O2):
@errno = global i64 0
define i32 @convert_html_entity(i8* %0, i8* %1, i32 %2) {
%4 = alloca [32 x i8]
%5 = ptrtoint i8* %1 to i64
%6 = ptrtoint i8* %0 to i64
%7 = sub i64 %5, %6
%8 = trunc i64 %7 to i32
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%10 = add i32 %8, -32
%11 = icmp ult i32 %10, -31
br i1 %11, label %25, label %12
12: ; preds = %3
%13 = call i32 @memcpy(i8* %9, i8* %0, i32 %8)
%14 = shl i64 %7, 32
%15 = ashr exact i64 %14, 32
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %15
store i8 0, i8* %16
store i64 0, i64* @errno
%17 = call i32 @strtol(i8* nocapture %9, i32* null, i32 %2)
%18 = load i64, i64* @errno
%19 = icmp ne i64 %18, 0
%20 = icmp slt i32 %17, 0
%21 = select i1 %19, i1 true, i1 %20
%22 = icmp sgt i32 %17, 65535
%23 = select i1 %21, i1 true, i1 %22
%24 = select i1 %23, i32 -1, i32 %17
br label %25
25: ; preds = %3, %12
%26 = phi i32 [ %24, %12 ], [ -1, %3 ]
ret i32 %26
}