#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 */
scalar_t__ isxdigit(char const);
int guess_base(const char *s) {
  if (s[0] == '0') {
    if ((s[1] == 'x' || s[1] == 'X') && isxdigit(s[2])) {
      return 16;
    } else {
      return 8;
    }
  } else {
    return 10;
  }
}


x86 assembly (clang, -O0):
<guess_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    117d <guess_base+0x6d>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     114e <guess_base+0x3e>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    1171 <guess_base+0x61>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <isxdigit@plt>
cmp    $0x0,%rax
je     1171 <guess_base+0x61>
movl   $0x10,-0x4(%rbp)
jmp    1184 <guess_base+0x74>
movl   $0x8,-0x4(%rbp)
jmp    1184 <guess_base+0x74>
movl   $0xa,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<guess_base>:
push   %rax
mov    $0xa,%eax
cmpb   $0x30,(%rdi)
jne    113a <guess_base+0x2a>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    113c <guess_base+0x2c>
movsbl 0x2(%rdi),%edi
call   1030 <isxdigit@plt>
mov    %rax,%rcx
mov    $0x10,%eax
test   %rcx,%rcx
je     113c <guess_base+0x2c>
pop    %rcx
ret
mov    $0x8,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @guess_base(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp eq i32 %7, 48
br i1 %8, label %9, label %29
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 120
br i1 %14, label %21, label %15
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 88
br i1 %20, label %21, label %28
21: ; preds = %15, %9
%22 = load i8*, i8** %3
%23 = getelementptr inbounds i8, i8* %22, i64 2
%24 = load i8, i8* %23
%25 = call i64 @isxdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
store i32 16, i32* %2
br label %30
28: ; preds = %21, %15
store i32 8, i32* %2
br label %30
29: ; preds = %1
store i32 10, i32* %2
br label %30
30: ; preds = %29, %28, %27
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
define i32 @guess_base(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 48
br i1 %3, label %4, label %13
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
switch i8 %6, label %12 [
i8 120, label %7
i8 88, label %7
]
7: ; preds = %4, %4
%8 = getelementptr inbounds i8, i8* %0, i64 2
%9 = load i8, i8* %8
%10 = tail call i64 @isxdigit(i8 signext %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %4, %7
br label %13
13: ; preds = %1, %7, %12
%14 = phi i32 [ 8, %12 ], [ 16, %7 ], [ 10, %1 ]
ret i32 %14
}