#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 INT_MAX;
long INT_MIN;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ errno;
long strtol(char const *, char **, int);
int str2int(const char *str, int *result) {
  long tmp_result = 0;
  char *tail = NULL;
  assert(str != NULL);
  assert(result != NULL);
  errno = 0;
  tmp_result = strtol(str, &tail, 10);
  if (errno != 0 || *tail != '\0' || tmp_result < INT_MIN ||
      tmp_result > INT_MAX) {
    return 0;
  }
  *result = tmp_result;
  return 1;
}


x86 assembly (clang, -O0):
<str2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%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    0x2e65(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e41(%rip),%rax
cmpq   $0x0,(%rax)
jne    11d1 <str2int+0xb1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11d1 <str2int+0xb1>
mov    -0x20(%rbp),%rax
mov    0x2e2c(%rip),%rcx
cmp    (%rcx),%rax
jl     11d1 <str2int+0xb1>
mov    -0x20(%rbp),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
jle    11dd <str2int+0xbd>
movl   $0x0,-0x4(%rbp)
jmp    11f0 <str2int+0xd0>
mov    -0x20(%rbp),%rax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
mov    0x2e75(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmpq   $0x0,(%r15)
jne    11a9 <str2int+0x89>
mov    0x8(%rsp),%rdx
cmpb   $0x0,(%rdx)
jne    11a9 <str2int+0x89>
mov    0x2e50(%rip),%rdx
cmp    (%rdx),%rcx
jl     11a9 <str2int+0x89>
mov    0x2e4c(%rip),%rdx
cmp    (%rdx),%rcx
jg     11a9 <str2int+0x89>
mov    %ecx,(%r14)
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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