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

/* Variables and functions */
unsigned long long UINT32_MAX;
scalar_t__ errno;
unsigned long long *malloc(int);
unsigned long long strtoul(char const *, char **, int /*<<< orphan*/);
uint32_t *parse_number32(const char *argv) {
  unsigned long long tmp;
  uint32_t *n = malloc(sizeof(*n));
  char *endptr;
  if (!argv)
    return NULL;
  errno = 0;
  tmp = strtoul(argv, &endptr, 0);
  if (errno || *endptr != '\0' || tmp > UINT32_MAX)
    return NULL;
  *n = tmp;
  return n;
}


x86 assembly (clang, -O0):
<parse_number32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x8,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1152 <parse_number32+0x32>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <parse_number32+0xa8>
mov    0x2e7f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e5e(%rip),%rax
cmpq   $0x0,(%rax)
jne    11a8 <parse_number32+0x88>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a8 <parse_number32+0x88>
mov    -0x18(%rbp),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
jbe    11b5 <parse_number32+0x95>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <parse_number32+0xa8>
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_number32>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x8,%edi
call   1030 <malloc@plt>
test   %rbx,%rbx
je     1183 <parse_number32+0x63>
mov    %rax,%r14
mov    0x2e94(%rip),%r12
movq   $0x0,(%r12)
mov    %rsp,%rsi
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %edx,%edx
call   1040 <strtoul@plt>
cmpq   $0x0,(%r12)
jne    1186 <parse_number32+0x66>
mov    (%rsp),%rcx
xor    %r15d,%r15d
cmpb   $0x0,(%rcx)
jne    1186 <parse_number32+0x66>
mov    0x2e82(%rip),%rcx
cmp    (%rcx),%rax
ja     1186 <parse_number32+0x66>
mov    %rax,(%r14)
mov    %r14,%r15
jmp    1186 <parse_number32+0x66>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@errno = global i64 0
@UINT32_MAX = global i64 0
define noalias i64* @parse_number32(i8* %0) {
%2 = alloca i8*
%3 = tail call i64* @malloc(i32 8)
%4 = bitcast i8** %2 to i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %18, label %6
6: ; preds = %1
store i64 0, i64* @errno
%7 = call i64 @strtoul(i8* %0, i8** %2, i32 0)
%8 = load i64, i64* @errno
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = icmp ne i8 %12, 0
%14 = load i64, i64* @UINT32_MAX
%15 = icmp ugt i64 %7, %14
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %18, label %17
17: ; preds = %10
store i64 %7, i64* %3
br label %18
18: ; preds = %6, %10, %1, %17
%19 = phi i64* [ %3, %17 ], [ null, %1 ], [ null, %10 ], [ null, %6 ]
ret i64* %19
}