#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 */
scalar_t__ ERANGE;
scalar_t__ errno;
long strtol(char *, char **, int);
int parse_int(char *str, bool *success) {
  char *pEnd;
  errno = 0;
  long int num = strtol(str, &pEnd, 10);
  if ((pEnd != str && *pEnd != '\0') || pEnd == str || errno == ERANGE) {
    *success = false;
  }
  return (int)num;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     1162 <parse_int+0x52>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    118a <parse_int+0x7a>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     118a <parse_int+0x7a>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    1194 <parse_int+0x84>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2eb2(%rip),%r15
movq   $0x0,(%r15)
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    0x8(%rsp),%rcx
cmp    %rbx,%rcx
je     115a <parse_int+0x4a>
cmpb   $0x0,(%rcx)
jne    115a <parse_int+0x4a>
mov    (%r15),%rcx
mov    0x2e93(%rip),%rdx
cmp    (%rdx),%rcx
jne    1161 <parse_int+0x51>
movl   $0x0,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @parse_int(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i32* %1, i32** %4
store i64 0, i64* @errno
%7 = load i8*, i8** %3
%8 = call i64 @strtol(i8* %7, i8** %5, i32 10)
store i64 %8, i64* %6
%9 = load i8*, i8** %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* %9, %10
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %25, label %17
17: ; preds = %12, %2
%18 = load i8*, i8** %5
%19 = load i8*, i8** %3
%20 = icmp eq i8* %18, %19
br i1 %20, label %25, label %21
21: ; preds = %17
%22 = load i64, i64* @errno
%23 = load i64, i64* @ERANGE
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21, %17, %12
%26 = load i32*, i32** %4
store i32 0, i32* %26
br label %27
27: ; preds = %25, %21
%28 = load i64, i64* %6
%29 = trunc i64 %28 to i32
ret i32 %29
}

LLVM IR (-O2):
@errno = global i64 0
@ERANGE = global i64 0
define i32 @parse_int(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%5 = call i64 @strtol(i8* %0, i8** %3, i32 10)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, %0
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i64, i64* @errno
%13 = load i64, i64* @ERANGE
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %16
15: ; preds = %2, %11, %8
store i32 0, i32* %1
br label %16
16: ; preds = %15, %11
%17 = trunc i64 %5 to i32
ret i32 %17
}