#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 */
unsigned int atoi(unsigned char *);
scalar_t__ isdigit(unsigned char);
int /*<<< orphan*/ sscanf(unsigned char *, char *, unsigned int *);
char toupper(unsigned char);
unsigned int str2u32(unsigned char *u32str) {
  unsigned int ret = 0;
  if (u32str[0] == '0') {
    if (toupper(u32str[1]) == 'X')
      sscanf(u32str, "%x", &ret);
    else
      sscanf(u32str, "%o", &ret);
  } else if (isdigit(u32str[0])) {
    ret = atoi(u32str);
  } else {
    int i;
    ret = 0;
    for (i = 0; i < 4 && u32str[i]; i++)
      ret |= ((unsigned int)u32str[i]) << (8 * i);
  }
  return ret;
}


x86 assembly (clang, -O0):
<str2u32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x30,%eax
jne    11ae <str2u32+0x6e>
mov    -0x8(%rbp),%rax
movzbl 0x1(%rax),%edi
call   1040 <toupper@plt>
movsbl %al,%eax
cmp    $0x58,%eax
jne    1195 <str2u32+0x55>
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
jmp    11a9 <str2u32+0x69>
mov    -0x8(%rbp),%rdi
lea    0xe63(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1050 <sscanf@plt>
jmp    1249 <str2u32+0x109>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11d5 <str2u32+0x95>
mov    -0x8(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0xc(%rbp)
jmp    1244 <str2u32+0x104>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x4,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jge    1207 <str2u32+0xc7>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1217 <str2u32+0xd7>
jmp    123f <str2u32+0xff>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    -0x10(%rbp),%ecx
shl    $0x3,%ecx
shl    %cl,%eax
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e3 <str2u32+0xa3>
jmp    1244 <str2u32+0x104>
jmp    1249 <str2u32+0x109>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2u32>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
mov    (%rdi),%al
cmp    $0x30,%al
jne    116c <str2u32+0x2c>
movzbl 0x1(%rbx),%edi
call   1040 <toupper@plt>
cmp    $0x58,%al
jne    1187 <str2u32+0x47>
lea    0xe96(%rip),%rsi
jmp    118e <str2u32+0x4e>
movzbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     119d <str2u32+0x5d>
mov    %rbx,%rdi
call   1060 <atoi@plt>
mov    %eax,0xc(%rsp)
jmp    11d5 <str2u32+0x95>
lea    0xe75(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1050 <sscanf@plt>
jmp    11d5 <str2u32+0x95>
movzbl (%rbx),%ecx
test   %ecx,%ecx
je     11cf <str2u32+0x8f>
movzbl 0x1(%rbx),%eax
test   %eax,%eax
je     11d1 <str2u32+0x91>
shl    $0x8,%eax
or     %ecx,%eax
movzbl 0x2(%rbx),%ecx
test   %ecx,%ecx
je     11cb <str2u32+0x8b>
shl    $0x10,%ecx
or     %ecx,%eax
movzbl 0x3(%rbx),%ecx
test   %ecx,%ecx
je     11cb <str2u32+0x8b>
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,%ecx
jmp    11d1 <str2u32+0x91>
xor    %ecx,%ecx
mov    %ecx,0xc(%rsp)
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%x\00"
@.str.1 = [3 x i8] c"%o\00"
define i32 @str2u32(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
%5 = load i8*, i8** %2
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = zext i8 %7 to i32
%9 = icmp eq i32 %8, 48
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = call signext i8 @toupper(i8 zeroext %13)
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 88
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i8*, i8** %2
%19 = call i32 @sscanf(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %23
20: ; preds = %10
%21 = load i8*, i8** %2
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
br label %23
23: ; preds = %20, %17
br label %64
24: ; preds = %1
%25 = load i8*, i8** %2
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = call i64 @isdigit(i8 zeroext %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = load i8*, i8** %2
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %3
br label %63
33: ; preds = %24
store i32 0, i32* %3
store i32 0, i32* %4
br label %34
34: ; preds = %59, %33
%35 = load i32, i32* %4
%36 = icmp slt i32 %35, 4
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = load i8*, i8** %2
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = zext i8 %42 to i32
%44 = icmp ne i32 %43, 0
br label %45
45: ; preds = %37, %34
%46 = phi i1 [ false, %34 ], [ %44, %37 ]
br i1 %46, label %47, label %62
47: ; preds = %45
%48 = load i8*, i8** %2
%49 = load i32, i32* %4
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = load i32, i32* %4
%55 = mul nsw i32 8, %54
%56 = shl i32 %53, %55
%57 = load i32, i32* %3
%58 = or i32 %57, %56
store i32 %58, i32* %3
br label %59
59: ; preds = %47
%60 = load i32, i32* %4
%61 = add nsw i32 %60, 1
store i32 %61, i32* %4
br label %34
62: ; preds = %45
br label %63
63: ; preds = %62, %30
br label %64
64: ; preds = %63, %23
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [3 x i8] c"%x\00"
@.str.1 = [3 x i8] c"%o\00"
define i32 @str2u32(i8* nocapture %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 48
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = tail call signext i8 @toupper(i8 zeroext %8)
%10 = icmp eq i8 %9, 88
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %48
13: ; preds = %6
%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 %48
15: ; preds = %1
%16 = tail call i64 @isdigit(i8 zeroext %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @atoi(i8* %0)
store i32 %19, i32* %2
br label %48
20: ; preds = %15
%21 = load i8, i8* %0
%22 = icmp eq i8 %21, 0
br i1 %22, label %46, label %23
23: ; preds = %20
%24 = zext i8 %21 to i32
%25 = getelementptr inbounds i8, i8* %0, i64 1
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %46, label %28
28: ; preds = %23
%29 = zext i8 %26 to i32
%30 = shl nuw nsw i32 %29, 8
%31 = or i32 %30, %24
%32 = getelementptr inbounds i8, i8* %0, i64 2
%33 = load i8, i8* %32
%34 = icmp eq i8 %33, 0
br i1 %34, label %46, label %35
35: ; preds = %28
%36 = zext i8 %33 to i32
%37 = shl nuw nsw i32 %36, 16
%38 = or i32 %31, %37
%39 = getelementptr inbounds i8, i8* %0, i64 3
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
br i1 %41, label %46, label %42
42: ; preds = %35
%43 = zext i8 %40 to i32
%44 = shl nuw i32 %43, 24
%45 = or i32 %38, %44
br label %46
46: ; preds = %42, %35, %28, %23, %20
%47 = phi i32 [ 0, %20 ], [ %24, %23 ], [ %31, %28 ], [ %38, %35 ], [ %45, %42 ]
store i32 %47, i32* %2
br label %48
48: ; preds = %46, %18, %11, %13
%49 = load i32, i32* %2
ret i32 %49
}