#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 */
struct lookahead_state {
  int dummy;
};

/* Variables and functions */
int _lookahead_getc(struct lookahead_state *);
int /*<<< orphan*/ _lookahead_revert(struct lookahead_state *, unsigned int);
unsigned int _lookahead_tell(struct lookahead_state *);
unsigned int _parse_dec(struct lookahead_state *lookahead) {
  unsigned int n = 0;
  for (;;) {
    unsigned int pos = _lookahead_tell(lookahead);
    int c = _lookahead_getc(lookahead);
    if ((c >= '0' && c <= '9')) {
      n++;
    } else {
      _lookahead_revert(lookahead, pos);
      break;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<_parse_dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <_lookahead_tell@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <_lookahead_getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
jl     117d <_parse_dec+0x4d>
cmpl   $0x39,-0x14(%rbp)
jg     117d <_parse_dec+0x4d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118e <_parse_dec+0x5e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <_lookahead_revert@plt>
jmp    1193 <_parse_dec+0x63>
jmp    1143 <_parse_dec+0x13>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_dec>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
mov    $0xffffffff,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1050 <_lookahead_tell@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <_lookahead_getc@plt>
add    $0xffffffd0,%eax
add    $0x1,%ebx
cmp    $0xa,%eax
jb     1140 <_parse_dec+0x10>
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <_lookahead_revert@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.lookahead_state = type { i32 }
define i32 @_parse_dec(%struct.lookahead_state* %0) {
%2 = alloca %struct.lookahead_state*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.lookahead_state* %0, %struct.lookahead_state** %2
store i32 0, i32* %3
br label %6
6: ; preds = %23, %1
%7 = load %struct.lookahead_state*, %struct.lookahead_state** %2
%8 = call i32 @_lookahead_tell(%struct.lookahead_state* %7)
store i32 %8, i32* %4
%9 = load %struct.lookahead_state*, %struct.lookahead_state** %2
%10 = call i32 @_lookahead_getc(%struct.lookahead_state* %9)
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 48
br i1 %12, label %13, label %19
13: ; preds = %6
%14 = load i32, i32* %5
%15 = icmp sle i32 %14, 57
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i32, i32* %3
%18 = add i32 %17, 1
store i32 %18, i32* %3
br label %23
19: ; preds = %13, %6
%20 = load %struct.lookahead_state*, %struct.lookahead_state** %2
%21 = load i32, i32* %4
%22 = call i32 @_lookahead_revert(%struct.lookahead_state* %20, i32 %21)
br label %24
23: ; preds = %16
br label %6
24: ; preds = %19
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.lookahead_state = type { i32 }
define i32 @_parse_dec(%struct.lookahead_state* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i32 [ 0, %1 ], [ %8, %2 ]
%4 = tail call i32 @_lookahead_tell(%struct.lookahead_state* %0)
%5 = tail call i32 @_lookahead_getc(%struct.lookahead_state* %0)
%6 = add i32 %5, -48
%7 = icmp ult i32 %6, 10
%8 = add i32 %3, 1
br i1 %7, label %2, label %9
9: ; preds = %2
%10 = tail call i32 @_lookahead_revert(%struct.lookahead_state* %0, i32 %4)
ret i32 %3
}