#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 sscanf(char const *, char *, int /*<<< orphan*/ *, char *);
scalar_t__ strncmp(char const *, char *, int);
int HexStringToUint32(const char *string, uint32_t *value) {
  char tail[1];
  char *format = strncmp(string, "0x", 2) ? "%8x%1s" : "0x%8x%1s";
  int n = sscanf(string, format, value, tail);
  return n != 1;
}


x86 assembly (clang, -O0):
<HexStringToUint32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec5(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
mov    %rax,%rdx
lea    0xeb4(%rip),%rax
lea    0xeaf(%rip),%rcx
cmp    $0x0,%rdx
cmovne %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    -0x11(%rbp),%rcx
call   1040 <sscanf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HexStringToUint32>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xecf(%rip),%rsi
mov    $0x2,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0xebe(%rip),%rax
lea    0xeb9(%rip),%rsi
cmove  %rax,%rsi
lea    0x7(%rsp),%rcx
mov    %rbx,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
setne  %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [7 x i8] c"%8x%1s\00"
@.str.2 = [9 x i8] c"0x%8x%1s\00"
define i32 @HexStringToUint32(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [1 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i32* %1, i32** %4
%8 = load i8*, i8** %3
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%10 = icmp ne i64 %9, 0
%11 = zext i1 %10 to i64
%12 = select i1 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0)
store i8* %12, i8** %6
%13 = load i8*, i8** %3
%14 = load i8*, i8** %6
%15 = load i32*, i32** %4
%16 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%17 = call i32 @sscanf(i8* %13, i8* %14, i32* %15, i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = icmp ne i32 %18, 1
%20 = zext i1 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [7 x i8] c"%8x%1s\00"
@.str.2 = [9 x i8] c"0x%8x%1s\00"
define i32 @HexStringToUint32(i8* %0, i32* %1) {
%3 = alloca [1 x i8]
%4 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%6 = icmp eq i64 %5, 0
%7 = select i1 %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0)
%8 = call i32 @sscanf(i8* %0, i8* %7, i32* %1, i8* %4)
%9 = icmp ne i32 %8, 1
%10 = zext i1 %9 to i32
ret i32 %10
}