#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 /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ printf(char *, int);
int main() {
  char *t, s[8];
  int n;
  t = s;
  gets(t);
  n = *t - '0';
  while (*(++t) != '\0')
    n = n * 8 + *t - '0';
  printf(" %d\n", n);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <gets@plt>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1183 <main+0x63>
mov    -0x1c(%rbp),%eax
shl    $0x3,%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
add    %ecx,%eax
sub    $0x30,%eax
mov    %eax,-0x1c(%rbp)
jmp    114d <main+0x2d>
mov    -0x1c(%rbp),%esi
lea    0xe73(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1040 <gets@plt>
movsbl (%rsp),%esi
add    $0xffffffd0,%esi
mov    0x1(%rsp),%cl
test   %cl,%cl
je     1154 <main+0x34>
lea    0x2(%rsp),%rax
nopl   (%rax)
movsbl %cl,%ecx
lea    (%rcx,%rsi,8),%esi
add    $0xffffffd0,%esi
movzbl (%rax),%ecx
add    $0x1,%rax
test   %cl,%cl
jne    1140 <main+0x20>
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c" %d\0A\00"
define i32 @main() {
%1 = alloca [8 x i8]
%2 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%3 = call i32 @gets(i8* %2)
%4 = load i8, i8* %2
%5 = sext i8 %4 to i32
%6 = add nsw i32 %5, -48
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %0, %10
%11 = phi i8 [ %19, %10 ], [ %8, %0 ]
%12 = phi i8* [ %18, %10 ], [ %7, %0 ]
%13 = phi i32 [ %17, %10 ], [ %6, %0 ]
%14 = sext i8 %11 to i32
%15 = shl nsw i32 %13, 3
%16 = add nsw i32 %15, %14
%17 = add nsw i32 %16, -48
%18 = getelementptr inbounds i8, i8* %12, i64 1
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %10
21: ; preds = %10, %0
%22 = phi i32 [ %6, %0 ], [ %17, %10 ]
%23 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
ret i32 0
}