#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 */
typedef int /*<<< orphan*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ strtol(char *, char **, int);
int string_to_number(char *string, int64_t *number) {
  char *endp;
  int64_t val;
  if (!string || !number)
    return -1;
  val = strtol(string, &endp, 10);
  if (string == endp)
    return -1;
  *number = val;
  return 0;
}


x86 assembly (clang, -O0):
<string_to_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1136 <string_to_number+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1142 <string_to_number+0x32>
movl   $0xffffffff,-0x4(%rbp)
jmp    1181 <string_to_number+0x71>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    1171 <string_to_number+0x61>
movl   $0xffffffff,-0x4(%rbp)
jmp    1181 <string_to_number+0x71>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_to_number>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%ebp
test   %rdi,%rdi
je     1148 <string_to_number+0x38>
mov    %rsi,%r14
test   %rsi,%rsi
je     1148 <string_to_number+0x38>
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1030 <strtol@plt>
cmp    %rbx,0x8(%rsp)
je     1148 <string_to_number+0x38>
mov    %eax,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @string_to_number(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%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 %13
10: ; preds = %2
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %14, label %13
13: ; preds = %10, %2
store i32 -1, i32* %3
br label %24
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i32 @strtol(i8* %15, i8** %6, i32 10)
store i32 %16, i32* %7
%17 = load i8*, i8** %4
%18 = load i8*, i8** %6
%19 = icmp eq i8* %17, %18
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 -1, i32* %3
br label %24
21: ; preds = %14
%22 = load i32, i32* %7
%23 = load i32*, i32** %5
store i32 %22, i32* %23
store i32 0, i32* %3
br label %24
24: ; preds = %21, %20, %13
%25 = load i32, i32* %3
ret i32 %25
}

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