#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 (*str == '-')
    ++str;
  if (!*str)
    return 0;
  while (*str) {
    if (!isdigit(*str))
      return 0;
    else
      ++str;
  }
  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),%eax
cmp    $0x2d,%eax
jne    1138 <is_valid_int+0x28>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1151 <is_valid_int+0x41>
movl   $0x0,-0x4(%rbp)
jmp    119c <is_valid_int+0x8c>
jmp    1156 <is_valid_int+0x46>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1195 <is_valid_int+0x85>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1184 <is_valid_int+0x74>
movl   $0x0,-0x4(%rbp)
jmp    119c <is_valid_int+0x8c>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1156 <is_valid_int+0x46>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_int>:
push   %rbp
push   %rbx
push   %rax
xor    %ecx,%ecx
cmpb   $0x2d,(%rdi)
sete   %cl
mov    (%rdi,%rcx,1),%al
xor    %ebp,%ebp
test   %al,%al
je     114c <is_valid_int+0x3c>
lea    (%rcx,%rdi,1),%rbx
add    $0x1,%rbx
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     114c <is_valid_int+0x3c>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <is_valid_int+0x20>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
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 = sext i8 %5 to i32
%7 = icmp eq i32 %6, 45
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %3
br label %11
11: ; preds = %8, %1
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11
store i32 0, i32* %2
br label %32
16: ; preds = %11
br label %17
17: ; preds = %30, %16
%18 = load i8*, i8** %3
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = load i8, i8* %22
%24 = call i32 @isdigit(i8 signext %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %21
store i32 0, i32* %2
br label %32
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i32 1
store i8* %29, i8** %3
br label %30
30: ; preds = %27
br label %17
31: ; preds = %17
store i32 -1, i32* %2
br label %32
32: ; preds = %31, %26, %15
%33 = load i32, i32* %2
ret i32 %33
}

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