#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__ EINVAL;
scalar_t__ errno;
long long strtoll(char const *, char **, int);
int parse_int(const char *str, long long *ret) {
  char *endptr;
  errno = 0;
  *ret = strtoll(str, &endptr, 10);
  if (errno)
    return -1;
  if (*endptr) {
    errno = EINVAL;
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2eb9(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e8f(%rip),%rax
cmpq   $0x0,(%rax)
je     1167 <parse_int+0x57>
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <parse_int+0x8b>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     1194 <parse_int+0x84>
mov    0x2e5d(%rip),%rax
mov    (%rax),%rcx
mov    0x2e5b(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    119b <parse_int+0x8b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    0x2ec2(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1030 <strtoll@plt>
mov    %rax,(%rbx)
mov    $0xffffffff,%eax
cmpq   $0x0,(%r14)
jne    115a <parse_int+0x4a>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1158 <parse_int+0x48>
mov    0x2e88(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,(%r14)
jmp    115a <parse_int+0x4a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@errno = global i64 0
@EINVAL = global i64 0
define i32 @parse_int(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
store i64 0, i64* @errno
%7 = load i8*, i8** %4
%8 = call i64 @strtoll(i8* %7, i8** %6, i32 10)
%9 = load i64*, i64** %5
store i64 %8, i64* %9
%10 = load i64, i64* @errno
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %20
13: ; preds = %2
%14 = load i8*, i8** %6
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load i64, i64* @EINVAL
store i64 %18, i64* @errno
store i32 -1, i32* %3
br label %20
19: ; preds = %13
store i32 0, i32* %3
br label %20
20: ; preds = %19, %17, %12
%21 = load i32, i32* %3
ret i32 %21
}

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