#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_oct(struct lookahead_state *lookahead) {
  int c;
  unsigned int n;
  c = _lookahead_getc(lookahead);
  if (c != '0') {
    _lookahead_revert(lookahead, 0);
    return 0;
  }
  for (n = 1;;) {
    unsigned int pos = _lookahead_tell(lookahead);
    c = _lookahead_getc(lookahead);
    if ((c >= '0' && c <= '7')) {
      n++;
    } else {
      _lookahead_revert(lookahead, pos);
      break;
    }
  }
  return n;
}


x86 assembly (clang, -O0):
<_parse_oct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_lookahead_getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
je     1169 <_parse_oct+0x39>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <_lookahead_revert@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <_parse_oct+0x96>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <_lookahead_tell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <_lookahead_getc@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x30,-0x14(%rbp)
jl     11aa <_parse_oct+0x7a>
cmpl   $0x37,-0x14(%rbp)
jg     11aa <_parse_oct+0x7a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11bb <_parse_oct+0x8b>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <_lookahead_revert@plt>
jmp    11c0 <_parse_oct+0x90>
jmp    1170 <_parse_oct+0x40>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_parse_oct>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <_lookahead_getc@plt>
xor    %ebx,%ebx
mov    $0x0,%ebp
cmp    $0x30,%eax
jne    116d <_parse_oct+0x3d>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <_lookahead_tell@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <_lookahead_getc@plt>
and    $0xfffffff8,%eax
add    $0x1,%ebp
cmp    $0x30,%eax
je     1150 <_parse_oct+0x20>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <_lookahead_revert@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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