#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 a2hex(char *);
int atoi(char *);
int /*<<< orphan*/ ishexstring(char *);
int /*<<< orphan*/ strncasecmp(char *, char *, int);
int atoval(char *buf) {
  if (!strncasecmp(buf, "0x", 2))
    return a2hex(buf + 2);
  else if (!ishexstring(buf))
    return a2hex(buf);
  else
    return atoi(buf);
}


x86 assembly (clang, -O0):
<atoval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncasecmp@plt>
cmp    $0x0,%eax
jne    117f <atoval+0x3f>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
call   1060 <a2hex@plt>
mov    %eax,-0x4(%rbp)
jmp    11ae <atoval+0x6e>
mov    -0x10(%rbp),%rdi
call   1040 <ishexstring@plt>
cmp    $0x0,%eax
jne    11a2 <atoval+0x62>
mov    -0x10(%rbp),%rdi
call   1060 <a2hex@plt>
mov    %eax,-0x4(%rbp)
jmp    11ae <atoval+0x6e>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoval>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncasecmp@plt>
test   %eax,%eax
je     116e <atoval+0x2e>
mov    %rbx,%rdi
call   1040 <ishexstring@plt>
test   %eax,%eax
je     1172 <atoval+0x32>
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <atoi@plt>
add    $0x2,%rbx
mov    %rbx,%rdi
pop    %rbx
jmp    1060 <a2hex@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
define i32 @atoval(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i32 @strncasecmp(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp ne i32 %5, 0
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 2
%10 = call i32 @a2hex(i8* %9)
store i32 %10, i32* %2
br label %21
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @ishexstring(i8* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 @a2hex(i8* %16)
store i32 %17, i32* %2
br label %21
18: ; preds = %11
%19 = load i8*, i8** %3
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %2
br label %21
21: ; preds = %18, %15, %7
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
define i32 @atoval(i8* %0) {
%2 = tail call i32 @strncasecmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 2
%6 = tail call i32 @a2hex(i8* %5)
br label %14
7: ; preds = %1
%8 = tail call i32 @ishexstring(i8* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @a2hex(i8* %0)
br label %14
12: ; preds = %7
%13 = tail call i32 @atoi(i8* %0)
br label %14
14: ; preds = %12, %10, %4
%15 = phi i32 [ %13, %12 ], [ %11, %10 ], [ %6, %4 ]
ret i32 %15
}