#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 const INT_MAX;
long const INT_MIN;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ str_is_maybe_integer(char const *);
long strtol(char const *, char **, int);
bool str_try_parse_as_sint(const char *s, signed int *i_handle) {
  assert(s != NULL && i_handle != NULL);
  if (!str_is_maybe_integer(s))
    return false;
  char *end;
  const long signed int i = strtol(s, &end, 10);
  if (*end != '\0')
    return false;
  if (i < INT_MIN || i > INT_MAX)
    return false;
  *i_handle = (signed int)(i);
  return true;
}


x86 assembly (clang, -O0):
<str_try_parse_as_sint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x29(%rbp)
je     115b <str_try_parse_as_sint+0x2b>
cmpq   $0x0,-0x18(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1050 <str_is_maybe_integer@plt>
cmp    $0x0,%eax
jne    1186 <str_try_parse_as_sint+0x56>
movl   $0x0,-0x4(%rbp)
jmp    11ff <str_try_parse_as_sint+0xcf>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b8 <str_try_parse_as_sint+0x88>
movl   $0x0,-0x4(%rbp)
jmp    11ff <str_try_parse_as_sint+0xcf>
mov    -0x28(%rbp),%rax
mov    0x2e1d(%rip),%rcx
cmp    (%rcx),%rax
jl     11e0 <str_try_parse_as_sint+0xb0>
mov    -0x28(%rbp),%rax
mov    0x2e11(%rip),%rcx
cmp    (%rcx),%rax
jle    11ec <str_try_parse_as_sint+0xbc>
movl   $0x0,-0x4(%rbp)
jmp    11ff <str_try_parse_as_sint+0xcf>
mov    -0x28(%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):
<str_try_parse_as_sint>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    %rbx,%rdi
call   1050 <str_is_maybe_integer@plt>
test   %eax,%eax
je     118d <str_try_parse_as_sint+0x5d>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    (%rsp),%rdx
xor    %eax,%eax
cmpb   $0x0,(%rdx)
jne    118f <str_try_parse_as_sint+0x5f>
test   %rcx,%rcx
jne    118f <str_try_parse_as_sint+0x5f>
movl   $0x0,(%r14)
mov    $0x1,%eax
jmp    118f <str_try_parse_as_sint+0x5f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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