#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 is_valid_int(const char *str) {
  if (!isdigit(*str) && *str != '-')
    return 0;
  for (str++; *str != '\0'; str++)
    if (!isdigit(*str))
      return 0;
  return 1;
}


x86 assembly (clang, -O0):
<is_valid_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    114d <is_valid_int+0x3d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     114d <is_valid_int+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <is_valid_int+0x97>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11a0 <is_valid_int+0x90>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    118a <is_valid_int+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    11a7 <is_valid_int+0x97>
jmp    118f <is_valid_int+0x7f>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1159 <is_valid_int+0x49>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_int>:
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
test   %eax,%eax
jne    1127 <is_valid_int+0x17>
xor    %eax,%eax
cmpb   $0x2d,(%rbx)
jne    1149 <is_valid_int+0x39>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%eax
test   %al,%al
je     114b <is_valid_int+0x3b>
movsbl %al,%edi
call   1030 <isdigit@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    1130 <is_valid_int+0x20>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

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

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