#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 validate_int(char *string) {
  int isInt = 1;
  int j = 0;
  for (j = 0; j < strlen(string); j++) {
    if (isInt == 1) {
      if (!isdigit(string[j])) {
        isInt = 0;
      }
    }
  }
  return isInt;
}


x86 assembly (clang, -O0):
<validate_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
cmp    %ecx,%eax
jge    11a0 <validate_int+0x80>
cmpl   $0x1,-0xc(%rbp)
jne    118d <validate_int+0x6d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    1188 <validate_int+0x68>
movl   $0x0,-0xc(%rbp)
jmp    118d <validate_int+0x6d>
jmp    1192 <validate_int+0x72>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <validate_int+0x21>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_int>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    $0x1,%ebp
test   %eax,%eax
jle    1171 <validate_int+0x51>
xor    %ebx,%ebx
jmp    1153 <validate_int+0x33>
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    1171 <validate_int+0x51>
cmp    $0x1,%ebp
mov    $0x0,%ebp
jne    1140 <validate_int+0x20>
movsbl (%r14,%rbx,1),%edi
call   1030 <isdigit@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
jmp    1140 <validate_int+0x20>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @validate_int(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, %14
%5 = phi i64 [ %16, %14 ], [ 0, %1 ]
%6 = phi i32 [ %15, %14 ], [ 1, %1 ]
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = getelementptr inbounds i8, i8* %0, i64 %5
%10 = load i8, i8* %9
%11 = tail call i32 @isdigit(i8 signext %10)
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %8, %4
%15 = phi i32 [ 0, %4 ], [ %13, %8 ]
%16 = add nuw nsw i64 %5, 1
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = icmp slt i64 %16, %18
br i1 %19, label %4, label %20
20: ; preds = %14, %1
%21 = phi i32 [ 1, %1 ], [ %15, %14 ]
ret i32 %21
}