#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*/ fatalError(char *);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int from_hexa(const char *s) {
  char aux[60];
  if (strlen(s) > 59) {
    fatalError("Hexadecimal number is too long");
  }
  strncpy(aux, s, strlen(s));
  aux[strlen(s)] = 0x0;
  if (aux[strlen(aux) - 1] == 'H' || aux[strlen(aux) - 1] == 'h') {
    aux[strlen(aux) - 1] = 0x0;
  }
  return (int)strtol(aux, NULL, 16);
}


x86 assembly (clang, -O0):
<from_hexa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3b,%eax
jle    116a <from_hexa+0x2a>
lea    0xe9b(%rip),%rdi
call   1060 <fatalError@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x48,%eax
je     11da <from_hexa+0x9a>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x68,%eax
jne    11ed <from_hexa+0xad>
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<from_hexa>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    $0x3c,%eax
jl     1160 <from_hexa+0x20>
lea    0xea5(%rip),%rdi
call   1060 <fatalError@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rsp,%r14
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x48,-0x1(%rax,%r14,1)
je     11aa <from_hexa+0x6a>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmpb   $0x68,-0x1(%rax,%r14,1)
jne    11ba <from_hexa+0x7a>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Hexadecimal number is too long\00"
define i32 @from_hexa(i8* %0) {
%2 = alloca i8*
%3 = alloca [60 x i8]
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %5, 59
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @fatalError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %1
%10 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%11 = load i8*, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @strlen(i8* %12)
%14 = call i32 @strncpy(i8* %10, i8* %11, i32 %13)
%15 = load i8*, i8** %2
%16 = call i32 @strlen(i8* %15)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 72
br i1 %26, label %36, label %27
27: ; preds = %9
%28 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 104
br i1 %35, label %36, label %42
36: ; preds = %27, %9
%37 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%38 = call i32 @strlen(i8* %37)
%39 = sub nsw i32 %38, 1
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 %40
store i8 0, i8* %41
br label %42
42: ; preds = %36, %27
%43 = getelementptr inbounds [60 x i8], [60 x i8]* %3, i64 0, i64 0
%44 = call i64 @strtol(i8* %43, i32* null, i32 16)
%45 = trunc i64 %44 to i32
ret i32 %45
}

LLVM IR (-O2):
@.str = [31 x i8] c"Hexadecimal number is too long\00"
define i32 @from_hexa(i8* %0) {
%2 = alloca [60 x i8]
%3 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 59
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @fatalError(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = tail call i32 @strlen(i8* %0)
%10 = call i32 @strncpy(i8* %3, i8* %0, i32 %9)
%11 = call i32 @strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %12
store i8 0, i8* %13
%14 = call i32 @strlen(i8* %3)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 72
br i1 %19, label %27, label %20
20: ; preds = %8
%21 = call i32 @strlen(i8* %3)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 104
br i1 %26, label %27, label %32
27: ; preds = %20, %8
%28 = call i32 @strlen(i8* %3)
%29 = add nsw i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [60 x i8], [60 x i8]* %2, i64 0, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %27, %20
%33 = call i64 @strtol(i8* nocapture %3, i32* null, i32 16)
%34 = trunc i64 %33 to i32
ret i32 %34
}