#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sscanf(char const *, char *, int /*<<< orphan*/ *);
uint32_t getOffset(const char *str) {
  uint32_t ret = 0;
  if (str == NULL || *str == '\0')
    return ret;
  if (str[0] == '0' && (str[1] == 'X' || str[1] == 'x')) {
    str += 2;
    sscanf(str, "%x", &ret);
  } else
    sscanf(str, "%d", &ret);
  return ret;
}


x86 assembly (clang, -O0):
<getOffset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     113e <getOffset+0x2e>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1149 <getOffset+0x39>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ba <getOffset+0xaa>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    11a0 <getOffset+0x90>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
je     117b <getOffset+0x6b>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
jne    11a0 <getOffset+0x90>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe6e(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <sscanf@plt>
jmp    11b4 <getOffset+0xa4>
mov    -0x10(%rbp),%rdi
lea    0xe58(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getOffset>:
push   %rax
movl   $0x0,0x4(%rsp)
test   %rdi,%rdi
je     114f <getOffset+0x3f>
mov    (%rdi),%al
test   %al,%al
je     114f <getOffset+0x3f>
cmp    $0x30,%al
jne    113e <getOffset+0x2e>
mov    0x1(%rdi),%al
or     $0x20,%al
cmp    $0x78,%al
jne    113e <getOffset+0x2e>
add    $0x2,%rdi
lea    0xec4(%rip),%rsi
jmp    1145 <getOffset+0x35>
lea    0xebe(%rip),%rsi
lea    0x4(%rsp),%rdx
call   1030 <sscanf@plt>
mov    0x4(%rsp),%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @getOffset(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = icmp eq i8* %0, null
br i1 %4, label %15, label %5
5: ; preds = %1
%6 = load i8, i8* %0
switch i8 %6, label %13 [
i8 0, label %15
i8 48, label %7
]
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = load i8, i8* %8
switch i8 %9, label %13 [
i8 88, label %10
i8 120, label %10
]
10: ; preds = %7, %7
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %15
13: ; preds = %7, %5
%14 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
br label %15
15: ; preds = %10, %13, %5, %1
%16 = load i32, i32* %2
ret i32 %16
}