#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*/ sscanf(char const *, char *, unsigned long *);
void *script_str2ptr(const char *pointer_str) {
  long unsigned int value;
  if (!pointer_str || (pointer_str[0] != '0') || (pointer_str[1] != 'x'))
    return NULL;
  sscanf(pointer_str + 2, "%lx", &value);
  return (void *)value;
}


x86 assembly (clang, -O0):
<script_str2ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1148 <script_str2ptr+0x38>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jne    1148 <script_str2ptr+0x38>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     1155 <script_str2ptr+0x45>
movq   $0x0,-0x8(%rbp)
jmp    1175 <script_str2ptr+0x65>
mov    -0x10(%rbp),%rdi
add    $0x2,%rdi
lea    0xe9c(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<script_str2ptr>:
push   %rax
test   %rdi,%rdi
je     113a <script_str2ptr+0x2a>
cmpb   $0x30,(%rdi)
jne    113a <script_str2ptr+0x2a>
cmpb   $0x78,0x1(%rdi)
jne    113a <script_str2ptr+0x2a>
add    $0x2,%rdi
lea    0xed4(%rip),%rsi
mov    %rsp,%rdx
call   1030 <sscanf@plt>
mov    (%rsp),%rax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%lx\00"
define i8* @script_str2ptr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %19
7: ; preds = %1
%8 = load i8*, i8** %3
%9 = getelementptr inbounds i8, i8* %8, i64 0
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 48
br i1 %12, label %19, label %13
13: ; preds = %7
%14 = load i8*, i8** %3
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 120
br i1 %18, label %19, label %20
19: ; preds = %13, %7, %1
store i8* null, i8** %2
br label %26
20: ; preds = %13
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %4)
%24 = load i64, i64* %4
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %2
br label %26
26: ; preds = %20, %19
%27 = load i8*, i8** %2
ret i8* %27
}

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