#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);
size_t strlen(char const *);
int string_is_number(const char *string) {
  const size_t length = strlen(string);
  size_t i;
  if (!length) {
    return 0;
  }
  for (i = 0; i < length; ++i) {
    if (!isdigit(string[i])) {
      return 0;
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<string_is_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1150 <string_is_number+0x30>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <string_is_number+0x89>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11a2 <string_is_number+0x82>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    118c <string_is_number+0x6c>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <string_is_number+0x89>
jmp    1191 <string_is_number+0x71>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1158 <string_is_number+0x38>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_is_number>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1040 <strlen@plt>
test   %rax,%rax
je     115f <string_is_number+0x3f>
mov    %rax,%r12
xor    %r14d,%r14d
xor    %ebx,%ebx
nopl   (%rax)
movsbl (%r15,%rbx,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1162 <string_is_number+0x42>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <string_is_number+0x20>
mov    $0x1,%r14d
jmp    1162 <string_is_number+0x42>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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