#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 char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ abort();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
scalar_t__ strncmp(char *, char *, int);
int atoi_any(char *arg, uint8_t *sizep) {
  int value;
  if (strncmp(arg, "0x", 2) != 0)
    sscanf(arg, "%u", &value);
  else
    sscanf(arg, "0x%x", &value);
  if (sizep) {
    char *sp;
    if ((sp = strchr(arg, '/')))
      switch (*++sp) {
      default:
        fprintf(stderr, "Bad size specifier: must be 1, 2, or 4");
        abort();
      case '1':
      case '2':
      case '4':
      case '8':
        *sizep = *sp - '0';
      }
    else
      *sizep = 4;
  }
  return value;
}


x86 assembly (clang, -O0):
<atoi_any>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1198 <atoi_any+0x48>
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
jmp    11ac <atoi_any+0x5c>
mov    -0x8(%rbp),%rdi
lea    0xe63(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1070 <sscanf@plt>
cmpq   $0x0,-0x10(%rbp)
je     125b <atoi_any+0x10b>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     124f <atoi_any+0xff>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movsbl 0x1(%rax),%eax
mov    %eax,-0x24(%rbp)
add    $0xffffffcf,%eax
sub    $0x2,%eax
jb     1238 <atoi_any+0xe8>
jmp    11fa <atoi_any+0xaa>
mov    -0x24(%rbp),%eax
sub    $0x34,%eax
je     1238 <atoi_any+0xe8>
jmp    120b <atoi_any+0xbb>
mov    -0x24(%rbp),%eax
sub    $0x38,%eax
je     1238 <atoi_any+0xe8>
jmp    121c <atoi_any+0xcc>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
lea    0xddf(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
jmp    1256 <atoi_any+0x106>
mov    -0x10(%rbp),%rax
movb   $0x4,(%rax)
jmp    125b <atoi_any+0x10b>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<atoi_any>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe9f(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
lea    0xe91(%rip),%rax
lea    0xe87(%rip),%rsi
cmove  %rax,%rsi
lea    0x4(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
test   %r14,%r14
je     11c6 <atoi_any+0x76>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11c1 <atoi_any+0x71>
movsbl 0x1(%rax),%eax
cmp    $0x38,%eax
ja     11d2 <atoi_any+0x82>
movabs $0x116000000000000,%rcx
bt     %rax,%rcx
jae    11d2 <atoi_any+0x82>
add    $0xd0,%al
jmp    11c3 <atoi_any+0x73>
mov    $0x4,%al
mov    %al,(%r14)
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [5 x i8] c"0x%x\00"
@stderr = global i32 0
@.str.3 = [39 x i8] c"Bad size specifier: must be 1, 2, or 4\00"
define i32 @atoi_any(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 @sscanf(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %5)
br label %16
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call i32 @sscanf(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* %5)
br label %16
16: ; preds = %13, %10
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %43
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i8* @strchr(i8* %20, i8 signext 47)
store i8* %21, i8** %6
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %40
23: ; preds = %19
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %6
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
switch i32 %27, label %28 [
i32 49, label %32
i32 50, label %32
i32 52, label %32
i32 56, label %32
]
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %23, %23, %23, %23
%33 = load i8*, i8** %6
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = sub nsw i32 %35, 48
%37 = trunc i32 %36 to i8
%38 = load i8*, i8** %4
store i8 %37, i8* %38
br label %39
39: ; preds = %32
br label %42
40: ; preds = %19
%41 = load i8*, i8** %4
store i8 4, i8* %41
br label %42
42: ; preds = %40, %39
br label %43
43: ; preds = %42, %16
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@.str = [3 x i8] c"0x\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [5 x i8] c"0x%x\00"
@stderr = global i32 0
@.str.3 = [39 x i8] c"Bad size specifier: must be 1, 2, or 4\00"
define i32 @atoi_any(i8* %0, i8* writeonly %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%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 ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%8 = call i32 @sscanf(i8* %0, i8* %7, i32* %3)
%9 = icmp eq i8* %1, null
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = getelementptr inbounds i8, i8* %11, i64 1
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %17 [
i32 49, label %21
i32 50, label %21
i32 52, label %21
i32 56, label %21
]
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0))
%20 = call i32 (...) @abort()
unreachable
21: ; preds = %13, %13, %13, %13
%22 = add i8 %15, -48
br label %23
23: ; preds = %10, %21
%24 = phi i8 [ %22, %21 ], [ 4, %10 ]
store i8 %24, i8* %1
br label %25
25: ; preds = %23, %2
%26 = load i32, i32* %3
ret i32 %26
}