#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*/ assert(int);
unsigned int error(char *, ...);
char *find_token(char const *, int *, unsigned int *);
unsigned int eval_register(const char *text, int *len) {
  unsigned int lval;
  int ilen;
  const char *ip = find_token(text, &ilen, &lval);
  if (ip == NULL)
    return error("Expected an integer");
  if (lval == -1u || (lval & 01000000))
    return error("Expected a register number");
  if (lval & ~07)
    return error("Register number out of range");
  if (ip[0] == '#')
    return error("Type error: integer \"%.*s\" should be a register number",
                 ilen, ip);
  ip += ilen;
  assert(ip >= text);
  *len = (ip - text);
  return lval;
}


x86 assembly (clang, -O0):
<eval_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1030 <find_token@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1176 <eval_register+0x46>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1050 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1238 <eval_register+0x108>
cmpl   $0xffffffff,-0x1c(%rbp)
je     1191 <eval_register+0x61>
mov    -0x1c(%rbp),%eax
and    $0x40000,%eax
cmp    $0x0,%eax
je     11a7 <eval_register+0x77>
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1050 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1238 <eval_register+0x108>
mov    -0x1c(%rbp),%eax
and    $0xfffffff8,%eax
cmp    $0x0,%eax
je     11cc <eval_register+0x9c>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1050 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1238 <eval_register+0x108>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11f9 <eval_register+0xc9>
mov    -0x20(%rbp),%esi
mov    -0x28(%rbp),%rdx
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <error@plt>
mov    %eax,-0x4(%rbp)
jmp    1238 <eval_register+0x108>
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eval_register>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1030 <find_token@plt>
test   %rax,%rax
je     1183 <eval_register+0x53>
mov    %rax,%rbx
mov    0x8(%rsp),%eax
test   $0x40000,%eax
jne    118c <eval_register+0x5c>
cmp    $0x8,%eax
jae    1195 <eval_register+0x65>
cmpb   $0x23,(%rbx)
movslq 0xc(%rsp),%rsi
jne    11ad <eval_register+0x7d>
lea    0xed5(%rip),%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <error@plt>
jmp    11a3 <eval_register+0x73>
lea    0xe76(%rip),%rdi
jmp    119c <eval_register+0x6c>
lea    0xe81(%rip),%rdi
jmp    119c <eval_register+0x6c>
lea    0xe93(%rip),%rdi
xor    %eax,%eax
call   1050 <error@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
add    %rsi,%rbx
xor    %edi,%edi
cmp    %r15,%rbx
setae  %dil
call   1040 <assert@plt>
sub    %r15d,%ebx
mov    %ebx,(%r14)
mov    0x8(%rsp),%eax
jmp    11a3 <eval_register+0x73>

LLVM IR (-O0):
@.str = [20 x i8] c"Expected an integer\00"
@.str.1 = [27 x i8] c"Expected a register number\00"
@.str.2 = [29 x i8] c"Register number out of range\00"
@.str.3 = [55 x i8] c"Type error: integer \22%.*s\22 should be a register number\00"
define i32 @eval_register(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
%9 = load i8*, i8** %4
%10 = call i8* @find_token(i8* %9, i32* %7, i32* %6)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %3
br label %58
15: ; preds = %2
%16 = load i32, i32* %6
%17 = icmp eq i32 %16, -1
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32, i32* %6
%20 = and i32 %19, 262144
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18, %15
%23 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 %23, i32* %3
br label %58
24: ; preds = %18
%25 = load i32, i32* %6
%26 = and i32 %25, -8
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
store i32 %29, i32* %3
br label %58
30: ; preds = %24
%31 = load i8*, i8** %8
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 35
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = load i32, i32* %7
%38 = load i8*, i8** %8
%39 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %37, i8* %38)
store i32 %39, i32* %3
br label %58
40: ; preds = %30
%41 = load i32, i32* %7
%42 = load i8*, i8** %8
%43 = sext i32 %41 to i64
%44 = getelementptr inbounds i8, i8* %42, i64 %43
store i8* %44, i8** %8
%45 = load i8*, i8** %8
%46 = load i8*, i8** %4
%47 = icmp uge i8* %45, %46
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %8
%51 = load i8*, i8** %4
%52 = ptrtoint i8* %50 to i64
%53 = ptrtoint i8* %51 to i64
%54 = sub i64 %52, %53
%55 = trunc i64 %54 to i32
%56 = load i32*, i32** %5
store i32 %55, i32* %56
%57 = load i32, i32* %6
store i32 %57, i32* %3
br label %58
58: ; preds = %40, %36, %28, %22, %13
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [20 x i8] c"Expected an integer\00"
@.str.1 = [27 x i8] c"Expected a register number\00"
@.str.2 = [29 x i8] c"Register number out of range\00"
@.str.3 = [55 x i8] c"Type error: integer \22%.*s\22 should be a register number\00"
define i32 @eval_register(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i8* @find_token(i8* %0, i32* %4, i32* %3)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %38
11: ; preds = %2
%12 = load i32, i32* %3
%13 = and i32 %12, 262144
%14 = icmp eq i32 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %38
17: ; preds = %11
%18 = icmp ult i32 %12, 8
br i1 %18, label %21, label %19
19: ; preds = %17
%20 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
br label %38
21: ; preds = %17
%22 = load i8, i8* %7
%23 = icmp eq i8 %22, 35
%24 = load i32, i32* %4
br i1 %23, label %25, label %27
25: ; preds = %21
%26 = call i32 (i8*, ...) @error(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %7)
br label %38
27: ; preds = %21
%28 = sext i32 %24 to i64
%29 = getelementptr inbounds i8, i8* %7, i64 %28
%30 = icmp uge i8* %29, %0
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = ptrtoint i8* %29 to i64
%34 = ptrtoint i8* %0 to i64
%35 = sub i64 %33, %34
%36 = trunc i64 %35 to i32
store i32 %36, i32* %1
%37 = load i32, i32* %3
br label %38
38: ; preds = %27, %25, %19, %15, %9
%39 = phi i32 [ %10, %9 ], [ %16, %15 ], [ %20, %19 ], [ %26, %25 ], [ %37, %27 ]
ret i32 %39
}