#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 */
scalar_t__ isdigit(int);
int isnum(const char *str) {
  const char *p = str;
  if (!isdigit((int)*p++))
    return 0;
  while (*p && isdigit((int)*p))
    p++;
  return !*p;
}


x86 assembly (clang, -O0):
<isnum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    1151 <isnum+0x41>
movl   $0x0,-0x4(%rbp)
jmp    11b6 <isnum+0xa6>
jmp    1156 <isnum+0x46>
mov    -0x18(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     1181 <isnum+0x71>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1191 <isnum+0x81>
jmp    11a2 <isnum+0x92>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1156 <isnum+0x46>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isnum>:
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1150 <isnum+0x40>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movsbl (%rbx),%edi
test   %edi,%edi
je     1154 <isnum+0x44>
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1130 <isnum+0x20>
xor    %eax,%eax
cmpb   $0x0,-0x1(%rbx)
sete   %al
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @isnum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %4
%7 = getelementptr inbounds i8, i8* %6, i32 1
store i8* %7, i8** %4
%8 = load i8, i8* %6
%9 = sext i8 %8 to i32
%10 = call i64 @isdigit(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 0, i32* %2
br label %36
13: ; preds = %1
br label %14
14: ; preds = %27, %13
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i64 @isdigit(i32 %22)
%24 = icmp ne i64 %23, 0
br label %25
25: ; preds = %19, %14
%26 = phi i1 [ false, %14 ], [ %24, %19 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i8*, i8** %4
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %4
br label %14
30: ; preds = %25
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = icmp ne i8 %32, 0
%34 = xor i1 %33, true
%35 = zext i1 %34 to i32
store i32 %35, i32* %2
br label %36
36: ; preds = %30, %12
%37 = load i32, i32* %2
ret i32 %37
}

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