#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 errno;
long strtol(char *, char **, int);
int /*<<< orphan*/ xfree(long *);
long *xmalloc(int);
long *str2longp(char *num, int base) {
  long *rlong;
  int p_errno;
  if (num != (char *)NULL) {
    rlong = xmalloc(sizeof(long));
    if (rlong != (long *)NULL) {
      p_errno = errno;
      errno = 0;
      *rlong = strtol(num, (char **)NULL, base);
      if (errno == 0) {
        errno = p_errno;
        return rlong;
      }
      xfree(rlong);
      return (long *)NULL;
    }
  }
  return (long *)NULL;
}


x86 assembly (clang, -O0):
<str2longp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11da <str2longp+0xaa>
mov    $0x8,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d5 <str2longp+0xa5>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e6a(%rip),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1050 <strtol@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e43(%rip),%rax
cmpl   $0x0,(%rax)
jne    11bf <str2longp+0x8f>
mov    -0x24(%rbp),%ecx
mov    0x2e30(%rip),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e2 <str2longp+0xb2>
mov    -0x20(%rbp),%rdi
call   1030 <xfree@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e2 <str2longp+0xb2>
jmp    11da <str2longp+0xaa>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str2longp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdi,%rdi
je     1184 <str2longp+0x54>
mov    %esi,%r14d
mov    %rdi,%rbp
mov    $0x8,%edi
call   1040 <xmalloc@plt>
test   %rax,%rax
je     1184 <str2longp+0x54>
mov    %rax,%rbx
mov    0x2e84(%rip),%r15
mov    (%r15),%r12d
movl   $0x0,(%r15)
mov    %rbp,%rdi
xor    %esi,%esi
mov    %r14d,%edx
call   1050 <strtol@plt>
mov    %rax,(%rbx)
cmpl   $0x0,(%r15)
je     1192 <str2longp+0x62>
mov    %rbx,%rdi
call   1030 <xfree@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,(%r15)
jmp    1186 <str2longp+0x56>

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

LLVM IR (-O2):
@errno = global i32 0
define i64* @str2longp(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = tail call i64* @xmalloc(i32 8)
%6 = icmp eq i64* %5, null
br i1 %6, label %15, label %7
7: ; preds = %4
%8 = load i32, i32* @errno
store i32 0, i32* @errno
%9 = tail call i64 @strtol(i8* nocapture %0, i8** null, i32 %1)
store i64 %9, i64* %5
%10 = load i32, i32* @errno
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %7
store i32 %8, i32* @errno
br label %15
13: ; preds = %7
%14 = tail call i32 @xfree(i64* %5)
br label %15
15: ; preds = %2, %4, %13, %12
%16 = phi i64* [ %5, %12 ], [ null, %13 ], [ null, %4 ], [ null, %2 ]
ret i64* %16
}