#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;
int /*<<< orphan*/ set_error_msg(char *);
int strtol(char const *, char **, int);
char parse_int(int *i, const char *str, const char **tail) {
  char *tmp;
  errno = 0;
  *i = strtol(str, &tmp, 10);
  if (tail)
    *tail = tmp;
  if (tmp == str) {
    set_error_msg("Bad numerical result");
    *i = 0;
    return 0;
  }
  if (errno == ERANGE) {
    set_error_msg("Numerical result out of range");
    *i = 0;
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e9d(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x20(%rbp)
je     1172 <parse_int+0x52>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    119f <parse_int+0x7f>
lea    0xe79(%rip),%rdi
call   1030 <set_error_msg@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movb   $0x0,-0x1(%rbp)
jmp    11dc <parse_int+0xbc>
mov    0x2e32(%rip),%rax
mov    (%rax),%rax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
jne    11d8 <parse_int+0xb8>
lea    0xe55(%rip),%rdi
call   1030 <set_error_msg@plt>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
movb   $0x0,-0x1(%rbp)
jmp    11dc <parse_int+0xbc>
movb   $0x1,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2ea0(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%r14)
mov    (%rsp),%rax
test   %r15,%r15
je     115f <parse_int+0x3f>
mov    %rax,(%r15)
cmp    %rbx,%rax
je     117f <parse_int+0x5f>
mov    (%r12),%rcx
mov    0x2e79(%rip),%rdx
mov    $0x1,%al
cmp    (%rdx),%rcx
jne    1194 <parse_int+0x74>
lea    0xe98(%rip),%rdi
jmp    1186 <parse_int+0x66>
lea    0xe7a(%rip),%rdi
call   1030 <set_error_msg@plt>
movl   $0x0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@.str = [21 x i8] c"Bad numerical result\00"
@ERANGE = global i64 0
@.str.1 = [30 x i8] c"Numerical result out of range\00"
define signext i8 @parse_int(i32* %0, i8* %1, i8** %2) {
%4 = alloca i8
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
store i64 0, i64* @errno
%9 = load i8*, i8** %6
%10 = call i32 @strtol(i8* %9, i8** %8, i32 10)
%11 = load i32*, i32** %5
store i32 %10, i32* %11
%12 = load i8**, i8*** %7
%13 = icmp ne i8** %12, null
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i8*, i8** %8
%16 = load i8**, i8*** %7
store i8* %15, i8** %16
br label %17
17: ; preds = %14, %3
%18 = load i8*, i8** %8
%19 = load i8*, i8** %6
%20 = icmp eq i8* %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @set_error_msg(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%23 = load i32*, i32** %5
store i32 0, i32* %23
store i8 0, i8* %4
br label %32
24: ; preds = %17
%25 = load i64, i64* @errno
%26 = load i64, i64* @ERANGE
%27 = icmp eq i64 %25, %26
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @set_error_msg(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32*, i32** %5
store i32 0, i32* %30
store i8 0, i8* %4
br label %32
31: ; preds = %24
store i8 1, i8* %4
br label %32
32: ; preds = %31, %28, %21
%33 = load i8, i8* %4
ret i8 %33
}

LLVM IR (-O2):
@errno = global i64 0
@.str = [21 x i8] c"Bad numerical result\00"
@ERANGE = global i64 0
@.str.1 = [30 x i8] c"Numerical result out of range\00"
define signext i8 @parse_int(i32* nocapture writeonly %0, i8* %1, i8** writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i64 0, i64* @errno
%6 = call i32 @strtol(i8* %1, i8** %4, i32 10)
store i32 %6, i32* %0
%7 = icmp eq i8** %2, null
%8 = load i8*, i8** %4
br i1 %7, label %10, label %9
9: ; preds = %3
store i8* %8, i8** %2
br label %10
10: ; preds = %3, %9
%11 = icmp eq i8* %8, %1
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = load i64, i64* @errno
%14 = load i64, i64* @ERANGE
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12, %10
%17 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %10 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), %12 ]
%18 = tail call i32 @set_error_msg(i8* %17)
store i32 0, i32* %0
br label %19
19: ; preds = %16, %12
%20 = phi i8 [ 1, %12 ], [ 0, %16 ]
ret i8 %20
}