#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 */
typedef int /*<<< orphan*/ pattern;

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int sscanf(char const *, char *, unsigned long long *);
unsigned long long read_octal_number(const char *str, int len) {
  char pattern[15];
  long long unsigned v;
  int res;
  int i;
  for (i = 0; i < len; ++i) {
    if (str[i] == 0)
      break;
    if ((str[i] < '0' || str[i] > '7'))
      return 0;
  }
  snprintf(pattern, sizeof(pattern), "%%%iLo", len);
  if (str[0] == '\0')
    return 0;
  res = sscanf(str, pattern, &v);
  if (res != 1)
    error("Failed number parsing");
  return v;
}


x86 assembly (clang, -O0):
<read_octal_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b6 <read_octal_number+0x86>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    116c <read_octal_number+0x3c>
jmp    11b6 <read_octal_number+0x86>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jl     1196 <read_octal_number+0x66>
mov    -0x10(%rbp),%rax
movslq -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x37,%eax
jle    11a3 <read_octal_number+0x73>
movq   $0x0,-0x8(%rbp)
jmp    121d <read_octal_number+0xed>
jmp    11a8 <read_octal_number+0x78>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1146 <read_octal_number+0x16>
lea    -0x23(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0xf,%esi
lea    0xe37(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11eb <read_octal_number+0xbb>
movq   $0x0,-0x8(%rbp)
jmp    121d <read_octal_number+0xed>
mov    -0x10(%rbp),%rdi
lea    -0x23(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1040 <sscanf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
je     1215 <read_octal_number+0xe5>
lea    0xdf7(%rip),%rdi
call   1050 <error@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_octal_number>:
push   %rbx
sub    $0x20,%rsp
mov    %esi,%r8d
mov    %rdi,%rbx
test   %esi,%esi
jle    1169 <read_octal_number+0x39>
mov    %r8d,%edx
xor    %eax,%eax
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx,%rsi,1),%ecx
test   %cl,%cl
je     1169 <read_octal_number+0x39>
add    $0xc8,%cl
cmp    $0xf8,%cl
jb     11b3 <read_octal_number+0x83>
add    $0x1,%rsi
cmp    %rsi,%rdx
jne    1150 <read_octal_number+0x20>
lea    0xe90(%rip),%rdx
lea    0x11(%rsp),%rdi
mov    $0xf,%esi
mov    %r8d,%ecx
call   1030 <snprintf@plt>
cmpb   $0x0,(%rbx)
je     11b1 <read_octal_number+0x81>
lea    0x11(%rsp),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <sscanf@plt>
cmp    $0x1,%eax
je     11aa <read_octal_number+0x7a>
lea    0xe62(%rip),%rdi
call   1050 <error@plt>
mov    0x8(%rsp),%rax
jmp    11b3 <read_octal_number+0x83>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%%%iLo\00"
@.str.1 = [22 x i8] c"Failed number parsing\00"
define i64 @read_octal_number(i8* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [15 x i8]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %9
br label %10
10: ; preds = %41, %2
%11 = load i32, i32* %9
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %44
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %14
br label %44
23: ; preds = %14
%24 = load i8*, i8** %4
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp slt i32 %29, 48
br i1 %30, label %39, label %31
31: ; preds = %23
%32 = load i8*, i8** %4
%33 = load i32, i32* %9
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp sgt i32 %37, 55
br i1 %38, label %39, label %40
39: ; preds = %31, %23
store i64 0, i64* %3
br label %64
40: ; preds = %31
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %10
44: ; preds = %22, %10
%45 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%46 = load i32, i32* %5
%47 = call i32 @snprintf(i8* %45, i32 15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %46)
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i64 0
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %44
store i64 0, i64* %3
br label %64
54: ; preds = %44
%55 = load i8*, i8** %4
%56 = getelementptr inbounds [15 x i8], [15 x i8]* %6, i64 0, i64 0
%57 = call i32 @sscanf(i8* %55, i8* %56, i64* %7)
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = icmp ne i32 %58, 1
br i1 %59, label %60, label %62
60: ; preds = %54
%61 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %60, %54
%63 = load i64, i64* %7
store i64 %63, i64* %3
br label %64
64: ; preds = %62, %53, %39
%65 = load i64, i64* %3
ret i64 %65
}

LLVM IR (-O2):
@.str = [7 x i8] c"%%%iLo\00"
@.str.1 = [22 x i8] c"Failed number parsing\00"
define i64 @read_octal_number(i8* nocapture %0, i32 %1) {
%3 = alloca [15 x i8]
%4 = alloca i64
%5 = getelementptr inbounds [15 x i8], [15 x i8]* %3, i64 0, i64 0
%6 = bitcast i64* %4 to i8*
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %21
8: ; preds = %2
%9 = zext i32 %1 to i64
br label %12
10: ; preds = %17
%11 = icmp eq i64 %20, %9
br i1 %11, label %21, label %12
12: ; preds = %8, %10
%13 = phi i64 [ 0, %8 ], [ %20, %10 ]
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %12
%18 = add i8 %15, -56
%19 = icmp ult i8 %18, -8
%20 = add nuw nsw i64 %13, 1
br i1 %19, label %32, label %10
21: ; preds = %10, %12, %2
%22 = call i32 @snprintf(i8* %5, i32 15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %1)
%23 = load i8, i8* %0
%24 = icmp eq i8 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %21
%26 = call i32 @sscanf(i8* %0, i8* %5, i64* %4)
%27 = icmp eq i32 %26, 1
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = load i64, i64* %4
br label %32
32: ; preds = %17, %21, %30
%33 = phi i64 [ %31, %30 ], [ 0, %21 ], [ 0, %17 ]
ret i64 %33
}