#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 LONG_MAX;
long LONG_MIN;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
long strtol(char *, char **, int);
int check_long(char *text, long *number) {
  char *tmp;
  assert(text != NULL);
  assert(number != NULL);
  if (((*number = strtol(text, &tmp, 10)) == LONG_MAX) ||
      (*number == LONG_MIN)) {
    return 1;
  }
  if ((*text != '\0') && (*tmp == '\0')) {
    return 0;
  } else {
    return 2;
  }
}


x86 assembly (clang, -O0):
<check_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
cmpq   $0x0,-0x18(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     1194 <check_long+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%rax
jne    11a0 <check_long+0x80>
movl   $0x1,-0x4(%rbp)
jmp    11d3 <check_long+0xb3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11cc <check_long+0xac>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11cc <check_long+0xac>
movl   $0x0,-0x4(%rbp)
jmp    11d3 <check_long+0xb3>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_long>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    %rax,(%rbx)
mov    0x2e75(%rip),%rdx
mov    $0x1,%eax
cmp    (%rdx),%rcx
je     1191 <check_long+0x71>
mov    0x2e74(%rip),%rdx
cmp    (%rdx),%rcx
je     1191 <check_long+0x71>
cmpb   $0x0,(%r14)
je     1188 <check_long+0x68>
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     118f <check_long+0x6f>
mov    $0x2,%eax
jmp    1191 <check_long+0x71>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
define i32 @check_long(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
%7 = load i8*, i8** %4
%8 = icmp ne i8* %7, null
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i64*, i64** %5
%12 = icmp ne i64* %11, null
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %4
%16 = call i64 @strtol(i8* %15, i8** %6, i32 10)
%17 = load i64*, i64** %5
store i64 %16, i64* %17
%18 = load i64, i64* @LONG_MAX
%19 = icmp eq i64 %16, %18
br i1 %19, label %25, label %20
20: ; preds = %2
%21 = load i64*, i64** %5
%22 = load i64, i64* %21
%23 = load i64, i64* @LONG_MIN
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %20, %2
store i32 1, i32* %3
br label %38
26: ; preds = %20
%27 = load i8*, i8** %4
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %26
%32 = load i8*, i8** %6
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %31
store i32 0, i32* %3
br label %38
37: ; preds = %31, %26
store i32 2, i32* %3
br label %38
38: ; preds = %37, %36, %25
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
define i32 @check_long(i8* %0, i64* writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = icmp ne i8* %0, null
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = icmp ne i64* %1, null
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = call i64 @strtol(i8* %0, i8** %3, i32 10)
store i64 %11, i64* %1
%12 = load i64, i64* @LONG_MAX
%13 = icmp eq i64 %11, %12
%14 = load i64, i64* @LONG_MIN
%15 = icmp eq i64 %11, %14
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %25, label %17
17: ; preds = %2
%18 = load i8, i8* %0
%19 = icmp eq i8 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %20, %2, %24
%26 = phi i32 [ 2, %24 ], [ 1, %2 ], [ 0, %20 ]
ret i32 %26
}