#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__ isspace(char const);
long lvexpression(char const **, int /*<<< orphan*/, int *);
long num_str2long(const char *str, const char **tail, int *perrval) {
  int errval;
  long int value;
  const char *ps = "";
  if (str)
    ps = str;
  while (isspace(*ps))
    ps++;
  value = lvexpression(&ps, 0, &errval);
  if (tail)
    *tail = ps;
  if (perrval)
    *perrval = errval;
  return (value);
}


x86 assembly (clang, -O0):
<num_str2long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xec5(%rip),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1152 <num_str2long+0x32>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1157 <num_str2long+0x37>
mov    -0x30(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     117e <num_str2long+0x5e>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1157 <num_str2long+0x37>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
lea    -0x1c(%rbp),%rdx
call   1040 <lvexpression@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a7 <num_str2long+0x87>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11bb <num_str2long+0x9b>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<num_str2long>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
test   %rdi,%rdi
lea    0xec7(%rip),%rbx
cmovne %rdi,%rbx
mov    %rbx,(%rsp)
movsbl (%rbx),%edi
call   1030 <isspace@plt>
test   %rax,%rax
je     1166 <num_str2long+0x46>
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isspace@plt>
test   %rax,%rax
jne    1150 <num_str2long+0x30>
mov    %rbx,(%rsp)
mov    %rsp,%rdi
lea    0xc(%rsp),%rdx
xor    %esi,%esi
call   1040 <lvexpression@plt>
test   %r15,%r15
je     1181 <num_str2long+0x61>
mov    (%rsp),%rcx
mov    %rcx,(%r15)
test   %r14,%r14
je     118d <num_str2long+0x6d>
mov    0xc(%rsp),%ecx
mov    %ecx,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i64 @num_str2long(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i64
%9 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = load i8*, i8** %4
store i8* %13, i8** %9
br label %14
14: ; preds = %12, %3
br label %15
15: ; preds = %20, %14
%16 = load i8*, i8** %9
%17 = load i8, i8* %16
%18 = call i64 @isspace(i8 signext %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %9
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %9
br label %15
23: ; preds = %15
%24 = call i64 @lvexpression(i8** %9, i32 0, i32* %7)
store i64 %24, i64* %8
%25 = load i8**, i8*** %5
%26 = icmp ne i8** %25, null
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i8*, i8** %9
%29 = load i8**, i8*** %5
store i8* %28, i8** %29
br label %30
30: ; preds = %27, %23
%31 = load i32*, i32** %6
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* %7
%35 = load i32*, i32** %6
store i32 %34, i32* %35
br label %36
36: ; preds = %33, %30
%37 = load i64, i64* %8
ret i64 %37
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i64 @num_str2long(i8* %0, i8** writeonly %1, i32* writeonly %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = bitcast i32* %4 to i8*
%7 = bitcast i8** %5 to i8*
%8 = icmp eq i8* %0, null
%9 = select i1 %8, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
store i8* %9, i8** %5
%10 = load i8, i8* %9
%11 = tail call i64 @isspace(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %3, %13
%14 = phi i8* [ %15, %13 ], [ %9, %3 ]
%15 = getelementptr inbounds i8, i8* %14, i64 1
%16 = load i8, i8* %15
%17 = tail call i64 @isspace(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %13
19: ; preds = %13
store i8* %15, i8** %5
br label %20
20: ; preds = %19, %3
%21 = call i64 @lvexpression(i8** %5, i32 0, i32* %4)
%22 = icmp eq i8** %1, null
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = load i8*, i8** %5
store i8* %24, i8** %1
br label %25
25: ; preds = %23, %20
%26 = icmp eq i32* %2, null
br i1 %26, label %29, label %27
27: ; preds = %25
%28 = load i32, i32* %4
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %25
ret i64 %21
}