#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(char);
unsigned scan_number(const char **format) {
  unsigned n = 0;
  char c = **format;
  while (isdigit(c)) {
    n = n * 10 + c - '0';
    (*format)++;
    c = **format;
  }
  return n;
}


x86 assembly (clang, -O0):
<scan_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
movsbl -0xd(%rbp),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1171 <scan_number+0x61>
imul   $0xa,-0xc(%rbp),%eax
movsbl -0xd(%rbp),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%al
mov    %al,-0xd(%rbp)
jmp    112f <scan_number+0x1f>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_number>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%rax
mov    (%rax),%bl
movsbl %bl,%edi
call   1030 <isdigit@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     115a <scan_number+0x4a>
nopl   (%rax)
lea    (%r15,%r15,4),%eax
movsbl %bl,%ecx
lea    (%rcx,%rax,2),%r15d
add    $0xffffffd0,%r15d
mov    (%r14),%rax
lea    0x1(%rax),%rcx
mov    %rcx,(%r14)
movzbl 0x1(%rax),%ebx
movsbl %bl,%edi
call   1030 <isdigit@plt>
test   %rax,%rax
jne    1130 <scan_number+0x20>
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

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