#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 */
scalar_t__ IsDigital(unsigned char const);
unsigned int atoi(char *);
unsigned int GprsGetReadNumber(const unsigned char *str, unsigned int *size) {
  unsigned int k = 0;
  unsigned char buffer[20] = {0};
  if (str == NULL)
    return 0;
  while ((str != NULL) && (IsDigital(*str))) {
    buffer[k++] = *str++;
  }
  *size = atoi((char *)buffer);
  return k;
}


x86 assembly (clang, -O0):
<GprsGetReadNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
jne    116e <GprsGetReadNumber+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <GprsGetReadNumber+0xb7>
jmp    1173 <GprsGetReadNumber+0x43>
xor    %eax,%eax
cmpq   $0x0,-0x10(%rbp)
mov    %al,-0x31(%rbp)
je     1199 <GprsGetReadNumber+0x69>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1050 <IsDigital@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11a9 <GprsGetReadNumber+0x79>
jmp    11d0 <GprsGetReadNumber+0xa0>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x1c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
mov    %eax,%eax
mov    %cl,-0x30(%rbp,%rax,1)
jmp    1173 <GprsGetReadNumber+0x43>
lea    -0x30(%rbp),%rdi
call   1040 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GprsGetReadNumber>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
test   %rdi,%rdi
je     118b <GprsGetReadNumber+0x6b>
mov    %rsi,%r14
mov    %rdi,%r15
movzbl (%rdi),%edi
call   1040 <IsDigital@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     117e <GprsGetReadNumber+0x5e>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%r15,%rbx,1),%eax
mov    %ebx,%ecx
mov    %al,(%rsp,%rcx,1)
movzbl 0x1(%r15,%rbx,1),%edi
call   1040 <IsDigital@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1160 <GprsGetReadNumber+0x40>
mov    %rsp,%rdi
call   1030 <atoi@plt>
mov    %eax,(%r14)
jmp    118d <GprsGetReadNumber+0x6d>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @GprsGetReadNumber(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [20 x i8]
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 0, i32* %6
%8 = bitcast [20 x i8]* %7 to i8*
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %36
12: ; preds = %2
br label %13
13: ; preds = %23, %12
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = load i8, i8* %17
%19 = call i64 @IsDigital(i8 zeroext %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %13
%22 = phi i1 [ false, %13 ], [ %20, %16 ]
br i1 %22, label %23, label %31
23: ; preds = %21
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
%26 = load i8, i8* %24
%27 = load i32, i32* %6
%28 = add i32 %27, 1
store i32 %28, i32* %6
%29 = zext i32 %27 to i64
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %29
store i8 %26, i8* %30
br label %13
31: ; preds = %21
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%33 = call i32 @atoi(i8* %32)
%34 = load i32*, i32** %5
store i32 %33, i32* %34
%35 = load i32, i32* %6
store i32 %35, i32* %3
br label %36
36: ; preds = %31, %11
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @GprsGetReadNumber(i8* %0, i32* nocapture writeonly %1) {
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %0, null
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = load i8, i8* %0
%8 = tail call i64 @IsDigital(i8 zeroext %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %6, %10
%11 = phi i32 [ %15, %10 ], [ 0, %6 ]
%12 = phi i8* [ %13, %10 ], [ %0, %6 ]
%13 = getelementptr inbounds i8, i8* %12, i64 1
%14 = load i8, i8* %12
%15 = add i32 %11, 1
%16 = zext i32 %11 to i64
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 %16
store i8 %14, i8* %17
%18 = load i8, i8* %13
%19 = tail call i64 @IsDigital(i8 zeroext %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %10
21: ; preds = %10, %6
%22 = phi i32 [ 0, %6 ], [ %15, %10 ]
%23 = call i32 @atoi(i8* %4)
store i32 %23, i32* %1
br label %24
24: ; preds = %2, %21
%25 = phi i32 [ %22, %21 ], [ 0, %2 ]
ret i32 %25
}