#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 long ULONG_MAX;
int /*<<< orphan*/ isdigit(char);
int strlen(char *);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
unsigned long strtoul_reals(char *s, int base) {
  int i, len;
  if (s == NULL)
    return ULONG_MAX;
  len = strlen(s);
  for (i = 0; i < len; i++)
    if (!isdigit(*(s + i)))
      break;
  if (i != len)
    return ULONG_MAX;
  return strtoul(s, NULL, base);
}


x86 assembly (clang, -O0):
<strtoul_reals>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115d <strtoul_reals+0x2d>
mov    0x2e87(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11e1 <strtoul_reals+0xb1>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11ae <strtoul_reals+0x7e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    119b <strtoul_reals+0x6b>
jmp    11ae <strtoul_reals+0x7e>
jmp    11a0 <strtoul_reals+0x70>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1170 <strtoul_reals+0x40>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11cd <strtoul_reals+0x9d>
mov    0x2e17(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11e1 <strtoul_reals+0xb1>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <strtoul@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strtoul_reals>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1195 <strtoul_reals+0x65>
mov    %esi,%r14d
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %eax,%r15d
test   %eax,%eax
jle    1179 <strtoul_reals+0x49>
mov    %r15d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r12,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     117b <strtoul_reals+0x4b>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1160 <strtoul_reals+0x30>
jmp    1180 <strtoul_reals+0x50>
xor    %ebp,%ebp
cmp    %r15d,%ebp
jne    1195 <strtoul_reals+0x65>
mov    %r12,%rdi
xor    %esi,%esi
mov    %r14d,%edx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <strtoul@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@ULONG_MAX = global i64 0
define i64 @strtoul_reals(i8* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i64, i64* @ULONG_MAX
store i64 %11, i64* %3
br label %42
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %7
store i32 0, i32* %6
br label %15
15: ; preds = %29, %12
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %32
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @isdigit(i8 signext %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %19
br label %32
28: ; preds = %19
br label %29
29: ; preds = %28
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %15
32: ; preds = %27, %15
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = icmp ne i32 %33, %34
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load i64, i64* @ULONG_MAX
store i64 %37, i64* %3
br label %42
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = call i64 @strtoul(i8* %39, i32* null, i32 %40)
store i64 %41, i64* %3
br label %42
42: ; preds = %38, %36, %10
%43 = load i64, i64* %3
ret i64 %43
}

LLVM IR (-O2):
@ULONG_MAX = global i64 0
define i64 @strtoul_reals(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = load i64, i64* @ULONG_MAX
br label %29
6: ; preds = %2
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %17
%12 = phi i64 [ 0, %9 ], [ %18, %17 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @isdigit(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %27, label %11
20: ; preds = %11
%21 = trunc i64 %12 to i32
br label %22
22: ; preds = %20, %6
%23 = phi i32 [ 0, %6 ], [ %21, %20 ]
%24 = icmp eq i32 %23, %7
br i1 %24, label %27, label %25
25: ; preds = %22
%26 = load i64, i64* @ULONG_MAX
br label %29
27: ; preds = %17, %22
%28 = tail call i64 @strtoul(i8* nocapture %0, i32* null, i32 %1)
br label %29
29: ; preds = %27, %25, %4
%30 = phi i64 [ %5, %4 ], [ %26, %25 ], [ %28, %27 ]
ret i64 %30
}