#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__ gets(char *);
int mi(int);
int /*<<< orphan*/ printf(char *, int);
int strlen(char *);
int main() {
  int len, i, out;
  char line[500];
  while (gets(line)) {
    out = 0;
    len = strlen(line);
    for (i = 0; i < len; i++)
      out += (int)(line[i] - '0') * (mi(len - i) - 1);
    if (out == 0)
      return 0;
    printf("%d\n", out);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x210(%rbp),%rdi
call   1050 <gets@plt>
cmp    $0x0,%rax
je     11fd <main+0xbd>
movl   $0x0,-0x10(%rbp)
lea    -0x210(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11d3 <main+0x93>
movslq -0xc(%rbp),%rax
movsbl -0x210(%rbp,%rax,1),%eax
ff
sub    $0x30,%eax
mov    %eax,-0x214(%rbp)
mov    -0x8(%rbp),%edi
sub    -0xc(%rbp),%edi
call   1060 <mi@plt>
mov    %eax,%ecx
mov    -0x214(%rbp),%eax
sub    $0x1,%ecx
imul   %ecx,%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1185 <main+0x45>
cmpl   $0x0,-0x10(%rbp)
jne    11e9 <main+0xa9>
movl   $0x0,-0x4(%rbp)
jmp    1204 <main+0xc4>
mov    -0x10(%rbp),%esi
lea    0xe0d(%rip),%rdi
call   1040 <printf@plt>
jmp    1152 <main+0x12>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
mov    %rsp,%r15
mov    %r15,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11d1 <main+0x91>
lea    0xe98(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11d1 <main+0x91>
mov    %eax,%ebx
xor    %r12d,%r12d
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl 0x0(%rbp),%r13d
add    $0xffffffd0,%r13d
mov    %ebx,%edi
call   1060 <mi@plt>
add    $0xffffffff,%eax
imul   %r13d,%eax
add    %eax,%r12d
add    $0x1,%rbp
add    $0xffffffffffffffff,%rbx
jne    1190 <main+0x50>
test   %r12d,%r12d
je     11d1 <main+0x91>
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <gets@plt>
test   %rax,%rax
jne    1170 <main+0x30>
xor    %eax,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [500 x i8]
store i32 0, i32* %1
br label %6
6: ; preds = %39, %0
%7 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%8 = call i64 @gets(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %42
10: ; preds = %6
store i32 0, i32* %4
%11 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %2
store i32 0, i32* %3
br label %13
13: ; preds = %32, %10
%14 = load i32, i32* %3
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %35
17: ; preds = %13
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %5, i64 0, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = sub nsw i32 %22, 48
%24 = load i32, i32* %2
%25 = load i32, i32* %3
%26 = sub nsw i32 %24, %25
%27 = call i32 @mi(i32 %26)
%28 = sub nsw i32 %27, 1
%29 = mul nsw i32 %23, %28
%30 = load i32, i32* %4
%31 = add nsw i32 %30, %29
store i32 %31, i32* %4
br label %32
32: ; preds = %17
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
br label %13
35: ; preds = %13
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %35
store i32 0, i32* %1
br label %43
39: ; preds = %35
%40 = load i32, i32* %4
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %40)
br label %6
42: ; preds = %6
store i32 0, i32* %1
br label %43
43: ; preds = %42, %38
%44 = load i32, i32* %1
ret i32 %44
}

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