#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 */
long strtol(char const *, char **, int);
int is_integer(const char *s) {
  char *endptr;
  long v;
  if (s == NULL || s[0] == 0)
    return 0;
  v = strtol(s, &endptr, 10);
  return (v > 0 && *endptr == 0);
}


x86 assembly (clang, -O0):
<is_integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1137 <is_integer+0x27>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1143 <is_integer+0x33>
movl   $0x0,-0x4(%rbp)
jmp    1184 <is_integer+0x74>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x20(%rbp)
mov    %al,-0x21(%rbp)
jle    1179 <is_integer+0x69>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_integer>:
push   %rbx
sub    $0x10,%rsp
xor    %ebx,%ebx
test   %rdi,%rdi
je     1142 <is_integer+0x32>
cmpb   $0x0,(%rdi)
je     1142 <is_integer+0x32>
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
test   %rax,%rax
jle    1142 <is_integer+0x32>
mov    0x8(%rsp),%rax
xor    %ebx,%ebx
cmpb   $0x0,(%rax)
sete   %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @is_integer(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %8, %1
store i32 0, i32* %2
br label %28
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = call i64 @strtol(i8* %16, i8** %4, i32 10)
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
br label %25
25: ; preds = %20, %15
%26 = phi i1 [ false, %15 ], [ %24, %20 ]
%27 = zext i1 %26 to i32
store i32 %27, i32* %2
br label %28
28: ; preds = %25, %14
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
define i32 @is_integer(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8** %2 to i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %16, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %5
%9 = call i64 @strtol(i8* %0, i8** %2, i32 10)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %8, %11, %1, %5
%17 = phi i32 [ 0, %5 ], [ 0, %1 ], [ 0, %8 ], [ %15, %11 ]
ret i32 %17
}