#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__ isdigit(unsigned char const);
unsigned int read_int(const unsigned char **pstr) {
  unsigned int retval = **pstr - '0';
  while (isdigit(*++(*pstr))) {
    retval *= 10;
    retval += **pstr - '0';
  }
  return retval;
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,(%rcx)
movzbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     116f <read_int+0x5f>
imul   $0xa,-0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
movzbl (%rax),%eax
sub    $0x30,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    112c <read_int+0x1c>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rax
movzbl (%rax),%ebx
add    $0xffffffd0,%ebx
lea    0x1(%rax),%rcx
mov    %rcx,(%rdi)
movzbl 0x1(%rax),%edi
nopl   0x0(%rax,%rax,1)
call   1030 <isdigit@plt>
test   %rax,%rax
je     1156 <read_int+0x46>
lea    (%rbx,%rbx,4),%eax
mov    (%r14),%rcx
movzbl (%rcx),%edx
lea    (%rdx,%rax,2),%ebx
add    $0xffffffd0,%ebx
lea    0x1(%rcx),%rax
mov    %rax,(%r14)
movzbl 0x1(%rcx),%edi
jmp    1130 <read_int+0x20>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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