#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 int atoi(char const *);
int /*<<< orphan*/ isdigit(char const);
int strlen(char const *);
bool parseUnsigned(const char *s1, unsigned int *a) {
  for (int i = 0, len = strlen(s1); i < len; i++)
    if (!isdigit(s1[i]))
      return false;
  *a = atoi(s1);
  return true;
}


x86 assembly (clang, -O0):
<parseUnsigned>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1198 <parseUnsigned+0x68>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1185 <parseUnsigned+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <parseUnsigned+0x80>
jmp    118a <parseUnsigned+0x5a>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1153 <parseUnsigned+0x23>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parseUnsigned>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
test   %eax,%eax
jle    1167 <parseUnsigned+0x37>
mov    %eax,%r13d
xor    %r15d,%r15d
xor    %ebx,%ebx
movsbl (%r12,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1178 <parseUnsigned+0x48>
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1150 <parseUnsigned+0x20>
mov    %r12,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @parseUnsigned(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %7
br label %10
10: ; preds = %24, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %7
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %27
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @isdigit(i8 signext %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %23, label %22
22: ; preds = %14
store i32 0, i32* %3
br label %31
23: ; preds = %14
br label %24
24: ; preds = %23
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %10
27: ; preds = %10
%28 = load i8*, i8** %4
%29 = call i32 @atoi(i8* %28)
%30 = load i32*, i32** %5
store i32 %29, i32* %30
store i32 1, i32* %3
br label %31
31: ; preds = %27, %22
%32 = load i32, i32* %3
ret i32 %32
}

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