#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__ errno;
long long strtoll(char const *, char **, int /*<<< orphan*/);
unsigned long long str2int(const char *s, unsigned long long def) {
  if (!s)
    return def;
  char *end;
  errno = 0;
  long long int x = strtoll(s, &end, 0);
  return errno == 0 && *end == '\0' && x >= 0 ? (unsigned long long)x : def;
}


x86 assembly (clang, -O0):
<str2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1138 <str2int+0x28>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <str2int+0x92>
mov    0x2ea1(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e80(%rip),%rax
cmpq   $0x0,(%rax)
jne    1192 <str2int+0x82>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1192 <str2int+0x82>
cmpq   $0x0,-0x28(%rbp)
jl     1192 <str2int+0x82>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    119a <str2int+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2int>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
test   %rdi,%rdi
je     1140 <str2int+0x30>
mov    0x2ebd(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
cmpq   $0x0,(%r14)
je     114b <str2int+0x3b>
mov    %rbx,%rax
mov    %rax,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
jne    113a <str2int+0x2a>
test   %rax,%rax
jns    113d <str2int+0x2d>
jmp    113a <str2int+0x2a>

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

LLVM IR (-O2):
@errno = global i64 0
define i64 @str2int(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = icmp eq i8* %0, null
br i1 %4, label %19, label %5
5: ; preds = %2
%6 = bitcast i8** %3 to i8*
store i64 0, i64* @errno
%7 = call i64 @strtoll(i8* %0, i8** %3, i32 0)
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = icmp sgt i64 %7, -1
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %17, label %16
16: ; preds = %10, %5
br label %17
17: ; preds = %10, %16
%18 = phi i64 [ %1, %16 ], [ %7, %10 ]
br label %19
19: ; preds = %2, %17
%20 = phi i64 [ %18, %17 ], [ %1, %2 ]
ret i64 %20
}