#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*/ error_exit(int, char *, ...);
unsigned long long strtoull(char const *, char **, int /*<<< orphan*/);
unsigned convert_string_to_number(const char *string) {
  if (!*string)
    error_exit(1, "argument is empty");
  char *error_pointer;
  unsigned long long value = strtoull(string, &error_pointer, 0);
  if (*error_pointer)
    error_exit(1, "invalid number: %s", string);
  return value;
}


x86 assembly (clang, -O0):
<convert_string_to_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    114c <convert_string_to_number+0x2c>
mov    $0x1,%edi
lea    0xebb(%rip),%rsi
mov    $0x0,%al
call   1030 <error_exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoull@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     1183 <convert_string_to_number+0x63>
mov    -0x8(%rbp),%rdx
mov    $0x1,%edi
lea    0xe96(%rip),%rsi
mov    $0x0,%al
call   1030 <error_exit@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_string_to_number>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
jne    113f <convert_string_to_number+0x1f>
lea    0xecd(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1030 <error_exit@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoull@plt>
mov    %rax,%r14
mov    (%rsp),%rax
cmpb   $0x0,(%rax)
je     116e <convert_string_to_number+0x4e>
lea    0xeb3(%rip),%rsi
mov    $0x1,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <error_exit@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [18 x i8] c"argument is empty\00"
@.str.1 = [19 x i8] c"invalid number: %s\00"
define i32 @convert_string_to_number(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = icmp ne i8 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = call i32 (i32, i8*, ...) @error_exit(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = load i8*, i8** %2
%12 = call i64 @strtoull(i8* %11, i8** %3, i32 0)
store i64 %12, i64* %4
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %10
%17 = load i8*, i8** %2
%18 = call i32 (i32, i8*, ...) @error_exit(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %10
%20 = load i64, i64* %4
%21 = trunc i64 %20 to i32
ret i32 %21
}

LLVM IR (-O2):
@.str = [18 x i8] c"argument is empty\00"
@.str.1 = [19 x i8] c"invalid number: %s\00"
define i32 @convert_string_to_number(i8* %0) {
%2 = alloca i8*
%3 = load i8, i8* %0
%4 = icmp eq i8 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 (i32, i8*, ...) @error_exit(i32 1, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %1
%8 = bitcast i8** %2 to i8*
%9 = call i64 @strtoull(i8* %0, i8** %2, i32 0)
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %7
%14 = tail call i32 (i32, i8*, ...) @error_exit(i32 1, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %13, %7
%16 = trunc i64 %9 to i32
ret i32 %16
}