#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 hex_degree(int);
int hex_symb(char);
int strlen(char *);
int htol(char string[]) {
  int i = 0;
  int j = 0;
  int rev = 0;
  int sum = 0;
  int step = 0;
  char symb = 0;
  for (i = strlen(string) - 1 - 1; i >= 2; --i) {
    j = hex_symb(string[i]);
    step = hex_degree(rev);
    sum = sum + step * j;
    ++rev;
  }
  return sum;
}


x86 assembly (clang, -O0):
<htol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jl     11c4 <htol+0x94>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <hex_symb@plt>
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <hex_degree@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x10(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1175 <htol+0x45>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<htol>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1050 <strlen@plt>
xor    %ebp,%ebp
cmp    $0x4,%eax
jl     1185 <htol+0x55>
mov    %eax,%r14d
lea    -0x2(%r14),%eax
add    $0xfffffffd,%r14d
add    %rax,%r15
xor    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
movsbl (%r15),%edi
call   1040 <hex_symb@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1030 <hex_degree@plt>
imul   %r12d,%eax
add    %eax,%ebp
add    $0x1,%ebx
add    $0xffffffffffffffff,%r15
cmp    %ebx,%r14d
jne    1160 <htol+0x30>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @htol(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i8 0, i8* %8
%9 = load i8*, i8** %2
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %3
br label %13
13: ; preds = %32, %1
%14 = load i32, i32* %3
%15 = icmp sge i32 %14, 2
br i1 %15, label %16, label %35
16: ; preds = %13
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i32 @hex_symb(i8 signext %21)
store i32 %22, i32* %4
%23 = load i32, i32* %5
%24 = call i32 @hex_degree(i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %6
%26 = load i32, i32* %7
%27 = load i32, i32* %4
%28 = mul nsw i32 %26, %27
%29 = add nsw i32 %25, %28
store i32 %29, i32* %6
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %32
32: ; preds = %16
%33 = load i32, i32* %3
%34 = add nsw i32 %33, -1
store i32 %34, i32* %3
br label %13
35: ; preds = %13
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
define i32 @htol(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 3
br i1 %3, label %4, label %21
4: ; preds = %1
%5 = add nsw i32 %2, -2
%6 = zext i32 %5 to i64
%7 = add nsw i32 %2, -3
br label %8
8: ; preds = %4, %8
%9 = phi i64 [ %6, %4 ], [ %19, %8 ]
%10 = phi i32 [ 0, %4 ], [ %17, %8 ]
%11 = phi i32 [ 0, %4 ], [ %18, %8 ]
%12 = getelementptr inbounds i8, i8* %0, i64 %9
%13 = load i8, i8* %12
%14 = tail call i32 @hex_symb(i8 signext %13)
%15 = tail call i32 @hex_degree(i32 %11)
%16 = mul nsw i32 %15, %14
%17 = add nsw i32 %16, %10
%18 = add nuw nsw i32 %11, 1
%19 = add nsw i64 %9, -1
%20 = icmp eq i32 %18, %7
br i1 %20, label %21, label %8
21: ; preds = %8, %1
%22 = phi i32 [ 0, %1 ], [ %17, %8 ]
ret i32 %22
}