#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__ digitValue(char);
scalar_t__ isOctalDigit(char);
int strlen(char const *);
int octalValue(char const *octalString) {
  int numberValue = 0;
  int i = 0, siz = 0;
  char digit = 0;
  siz = strlen(octalString);
  for (i = 0; i < siz; i++) {
    digit = octalString[i];
    if (isOctalDigit(digit)) {
      numberValue <<= 3;
      numberValue += digitValue(digit);
    } else {
      break;
    }
  }
  return numberValue;
}


x86 assembly (clang, -O0):
<octalValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d1 <octalValue+0xa1>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
movsbl -0x15(%rbp),%edi
call   1030 <isOctalDigit@plt>
cmp    $0x0,%rax
je     11b9 <octalValue+0x89>
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
mov    %eax,-0xc(%rbp)
movsbl -0x15(%rbp),%edi
call   1050 <digitValue@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    11be <octalValue+0x8e>
jmp    11d1 <octalValue+0xa1>
jmp    11c3 <octalValue+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1168 <octalValue+0x38>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<octalValue>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
test   %eax,%eax
jle    1177 <octalValue+0x47>
mov    %eax,%r15d
xor    %ebx,%ebx
xor    %r12d,%r12d
nopl   0x0(%rax)
movsbl (%r14,%rbx,1),%ebp
mov    %ebp,%edi
call   1030 <isOctalDigit@plt>
test   %rax,%rax
je     117a <octalValue+0x4a>
mov    %ebp,%edi
call   1050 <digitValue@plt>
lea    (%rax,%r12,8),%r12d
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <octalValue+0x20>
jmp    117a <octalValue+0x4a>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @octalValue(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i8 0, i8* %6
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %5
store i32 0, i32* %4
br label %9
9: ; preds = %33, %1
%10 = load i32, i32* %4
%11 = load i32, i32* %5
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
store i8 %18, i8* %6
%19 = load i8, i8* %6
%20 = call i64 @isOctalDigit(i8 signext %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %13
%23 = load i32, i32* %3
%24 = shl i32 %23, 3
store i32 %24, i32* %3
%25 = load i8, i8* %6
%26 = call i64 @digitValue(i8 signext %25)
%27 = load i32, i32* %3
%28 = sext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %3
br label %32
31: ; preds = %13
br label %36
32: ; preds = %22
br label %33
33: ; preds = %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
br label %9
36: ; preds = %31, %9
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
define i32 @octalValue(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %13
%7 = phi i64 [ 0, %4 ], [ %18, %13 ]
%8 = phi i32 [ 0, %4 ], [ %17, %13 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = load i8, i8* %9
%11 = tail call i64 @isOctalDigit(i8 signext %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %6
%14 = shl i32 %8, 3
%15 = tail call i64 @digitValue(i8 signext %10)
%16 = trunc i64 %15 to i32
%17 = add i32 %14, %16
%18 = add nuw nsw i64 %7, 1
%19 = icmp eq i64 %18, %5
br i1 %19, label %20, label %6
20: ; preds = %13, %6, %1
%21 = phi i32 [ 0, %1 ], [ %8, %6 ], [ %17, %13 ]
ret i32 %21
}