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


x86 assembly (clang, -O0):
<GprsGetReadDigitalNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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 <GprsGetReadDigitalNumber+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    11dc <GprsGetReadDigitalNumber+0xac>
jmp    1173 <GprsGetReadDigitalNumber+0x43>
cmpq   $0x0,-0x10(%rbp)
je     11c5 <GprsGetReadDigitalNumber+0x95>
mov    -0x10(%rbp),%rax
movzbl (%rax),%edi
call   1050 <IsDigital@plt>
cmp    $0x0,%rax
je     11bb <GprsGetReadDigitalNumber+0x8b>
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    11c0 <GprsGetReadDigitalNumber+0x90>
jmp    11c5 <GprsGetReadDigitalNumber+0x95>
jmp    1173 <GprsGetReadDigitalNumber+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    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GprsGetReadDigitalNumber>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
test   %rdi,%rdi
je     118b <GprsGetReadDigitalNumber+0x6b>
mov    %rsi,%r14
mov    %rdi,%r15
movzbl (%rdi),%edi
call   1040 <IsDigital@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     117e <GprsGetReadDigitalNumber+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 <GprsGetReadDigitalNumber+0x40>
mov    %rsp,%rdi
call   1030 <atoi@plt>
mov    %eax,(%r14)
jmp    118d <GprsGetReadDigitalNumber+0x6d>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @GprsGetReadDigitalNumber(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 = %30, %12
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %31
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 i1 %20, label %21, label %29
21: ; preds = %16
%22 = load i8*, i8** %4
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %4
%24 = load i8, i8* %22
%25 = load i32, i32* %6
%26 = add i32 %25, 1
store i32 %26, i32* %6
%27 = zext i32 %25 to i64
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %27
store i8 %24, i8* %28
br label %30
29: ; preds = %16
br label %31
30: ; preds = %21
br label %13
31: ; preds = %29, %13
%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 @GprsGetReadDigitalNumber(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
}