#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 pow(int, int /*<<< orphan*/);
int strlen(char *);
int convert_permissions(char *permissions) {
  int i, j = 0, r = 0, res = 0;
  for (i = strlen(permissions) - 1; i >= 0; i--) {
    if (permissions[i] < 48 || permissions[i] > 57) {
      return -1;
    }
    r += pow(8, j++) * (permissions[i] - 48);
  }
  j = 0;
  do {
    i = r % 2;
    res += pow(2, j++) * i;
  } while (r /= 2);
}


x86 assembly (clang, -O0):
<convert_permissions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11cb <convert_permissions+0xab>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x30,%eax
jl     1184 <convert_permissions+0x64>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x39,%eax
jle    1190 <convert_permissions+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <convert_permissions+0xf6>
mov    -0x18(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    $0x8,%edi
call   1040 <pow@plt>
mov    -0x10(%rbp),%rcx
movslq -0x14(%rbp),%rdx
movsbl (%rcx,%rdx,1),%ecx
sub    $0x30,%ecx
imul   %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1150 <convert_permissions+0x30>
movl   $0x0,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x18(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    $0x2,%edi
call   1040 <pow@plt>
imul   -0x14(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11d2 <convert_permissions+0xb2>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_permissions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
xor    %r12d,%r12d
mov    $0x0,%ebx
test   %eax,%eax
jle    1186 <convert_permissions+0x66>
mov    %eax,%r15d
add    $0xffffffffffffffff,%r15
xor    %ebx,%ebx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
mov    %r15d,%ebp
movzbl (%r14,%rbp,1),%eax
add    $0xc6,%al
cmp    $0xf6,%al
jb     11b6 <convert_permissions+0x96>
lea    0x1(%rsi),%r13d
mov    $0x8,%edi
call   1040 <pow@plt>
movsbl (%r14,%rbp,1),%ecx
add    $0xffffffd0,%ecx
imul   %eax,%ecx
add    %ecx,%ebx
add    $0xffffffffffffffff,%r15
mov    %r13d,%esi
cmp    $0xffffffff,%r15d
jne    1150 <convert_permissions+0x30>
mov    %ebx,%ebp
nopl   0x0(%rax,%rax,1)
lea    0x1(%r12),%r14d
mov    $0x2,%edi
mov    %r12d,%esi
call   1040 <pow@plt>
shr    $0x1f,%ebp
add    %ebx,%ebp
sar    %ebp
add    $0x1,%ebx
mov    %r14d,%r12d
cmp    $0x2,%ebx
mov    %ebp,%ebx
ja     1190 <convert_permissions+0x70>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @convert_permissions(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %4
br label %11
11: ; preds = %45, %1
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %48
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load i32, i32* %4
%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 slt i32 %20, 48
br i1 %21, label %30, label %22
22: ; preds = %14
%23 = load i8*, i8** %3
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp sgt i32 %28, 57
br i1 %29, label %30, label %31
30: ; preds = %22, %14
store i32 -1, i32* %2
br label %63
31: ; preds = %22
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = call i32 @pow(i32 8, i32 %32)
%35 = load i8*, i8** %3
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = sub nsw i32 %40, 48
%42 = mul nsw i32 %34, %41
%43 = load i32, i32* %6
%44 = add nsw i32 %43, %42
store i32 %44, i32* %6
br label %45
45: ; preds = %31
%46 = load i32, i32* %4
%47 = add nsw i32 %46, -1
store i32 %47, i32* %4
br label %11
48: ; preds = %11
store i32 0, i32* %5
br label %49
49: ; preds = %59, %48
%50 = load i32, i32* %6
%51 = srem i32 %50, 2
store i32 %51, i32* %4
%52 = load i32, i32* %5
%53 = add nsw i32 %52, 1
store i32 %53, i32* %5
%54 = call i32 @pow(i32 2, i32 %52)
%55 = load i32, i32* %4
%56 = mul nsw i32 %54, %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, %56
store i32 %58, i32* %7
br label %59
59: ; preds = %49
%60 = load i32, i32* %6
%61 = sdiv i32 %60, 2
store i32 %61, i32* %6
%62 = icmp ne i32 %61, 0
br i1 %62, label %49, label %63
63: ; preds = %30, %59
%64 = load i32, i32* %2
ret i32 %64
}

LLVM IR (-O2):
define i32 @convert_permissions(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %25
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %16
%7 = phi i64 [ %5, %4 ], [ %10, %16 ]
%8 = phi i32 [ 0, %4 ], [ %23, %16 ]
%9 = phi i32 [ 0, %4 ], [ %17, %16 ]
%10 = add nsw i64 %7, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = add i8 %13, -58
%15 = icmp ult i8 %14, -10
br i1 %15, label %35, label %16
16: ; preds = %6
%17 = add nuw nsw i32 %9, 1
%18 = tail call i32 @pow(i32 8, i32 %9)
%19 = load i8, i8* %12
%20 = sext i8 %19 to i32
%21 = add nsw i32 %20, -48
%22 = mul nsw i32 %21, %18
%23 = add nsw i32 %22, %8
%24 = icmp eq i32 %17, %2
br i1 %24, label %25, label %6
25: ; preds = %16, %1
%26 = phi i32 [ 0, %1 ], [ %23, %16 ]
br label %27
27: ; preds = %25, %27
%28 = phi i32 [ %30, %27 ], [ 0, %25 ]
%29 = phi i32 [ %32, %27 ], [ %26, %25 ]
%30 = add nuw nsw i32 %28, 1
%31 = tail call i32 @pow(i32 2, i32 %28)
%32 = sdiv i32 %29, 2
%33 = add i32 %29, 1
%34 = icmp ult i32 %33, 3
br i1 %34, label %35, label %27
35: ; preds = %6, %27
ret i32 -1
}