#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 */
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
long strtol(char const *, char **, int /*<<< orphan*/);
long str2integer(const char *str, long def) {
  char *endptr = NULL;
  assert(str);
  long n = strtol(str, &endptr, 0);
  if (*endptr != '\0') {
    fprintf(stderr, "can't convert to long %s\n", str);
    return def;
  }
  return n;
}


x86 assembly (clang, -O0):
<str2integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119a <str2integer+0x6a>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe78(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a2 <str2integer+0x72>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2integer>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
movq   $0x0,(%rsp)
call   1030 <assert@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <strtol@plt>
mov    (%rsp),%rcx
cmpb   $0x0,(%rcx)
je     1177 <str2integer+0x47>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
lea    0xe93(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
jmp    117a <str2integer+0x4a>
mov    %rax,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"can't convert to long %s\0A\00"
define i64 @str2integer(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
store i8* null, i8** %6
%8 = load i8*, i8** %4
%9 = call i32 @assert(i8* %8)
%10 = load i8*, i8** %4
%11 = call i64 @strtol(i8* %10, i8** %6, i32 0)
store i64 %11, i64* %7
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i64, i64* %5
store i64 %20, i64* %3
br label %23
21: ; preds = %2
%22 = load i64, i64* %7
store i64 %22, i64* %3
br label %23
23: ; preds = %21, %16
%24 = load i64, i64* %3
ret i64 %24
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"can't convert to long %s\0A\00"
define i64 @str2integer(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%5 = tail call i32 @assert(i8* %0)
%6 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
13: ; preds = %2, %10
%14 = phi i64 [ %1, %10 ], [ %6, %2 ]
ret i64 %14
}