#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 long uint32_t;

/* Variables and functions */
int strlen(char const *);
long strtol(char const *, char **, int /*<<< orphan*/);
bool read_number(const char *str, uint32_t *value) {
  char *end;
  long int ret = strtol(str, &end, 0);
  if ((str + strlen(str)) != end)
    return false;
  if (ret < 0)
    return false;
  *value = ret;
  return true;
}


x86 assembly (clang, -O0):
<read_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
cmp    -0x20(%rbp),%rax
je     1176 <read_number+0x56>
movl   $0x0,-0x4(%rbp)
jmp    119f <read_number+0x7f>
cmpq   $0x0,-0x28(%rbp)
jge    118d <read_number+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    119f <read_number+0x7f>
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_number>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
mov    %rsp,%rsi
xor    %r15d,%r15d
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
add    %rbp,%rax
cmp    (%rsp),%rax
jne    115e <read_number+0x3e>
test   %rbx,%rbx
js     115e <read_number+0x3e>
mov    %rbx,(%r14)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @read_number(i8* %0, i64* nocapture writeonly %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i64 @strtol(i8* %0, i8** %3, i32 0)
%6 = tail call i32 @strlen(i8* %0)
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8*, i8** %3
%10 = icmp ne i8* %8, %9
%11 = icmp slt i64 %5, 0
%12 = select i1 %10, i1 true, i1 %11
br i1 %12, label %14, label %13
13: ; preds = %2
store i64 %5, i64* %1
br label %14
14: ; preds = %2, %13
%15 = phi i32 [ 1, %13 ], [ 0, %2 ]
ret i32 %15
}