#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*/ *strchr(char *, char const);
int strlen(char const *);
int _sarg_get_number_base(const char *arg) {
  int len = strlen(arg);
  int base = 10;
  if (len > 2) {
    if ((arg[0] == '0' && strchr("1234567", arg[1]) != NULL))
      base = 8;
    if ((arg[0] == '0' && arg[1] == 'x'))
      base = 16;
  }
  return base;
}


x86 assembly (clang, -O0):
<_sarg_get_number_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0xa,-0x10(%rbp)
cmpl   $0x2,-0xc(%rbp)
jle    11ab <_sarg_get_number_base+0x8b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    117e <_sarg_get_number_base+0x5e>
mov    -0x8(%rbp),%rax
lea    0xe9c(%rip),%rdi
movsbl 0x1(%rax),%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     117e <_sarg_get_number_base+0x5e>
movl   $0x8,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11a6 <_sarg_get_number_base+0x86>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11a6 <_sarg_get_number_base+0x86>
movl   $0x10,-0x10(%rbp)
jmp    11ab <_sarg_get_number_base+0x8b>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_sarg_get_number_base>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    $0xa,%eax
cmp    $0x3,%ecx
jl     1169 <_sarg_get_number_base+0x49>
cmpb   $0x30,(%rbx)
jne    1169 <_sarg_get_number_base+0x49>
movsbl 0x1(%rbx),%esi
lea    0xebb(%rip),%rdi
call   1040 <strchr@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,1),%eax
add    $0x8,%eax
cmpb   $0x30,(%rbx)
jne    1169 <_sarg_get_number_base+0x49>
cmpb   $0x78,0x1(%rbx)
mov    $0x10,%ecx
cmove  %ecx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"1234567\00"
define i32 @_sarg_get_number_base(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %3
store i32 10, i32* %4
%7 = load i32, i32* %3
%8 = icmp sgt i32 %7, 2
br i1 %8, label %9, label %36
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 48
br i1 %14, label %15, label %22
15: ; preds = %9
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = call i32* @strchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 8, i32* %4
br label %22
22: ; preds = %21, %15, %9
%23 = load i8*, i8** %2
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 48
br i1 %27, label %28, label %35
28: ; preds = %22
%29 = load i8*, i8** %2
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 120
br i1 %33, label %34, label %35
34: ; preds = %28
store i32 16, i32* %4
br label %35
35: ; preds = %34, %28, %22
br label %36
36: ; preds = %35, %1
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
@.str = [8 x i8] c"1234567\00"
define i32 @_sarg_get_number_base(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 2
br i1 %3, label %4, label %19
4: ; preds = %1
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 48
br i1 %6, label %7, label %19
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
%10 = tail call i32* @strchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %9)
%11 = icmp eq i32* %10, null
%12 = select i1 %11, i32 10, i32 8
%13 = load i8, i8* %0
%14 = icmp eq i8 %13, 48
br i1 %14, label %15, label %19
15: ; preds = %7
%16 = load i8, i8* %8
%17 = icmp eq i8 %16, 120
%18 = select i1 %17, i32 16, i32 %12
br label %19
19: ; preds = %4, %15, %7, %1
%20 = phi i32 [ %12, %7 ], [ 10, %1 ], [ %18, %15 ], [ 10, %4 ]
ret i32 %20
}