#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__ isspace(char const);
char toupper(char const);
char *find_base_and_sign(const char *src, int *sign, int *base) {
  while (isspace(src[0]))
    src++;
  *sign = 1;
  if (src[0] == '-') {
    src++;
    *sign = -1;
  }
  if (*base == 0) {
    if (src[0] == '0') {
      src++;
      if (toupper(src[0]) == 'X') {
        src++;
        *base = 16;
      } else if (toupper(src[0]) == 'B') {
        src++;
        *base = 2;
      } else
        *base = 8;
    } else
      *base = 10;
  }
  return (char *)src;
}


x86 assembly (clang, -O0):
<find_base_and_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     115b <find_base_and_sign+0x3b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1134 <find_base_and_sign+0x14>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    118b <find_base_and_sign+0x6b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    123d <find_base_and_sign+0x11d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    122e <find_base_and_sign+0x10e>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x58,%eax
jne    11e7 <find_base_and_sign+0xc7>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x10,(%rax)
jmp    1229 <find_base_and_sign+0x109>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
movsbl %al,%eax
cmp    $0x42,%eax
jne    121a <find_base_and_sign+0xfa>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x2,(%rax)
jmp    1224 <find_base_and_sign+0x104>
mov    -0x18(%rbp),%rax
movl   $0x8,(%rax)
jmp    1229 <find_base_and_sign+0x109>
jmp    1238 <find_base_and_sign+0x118>
mov    -0x18(%rbp),%rax
movl   $0xa,(%rax)
jmp    123d <find_base_and_sign+0x11d>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_base_and_sign>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl (%rbx),%edi
call   1040 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1140 <find_base_and_sign+0x20>
movl   $0x1,(%r12)
xor    %eax,%eax
cmpb   $0x2d,-0x1(%rbx)
lea    -0x1(%rbx),%r15
setne  %al
lea    -0x1(%rax,%rax,1),%eax
mov    %eax,(%r12)
cmove  %rbx,%r15
cmpl   $0x0,(%r14)
jne    11c4 <find_base_and_sign+0xa4>
mov    $0xa,%eax
cmpb   $0x30,(%r15)
jne    11c1 <find_base_and_sign+0xa1>
movsbl 0x1(%r15),%edi
call   1030 <toupper@plt>
cmp    $0x58,%al
jne    119c <find_base_and_sign+0x7c>
add    $0x2,%r15
mov    $0x10,%eax
jmp    11c1 <find_base_and_sign+0xa1>
lea    0x1(%r15),%rbx
movsbl 0x1(%r15),%edi
call   1030 <toupper@plt>
add    $0x2,%r15
cmp    $0x42,%al
mov    $0x2,%ecx
mov    $0x8,%eax
cmove  %ecx,%eax
cmovne %rbx,%r15
mov    %eax,(%r14)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @find_base_and_sign(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
br label %7
7: ; preds = %13, %3
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = call i64 @isspace(i8 signext %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
br label %7
16: ; preds = %7
%17 = load i32*, i32** %5
store i32 1, i32* %17
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %27
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i32*, i32** %5
store i32 -1, i32* %26
br label %27
27: ; preds = %23, %16
%28 = load i32*, i32** %6
%29 = load i32, i32* %28
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %68
31: ; preds = %27
%32 = load i8*, i8** %4
%33 = getelementptr inbounds i8, i8* %32, i64 0
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 48
br i1 %36, label %37, label %65
37: ; preds = %31
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %4
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = call signext i8 @toupper(i8 signext %42)
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 88
br i1 %45, label %46, label %50
46: ; preds = %37
%47 = load i8*, i8** %4
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %4
%49 = load i32*, i32** %6
store i32 16, i32* %49
br label %64
50: ; preds = %37
%51 = load i8*, i8** %4
%52 = getelementptr inbounds i8, i8* %51, i64 0
%53 = load i8, i8* %52
%54 = call signext i8 @toupper(i8 signext %53)
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 66
br i1 %56, label %57, label %61
57: ; preds = %50
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i32 1
store i8* %59, i8** %4
%60 = load i32*, i32** %6
store i32 2, i32* %60
br label %63
61: ; preds = %50
%62 = load i32*, i32** %6
store i32 8, i32* %62
br label %63
63: ; preds = %61, %57
br label %64
64: ; preds = %63, %46
br label %67
65: ; preds = %31
%66 = load i32*, i32** %6
store i32 10, i32* %66
br label %67
67: ; preds = %65, %64
br label %68
68: ; preds = %67, %27
%69 = load i8*, i8** %4
ret i8* %69
}

LLVM IR (-O2):
define i8* @find_base_and_sign(i8* %0, i32* nocapture writeonly %1, i32* nocapture %2) {
br label %4
4: ; preds = %4, %3
%5 = phi i8* [ %0, %3 ], [ %9, %4 ]
%6 = load i8, i8* %5
%7 = tail call i64 @isspace(i8 signext %6)
%8 = icmp eq i64 %7, 0
%9 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %8, label %10, label %4
10: ; preds = %4
store i32 1, i32* %1
%11 = load i8, i8* %5
%12 = icmp eq i8 %11, 45
%13 = select i1 %12, i32 -1, i32 1
store i32 %13, i32* %1
%14 = select i1 %12, i8* %9, i8* %5
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %37
17: ; preds = %10
%18 = load i8, i8* %14
%19 = icmp eq i8 %18, 48
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = getelementptr inbounds i8, i8* %14, i64 1
%22 = load i8, i8* %21
%23 = tail call signext i8 @toupper(i8 signext %22)
%24 = icmp eq i8 %23, 88
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = getelementptr inbounds i8, i8* %14, i64 2
br label %34
27: ; preds = %20
%28 = load i8, i8* %21
%29 = tail call signext i8 @toupper(i8 signext %28)
%30 = icmp eq i8 %29, 66
%31 = getelementptr inbounds i8, i8* %14, i64 2
%32 = select i1 %30, i32 2, i32 8
%33 = select i1 %30, i8* %31, i8* %21
br label %34
34: ; preds = %27, %17, %25
%35 = phi i32 [ 16, %25 ], [ 10, %17 ], [ %32, %27 ]
%36 = phi i8* [ %26, %25 ], [ %14, %17 ], [ %33, %27 ]
store i32 %35, i32* %2
br label %37
37: ; preds = %34, %10
%38 = phi i8* [ %14, %10 ], [ %36, %34 ]
ret i8* %38
}