#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 */
unsigned int UINT_MAX;
scalar_t__ atol(char const *);
scalar_t__ isdigit(char const);
const char *read_number(const char *str, unsigned int *num) {
  if (str == NULL || num == NULL) {
    return str;
  }
  while (*str == ' ') {
    str++;
  }
  if (!isdigit(*str)) {
    *num = UINT_MAX;
    return str;
  }
  *num = (unsigned int)atol(str);
  while (isdigit(*str)) {
    str++;
  }
  return str;
}


x86 assembly (clang, -O0):
<read_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1146 <read_number+0x26>
cmpq   $0x0,-0x18(%rbp)
jne    1153 <read_number+0x33>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11eb <read_number+0xcb>
jmp    1158 <read_number+0x38>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    1179 <read_number+0x59>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1158 <read_number+0x38>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
jne    11ab <read_number+0x8b>
mov    0x2e52(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11eb <read_number+0xcb>
mov    -0x10(%rbp),%rdi
call   1040 <atol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     11e3 <read_number+0xc3>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11bc <read_number+0x9c>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_number>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
test   %rdi,%rdi
je     1190 <read_number+0x70>
mov    %rsi,%r14
test   %rsi,%rsi
je     1190 <read_number+0x70>
add    $0xffffffffffffffff,%rbx
nopl   0x0(%rax)
movzbl 0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x20,%al
je     1140 <read_number+0x20>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     1184 <read_number+0x64>
lea    -0x1(%rbx),%r15
mov    %rbx,%rdi
call   1040 <atol@plt>
mov    %eax,(%r14)
mov    %r15,%rbx
nopl   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1170 <read_number+0x50>
jmp    1190 <read_number+0x70>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@UINT_MAX = global i32 0
define i8* @read_number(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%6 = load i8*, i8** %4
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = load i32*, i32** %5
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8, %2
%12 = load i8*, i8** %4
store i8* %12, i8** %3
br label %46
13: ; preds = %8
br label %14
14: ; preds = %19, %13
%15 = load i8*, i8** %4
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
br label %14
22: ; preds = %14
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = call i64 @isdigit(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %22
%28 = load i32, i32* @UINT_MAX
%29 = load i32*, i32** %5
store i32 %28, i32* %29
%30 = load i8*, i8** %4
store i8* %30, i8** %3
br label %46
31: ; preds = %22
%32 = load i8*, i8** %4
%33 = call i64 @atol(i8* %32)
%34 = trunc i64 %33 to i32
%35 = load i32*, i32** %5
store i32 %34, i32* %35
br label %36
36: ; preds = %41, %31
%37 = load i8*, i8** %4
%38 = load i8, i8* %37
%39 = call i64 @isdigit(i8 signext %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i8*, i8** %4
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %4
br label %36
44: ; preds = %36
%45 = load i8*, i8** %4
store i8* %45, i8** %3
br label %46
46: ; preds = %44, %27, %11
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@UINT_MAX = global i32 0
define i8* @read_number(i8* %0, i32* writeonly %1) {
%3 = icmp eq i8* %0, null
%4 = icmp eq i32* %1, null
%5 = or i1 %3, %4
br i1 %5, label %25, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %10, %6 ], [ %0, %2 ]
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 32
%10 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %9, label %6, label %11
11: ; preds = %6
%12 = tail call i64 @isdigit(i8 signext %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = load i32, i32* @UINT_MAX
store i32 %15, i32* %1
br label %25
16: ; preds = %11
%17 = tail call i64 @atol(i8* %7)
%18 = trunc i64 %17 to i32
store i32 %18, i32* %1
br label %19
19: ; preds = %19, %16
%20 = phi i8* [ %7, %16 ], [ %24, %19 ]
%21 = load i8, i8* %20
%22 = tail call i64 @isdigit(i8 signext %21)
%23 = icmp eq i64 %22, 0
%24 = getelementptr inbounds i8, i8* %20, i64 1
br i1 %23, label %25, label %19
25: ; preds = %19, %2, %14
%26 = phi i8* [ %7, %14 ], [ %0, %2 ], [ %20, %19 ]
ret i8* %26
}