#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 */
int /*<<< orphan*/ isdigit(char);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int strToUlong(unsigned long *val, char *str) {
  char *tmp;
  for (tmp = str; *tmp; tmp++) {
    if (!isdigit(*tmp))
      return 0;
  }
  *val = strtoul(str, NULL, 10);
  return 1;
}


x86 assembly (clang, -O0):
<strToUlong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     117c <strToUlong+0x5c>
mov    -0x20(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1166 <strToUlong+0x46>
movl   $0x0,-0x4(%rbp)
jmp    119f <strToUlong+0x7f>
jmp    116b <strToUlong+0x4b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <strToUlong+0x18>
mov    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strToUlong>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    (%rsi),%al
test   %al,%al
je     1157 <strToUlong+0x37>
lea    0x1(%r15),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1170 <strToUlong+0x50>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <strToUlong+0x20>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtoul@plt>
mov    %rax,(%r14)
mov    $0x1,%eax
jmp    1172 <strToUlong+0x52>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @strToUlong(i64* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i8*
store i64* %0, i64** %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
store i8* %7, i8** %6
br label %8
8: ; preds = %19, %2
%9 = load i8*, i8** %6
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = call i32 @isdigit(i8 signext %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 0, i32* %3
br label %26
18: ; preds = %12
br label %19
19: ; preds = %18
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
br label %8
22: ; preds = %8
%23 = load i8*, i8** %5
%24 = call i64 @strtoul(i8* %23, i32* null, i32 10)
%25 = load i64*, i64** %4
store i64 %24, i64* %25
store i32 1, i32* %3
br label %26
26: ; preds = %22, %17
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
define i32 @strToUlong(i64* nocapture writeonly %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %14, label %8
5: ; preds = %8
%6 = load i8, i8* %13
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2, %5
%9 = phi i8 [ %6, %5 ], [ %3, %2 ]
%10 = phi i8* [ %13, %5 ], [ %1, %2 ]
%11 = tail call i32 @isdigit(i8 signext %9)
%12 = icmp eq i32 %11, 0
%13 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %12, label %16, label %5
14: ; preds = %5, %2
%15 = tail call i64 @strtoul(i8* nocapture %1, i32* null, i32 10)
store i64 %15, i64* %0
br label %16
16: ; preds = %8, %14
%17 = phi i32 [ 1, %14 ], [ 0, %8 ]
ret i32 %17
}