#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);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int is_number(char *str) {
  if (str == NULL)
    return -1;
  if (!strcmp(str, "0"))
    return 0;
  int i;
  int len = strlen(str);
  for (i = 0; i < len; i++) {
    if (!isdigit(str[i]))
      return 0;
  }
  if (i == len && i > 0)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<is_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1153 <is_number+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <is_number+0xc9>
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1178 <is_number+0x48>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <is_number+0xc9>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d0 <is_number+0xa0>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11bd <is_number+0x8d>
movl   $0x0,-0x4(%rbp)
jmp    11f9 <is_number+0xc9>
jmp    11c2 <is_number+0x92>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118b <is_number+0x5b>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11f2 <is_number+0xc2>
cmpl   $0x0,-0x14(%rbp)
jle    11f2 <is_number+0xc2>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <is_number+0xc9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_number>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     118b <is_number+0x5b>
mov    %rdi,%rbx
lea    0xeb9(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1193 <is_number+0x63>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    1198 <is_number+0x68>
mov    %r14d,%r12d
xor    %r15d,%r15d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     11ab <is_number+0x7b>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1170 <is_number+0x40>
mov    %r14d,%eax
jmp    119a <is_number+0x6a>
mov    $0xffffffff,%r15d
jmp    11ab <is_number+0x7b>
xor    %r15d,%r15d
jmp    11ab <is_number+0x7b>
xor    %eax,%eax
cmp    %r14d,%eax
sete   %cl
test   %eax,%eax
setne  %al
and    %cl,%al
movzbl %al,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"0\00"
define i32 @is_number(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %43
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strcmp(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp ne i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %9
store i32 0, i32* %2
br label %43
14: ; preds = %9
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
store i32 %16, i32* %5
store i32 0, i32* %4
br label %17
17: ; preds = %31, %14
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %34
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @isdigit(i8 signext %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %21
store i32 0, i32* %2
br label %43
30: ; preds = %21
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %17
34: ; preds = %17
%35 = load i32, i32* %4
%36 = load i32, i32* %5
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %4
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %38
store i32 1, i32* %2
br label %43
42: ; preds = %38, %34
store i32 0, i32* %2
br label %43
43: ; preds = %42, %41, %29, %13, %8
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"0\00"
define i32 @is_number(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %26, label %3
3: ; preds = %1
%4 = tail call i32 @strcmp(i8* %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %20
9: ; preds = %6
%10 = zext i32 %7 to i64
br label %11
11: ; preds = %9, %17
%12 = phi i64 [ 0, %9 ], [ %18, %17 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @isdigit(i8 signext %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %26, label %17
17: ; preds = %11
%18 = add nuw nsw i64 %12, 1
%19 = icmp eq i64 %18, %10
br i1 %19, label %20, label %11
20: ; preds = %17, %6
%21 = phi i32 [ 0, %6 ], [ %7, %17 ]
%22 = icmp eq i32 %21, %7
%23 = icmp ne i32 %21, 0
%24 = and i1 %22, %23
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %11, %20, %3, %1
%27 = phi i32 [ -1, %1 ], [ 0, %3 ], [ %25, %20 ], [ 0, %11 ]
ret i32 %27
}