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


x86 assembly (clang, -O0):
<str_isnumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a8 <str_isnumber+0x88>
cmpl   $0x0,-0x18(%rbp)
jne    116f <str_isnumber+0x4f>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2d,%eax
jne    116f <str_isnumber+0x4f>
jmp    119a <str_isnumber+0x7a>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1195 <str_isnumber+0x75>
movl   $0x0,-0x4(%rbp)
jmp    11af <str_isnumber+0x8f>
jmp    119a <str_isnumber+0x7a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    113f <str_isnumber+0x1f>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_isnumber>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    $0x1,%r14d
test   %eax,%eax
jle    1165 <str_isnumber+0x45>
mov    %eax,%r15d
xor    %ebp,%ebp
jmp    1156 <str_isnumber+0x36>
movsbl (%rbx,%rbp,1),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     1162 <str_isnumber+0x42>
add    $0x1,%rbp
cmp    %rbp,%r15
je     1165 <str_isnumber+0x45>
test   %rbp,%rbp
jne    1140 <str_isnumber+0x20>
cmpb   $0x2d,(%rbx)
jne    1140 <str_isnumber+0x20>
jmp    114d <str_isnumber+0x2d>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @str_isnumber(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 = call i32 @strlen(i8* %6)
store i32 %7, i32* %4
store i32 0, i32* %5
br label %8
8: ; preds = %34, %1
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %37
12: ; preds = %8
%13 = load i32, i32* %5
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 45
br i1 %22, label %23, label %24
23: ; preds = %15
br label %34
24: ; preds = %15, %12
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @isdigit(i8 signext %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %24
store i32 0, i32* %2
br label %38
33: ; preds = %24
br label %34
34: ; preds = %33, %23
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %8
37: ; preds = %8
store i32 1, i32* %2
br label %38
38: ; preds = %37, %32
%39 = load i32, i32* %2
ret i32 %39
}

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