#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 atoul(char *, unsigned int *);
int atoulx(char *, unsigned int *);
int StrToNumber(char *str, unsigned int *pulValue) {
  if (*str == '0' && (*(str + 1) == 'x' || *(str + 1) == 'X')) {
    if (*(str + 2) == '\0') {
      return -1;
    } else {
      return atoulx(str + 2, pulValue);
    }
  } else {
    return atoul(str, pulValue);
  }
}


x86 assembly (clang, -O0):
<StrToNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1198 <StrToNumber+0x78>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     1162 <StrToNumber+0x42>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    1198 <StrToNumber+0x78>
mov    -0x10(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    117f <StrToNumber+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a8 <StrToNumber+0x88>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
mov    -0x18(%rbp),%rsi
call   1040 <atoulx@plt>
mov    %eax,-0x4(%rbp)
jmp    11a8 <StrToNumber+0x88>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <atoul@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StrToNumber>:
cmpb   $0x30,(%rdi)
jne    113d <StrToNumber+0x1d>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    113d <StrToNumber+0x1d>
cmpb   $0x0,0x2(%rdi)
je     1142 <StrToNumber+0x22>
add    $0x2,%rdi
jmp    1040 <atoulx@plt>
jmp    1030 <atoul@plt>
mov    $0xffffffff,%eax
ret

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

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