#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 get_num_value(char);
scalar_t__ is_hex_digit(char);
int pow(int, int);
int strlen(char *);
int get_hex_constant(char *line) {
  int len = strlen(line);
  int number_length = 0;
  while (is_hex_digit(line[number_length]) && number_length < len)
    number_length++;
  int i, num = 0;
  for (i = 0; i < number_length; i++)
    num += get_num_value(line[i]) * pow(16, number_length - i - 1);
  return num;
}


x86 assembly (clang, -O0):
<get_hex_constant>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1060 <is_hex_digit@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     118e <get_hex_constant+0x4e>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setl   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    119e <get_hex_constant+0x5e>
jmp    11ac <get_hex_constant+0x6c>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115f <get_hex_constant+0x1f>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1209 <get_hex_constant+0xc9>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <get_num_value@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%esi
sub    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    $0x10,%edi
call   1050 <pow@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
imul   %ecx,%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ba <get_hex_constant+0x7a>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hex_constant>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
movslq %eax,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbp,1),%edi
call   1060 <is_hex_digit@plt>
lea    0x1(%rbp),%r14
test   %rax,%rax
je     117b <get_hex_constant+0x3b>
cmp    %rbx,%rbp
mov    %r14,%rbp
jl     1160 <get_hex_constant+0x20>
xor    %r12d,%r12d
cmp    $0x1,%r14d
je     11d4 <get_hex_constant+0x94>
lea    -0x2(%r14),%r13
add    $0xffffffffffffffff,%r14
xor    %ebx,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%r15,%rbx,1),%edi
call   1040 <get_num_value@plt>
mov    %r15,%rbp
mov    %eax,%r15d
mov    $0x10,%edi
mov    %r13d,%esi
call   1050 <pow@plt>
imul   %r15d,%eax
mov    %rbp,%r15
add    %eax,%r12d
add    $0x1,%rbx
add    $0xffffffff,%r13d
cmp    %rbx,%r14
jne    11a0 <get_hex_constant+0x60>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_hex_constant(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
store i32 0, i32* %4
br label %9
9: ; preds = %23, %1
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = call i64 @is_hex_digit(i8 signext %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %9
%18 = load i32, i32* %4
%19 = load i32, i32* %3
%20 = icmp slt i32 %18, %19
br label %21
21: ; preds = %17, %9
%22 = phi i1 [ false, %9 ], [ %20, %17 ]
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %9
26: ; preds = %21
store i32 0, i32* %6
store i32 0, i32* %5
br label %27
27: ; preds = %46, %26
%28 = load i32, i32* %5
%29 = load i32, i32* %4
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %49
31: ; preds = %27
%32 = load i8*, i8** %2
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @get_num_value(i8 signext %36)
%38 = load i32, i32* %4
%39 = load i32, i32* %5
%40 = sub nsw i32 %38, %39
%41 = sub nsw i32 %40, 1
%42 = call i32 @pow(i32 16, i32 %41)
%43 = mul nsw i32 %37, %42
%44 = load i32, i32* %6
%45 = add nsw i32 %44, %43
store i32 %45, i32* %6
br label %46
46: ; preds = %31
%47 = load i32, i32* %5
%48 = add nsw i32 %47, 1
store i32 %48, i32* %5
br label %27
49: ; preds = %27
%50 = load i32, i32* %6
ret i32 %50
}

LLVM IR (-O2):
define i32 @get_hex_constant(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ %12, %4 ], [ 0, %1 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i64 @is_hex_digit(i8 signext %7)
%9 = icmp ne i64 %8, 0
%10 = icmp slt i64 %5, %3
%11 = select i1 %9, i1 %10, i1 false
%12 = add nuw nsw i64 %5, 1
br i1 %11, label %4, label %13
13: ; preds = %4
%14 = trunc i64 %5 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %32, label %16
16: ; preds = %13
%17 = and i64 %5, 4294967295
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %30, %18 ]
%20 = phi i32 [ 0, %16 ], [ %29, %18 ]
%21 = trunc i64 %19 to i32
%22 = getelementptr inbounds i8, i8* %0, i64 %19
%23 = load i8, i8* %22
%24 = tail call i32 @get_num_value(i8 signext %23)
%25 = xor i32 %21, -1
%26 = add nsw i32 %14, %25
%27 = tail call i32 @pow(i32 16, i32 %26)
%28 = mul nsw i32 %27, %24
%29 = add nsw i32 %28, %20
%30 = add nuw nsw i64 %19, 1
%31 = icmp eq i64 %30, %17
br i1 %31, label %32, label %18
32: ; preds = %18, %13
%33 = phi i32 [ 0, %13 ], [ %29, %18 ]
ret i32 %33
}