#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 int myatoul(const char *str) {
  unsigned long int dummy = 0;
  while (isspace(*str))
    str++;
  while (*str >= '0' && *str <= '9') {
    dummy *= 10;
    dummy += (*str) - '0';
    str++;
  }
  return dummy;
}


x86 assembly (clang, -O0):
<myatoul>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     114b <myatoul+0x3b>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1124 <myatoul+0x14>
jmp    1150 <myatoul+0x40>
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x11(%rbp)
jl     1175 <myatoul+0x65>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
setle  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1185 <myatoul+0x75>
jmp    11b3 <myatoul+0xa3>
imul   $0xa,-0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
cltq
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1150 <myatoul+0x40>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myatoul>:
push   %rbx
mov    %rdi,%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1120 <myatoul+0x10>
mov    -0x1(%rbx),%cl
lea    -0x30(%rcx),%eax
cmp    $0x9,%al
ja     115f <myatoul+0x4f>
xor    %eax,%eax
nopl   (%rax)
lea    (%rax,%rax,4),%rax
movzbl %cl,%ecx
add    $0xffffffd0,%ecx
lea    (%rcx,%rax,2),%rax
movzbl (%rbx),%ecx
lea    -0x30(%rcx),%edx
add    $0x1,%rbx
cmp    $0xa,%dl
jb     1140 <myatoul+0x30>
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i64 @myatoul(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %4
4: ; preds = %9, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = call i64 @isspace(i8 signext %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = load i8*, i8** %2
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %2
br label %4
12: ; preds = %4
br label %13
13: ; preds = %25, %12
%14 = load i8*, i8** %2
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp sge i32 %16, 48
br i1 %17, label %18, label %23
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp sle i32 %21, 57
br label %23
23: ; preds = %18, %13
%24 = phi i1 [ false, %13 ], [ %22, %18 ]
br i1 %24, label %25, label %37
25: ; preds = %23
%26 = load i64, i64* %3
%27 = mul i64 %26, 10
store i64 %27, i64* %3
%28 = load i8*, i8** %2
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 48
%32 = sext i32 %31 to i64
%33 = load i64, i64* %3
%34 = add i64 %33, %32
store i64 %34, i64* %3
%35 = load i8*, i8** %2
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %2
br label %13
37: ; preds = %23
%38 = load i64, i64* %3
ret i64 %38
}

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