#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 */
int atoi(char *);
int pow(int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int oct2int(char *_oct) {
  int oct = atoi(_oct);
  printf("%d ** %s\n", oct, _oct);
  int result = 0;
  int exp = 0;
  while (oct != 0) {
    result = result + (oct % 10) * pow(8, exp);
    exp++;
    oct = oct / 10;
  }
  printf("result %d --", result);
  return result;
}


x86 assembly (clang, -O0):
<oct2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     11c2 <oct2int+0x92>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x1c(%rbp)
mov    -0x14(%rbp),%esi
mov    $0x8,%edi
call   1040 <pow@plt>
mov    -0x1c(%rbp),%edx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%edx
add    %edx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    116b <oct2int+0x3b>
mov    -0x10(%rbp),%esi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oct2int>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
call   1050 <atoi@plt>
mov    %eax,%ebx
lea    0xebb(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
test   %ebx,%ebx
je     119e <oct2int+0x6e>
xor    %ebp,%ebp
xor    %r14d,%r14d
nopl   (%rax)
mov    $0x8,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
movslq %ebx,%rcx
imul   $0x66666667,%rcx,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rbx
add    %edx,%ebx
lea    (%rbx,%rbx,1),%edx
lea    (%rdx,%rdx,4),%edx
mov    %ecx,%esi
sub    %edx,%esi
imul   %eax,%esi
add    %esi,%r14d
add    $0x1,%ebp
add    $0x9,%ecx
cmp    $0x12,%ecx
ja     1160 <oct2int+0x30>
lea    0xe65(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%d ** %s\0A\00"
@.str.1 = [13 x i8] c"result %d --\00"
define i32 @oct2int(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @atoi(i8* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = load i8*, i8** %2
%10 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %9)
store i32 0, i32* %4
store i32 0, i32* %5
br label %11
11: ; preds = %14, %1
%12 = load i32, i32* %3
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %26
14: ; preds = %11
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = srem i32 %16, 10
%18 = load i32, i32* %5
%19 = call i32 @pow(i32 8, i32 %18)
%20 = mul nsw i32 %17, %19
%21 = add nsw i32 %15, %20
store i32 %21, i32* %4
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
%24 = load i32, i32* %3
%25 = sdiv i32 %24, 10
store i32 %25, i32* %3
br label %11
26: ; preds = %11
%27 = load i32, i32* %4
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@.str = [10 x i8] c"%d ** %s\0A\00"
@.str.1 = [13 x i8] c"result %d --\00"
define i32 @oct2int(i8* %0) {
%2 = tail call i32 @atoi(i8* %0)
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %0)
%4 = icmp eq i32 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %1, %5
%6 = phi i32 [ %13, %5 ], [ 0, %1 ]
%7 = phi i32 [ %12, %5 ], [ 0, %1 ]
%8 = phi i32 [ %14, %5 ], [ %2, %1 ]
%9 = srem i32 %8, 10
%10 = tail call i32 @pow(i32 8, i32 %6)
%11 = mul nsw i32 %10, %9
%12 = add nsw i32 %11, %7
%13 = add nuw nsw i32 %6, 1
%14 = sdiv i32 %8, 10
%15 = add i32 %8, 9
%16 = icmp ult i32 %15, 19
br i1 %16, label %17, label %5
17: ; preds = %5, %1
%18 = phi i32 [ 0, %1 ], [ %12, %5 ]
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18)
ret i32 %18
}