#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 */
scalar_t__ isspace(char const);
unsigned long strtoul(char const *, char **, int);
scalar_t__ toupper(char);
unsigned long int strtol0X(const char *str, const char **endptr, char X,
                           int base) {
  unsigned long int val;
  const char *ptr = str;
  while (isspace(*ptr))
    ptr++;
  if ((*ptr++) != '0') {
    *endptr = str;
    return 0;
  }
  if (toupper(*ptr++) != toupper(X)) {
    *endptr = str;
    return 0;
  }
  val = strtoul(ptr, (char **)endptr, base);
  if (*endptr == ptr) {
    *endptr = str;
    return 0;
  }
  return val;
}


x86 assembly (clang, -O0):
<strtol0X>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %ecx,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     1177 <strtol0X+0x47>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1150 <strtol0X+0x20>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movsbl (%rax),%eax
cmp    $0x30,%eax
je     11aa <strtol0X+0x7a>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    123b <strtol0X+0x10b>
mov    -0x30(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x30(%rbp)
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %rax,-0x38(%rbp)
movsbl -0x19(%rbp),%edi
call   1030 <toupper@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     11f6 <strtol0X+0xc6>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    123b <strtol0X+0x10b>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1050 <strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
cmp    -0x30(%rbp),%rax
jne    1233 <strtol0X+0x103>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
jmp    123b <strtol0X+0x10b>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtol0X>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x1(%rdi),%rbp
nopl   0x0(%rax,%rax,1)
movsbl -0x1(%rbp),%edi
call   1040 <isspace@plt>
add    $0x1,%rbp
test   %rax,%rax
jne    1150 <strtol0X+0x20>
cmpb   $0x30,-0x2(%rbp)
jne    1195 <strtol0X+0x65>
movsbl -0x1(%rbp),%edi
call   1030 <toupper@plt>
mov    %rax,%r13
movsbl %r12b,%edi
call   1030 <toupper@plt>
cmp    %rax,%r13
jne    1195 <strtol0X+0x65>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1050 <strtoul@plt>
cmp    (%r14),%rbp
jne    119a <strtol0X+0x6a>
mov    %rbx,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i64 @strtol0X(i8* %0, i8** %1, i8 signext %2, i32 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %6
store i8** %1, i8*** %7
store i8 %2, i8* %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
store i8* %12, i8** %11
br label %13
13: ; preds = %18, %4
%14 = load i8*, i8** %11
%15 = load i8, i8* %14
%16 = call i64 @isspace(i8 signext %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i8*, i8** %11
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %11
br label %13
21: ; preds = %13
%22 = load i8*, i8** %11
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %11
%24 = load i8, i8* %22
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 48
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = load i8**, i8*** %7
store i8* %28, i8** %29
store i64 0, i64* %5
br label %55
30: ; preds = %21
%31 = load i8*, i8** %11
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %11
%33 = load i8, i8* %31
%34 = call i64 @toupper(i8 signext %33)
%35 = load i8, i8* %8
%36 = call i64 @toupper(i8 signext %35)
%37 = icmp ne i64 %34, %36
br i1 %37, label %38, label %41
38: ; preds = %30
%39 = load i8*, i8** %6
%40 = load i8**, i8*** %7
store i8* %39, i8** %40
store i64 0, i64* %5
br label %55
41: ; preds = %30
%42 = load i8*, i8** %11
%43 = load i8**, i8*** %7
%44 = load i32, i32* %9
%45 = call i64 @strtoul(i8* %42, i8** %43, i32 %44)
store i64 %45, i64* %10
%46 = load i8**, i8*** %7
%47 = load i8*, i8** %46
%48 = load i8*, i8** %11
%49 = icmp eq i8* %47, %48
br i1 %49, label %50, label %53
50: ; preds = %41
%51 = load i8*, i8** %6
%52 = load i8**, i8*** %7
store i8* %51, i8** %52
store i64 0, i64* %5
br label %55
53: ; preds = %41
%54 = load i64, i64* %10
store i64 %54, i64* %5
br label %55
55: ; preds = %53, %50, %38, %27
%56 = load i64, i64* %5
ret i64 %56
}

LLVM IR (-O2):
define i64 @strtol0X(i8* %0, i8** nocapture %1, i8 signext %2, i32 %3) {
br label %5
5: ; preds = %5, %4
%6 = phi i8* [ %0, %4 ], [ %10, %5 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isspace(i8 signext %7)
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = load i8, i8* %6
%13 = icmp eq i8 %12, 48
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = getelementptr inbounds i8, i8* %6, i64 2
%16 = load i8, i8* %10
%17 = tail call i64 @toupper(i8 signext %16)
%18 = tail call i64 @toupper(i8 signext %2)
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %24
20: ; preds = %14
%21 = tail call i64 @strtoul(i8* %15, i8** %1, i32 %3)
%22 = load i8*, i8** %1
%23 = icmp eq i8* %22, %15
br i1 %23, label %24, label %25
24: ; preds = %20, %14, %11
store i8* %0, i8** %1
br label %25
25: ; preds = %24, %20
%26 = phi i64 [ %21, %20 ], [ 0, %24 ]
ret i64 %26
}