#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 const);
int str_isdigit(const char *str, size_t len) {
  if (len == 0) {
    return 0;
  }
  for (size_t i = 0; i < len; i++) {
    if (!isdigit(str[i])) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<str_isdigit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1137 <str_isdigit+0x27>
movl   $0x0,-0x4(%rbp)
jmp    1190 <str_isdigit+0x80>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1189 <str_isdigit+0x79>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1173 <str_isdigit+0x63>
movl   $0x0,-0x4(%rbp)
jmp    1190 <str_isdigit+0x80>
jmp    1178 <str_isdigit+0x68>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113f <str_isdigit+0x2f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_isdigit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r15d,%r15d
test   %rsi,%rsi
je     1164 <str_isdigit+0x54>
mov    %rsi,%rbx
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1164 <str_isdigit+0x54>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    %rcx,%rbp
cmp    %rcx,%rbx
je     115a <str_isdigit+0x4a>
movsbl (%r14,%rbp,1),%edi
call   1030 <isdigit@plt>
lea    0x1(%rbp),%rcx
test   %eax,%eax
jne    1140 <str_isdigit+0x30>
xor    %r15d,%r15d
cmp    %rbx,%rbp
setae  %r15b
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str_isdigit(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
%7 = load i64, i64* %5
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 0, i32* %3
br label %28
10: ; preds = %2
store i64 0, i64* %6
br label %11
11: ; preds = %24, %10
%12 = load i64, i64* %6
%13 = load i64, i64* %5
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = load i64, i64* %6
%18 = getelementptr inbounds i8, i8* %16, 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 = %15
store i32 0, i32* %3
br label %28
23: ; preds = %15
br label %24
24: ; preds = %23
%25 = load i64, i64* %6
%26 = add i64 %25, 1
store i64 %26, i64* %6
br label %11
27: ; preds = %11
store i32 1, i32* %3
br label %28
28: ; preds = %27, %22, %9
%29 = load i32, i32* %3
ret i32 %29
}

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