#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 */
long strtol(char const *, char **, int /*<<< orphan*/);
long long strtoll(char const *, char **, int /*<<< orphan*/);
char *str_to_number(const char *s, long *val, long long *vall) {
  char *p;
  if (vall)
    *vall = strtoll(s, &p, 0);
  else if (val)
    *val = strtol(s, &p, 0);
  else
    p = NULL;
  return (p);
}


x86 assembly (clang, -O0):
<str_to_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     115d <str_to_number+0x3d>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1193 <str_to_number+0x73>
cmpq   $0x0,-0x10(%rbp)
je     1186 <str_to_number+0x66>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    118e <str_to_number+0x6e>
movq   $0x0,-0x20(%rbp)
jmp    1193 <str_to_number+0x73>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_to_number>:
push   %r14
push   %rbx
push   %rax
test   %rdx,%rdx
je     113b <str_to_number+0x1b>
mov    %rdx,%rbx
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <strtoll@plt>
mov    %rax,(%rbx)
jmp    115a <str_to_number+0x3a>
mov    %rsi,%r14
test   %rsi,%rsi
je     1152 <str_to_number+0x32>
mov    %rsp,%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,(%r14)
jmp    115a <str_to_number+0x3a>
movq   $0x0,(%rsp)
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @str_to_number(i8* %0, i64* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64*
%7 = alloca i8*
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64* %2, i64** %6
%8 = load i64*, i64** %6
%9 = icmp ne i64* %8, null
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i8*, i8** %4
%12 = call i64 @strtoll(i8* %11, i8** %7, i32 0)
%13 = load i64*, i64** %6
store i64 %12, i64* %13
br label %23
14: ; preds = %3
%15 = load i64*, i64** %5
%16 = icmp ne i64* %15, null
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = call i64 @strtol(i8* %18, i8** %7, i32 0)
%20 = load i64*, i64** %5
store i64 %19, i64* %20
br label %22
21: ; preds = %14
store i8* null, i8** %7
br label %22
22: ; preds = %21, %17
br label %23
23: ; preds = %22, %10
%24 = load i8*, i8** %7
ret i8* %24
}

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