#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 Digits(long long);
long long Spsum(int /*<<< orphan*/, long long, int);
int /*<<< orphan*/ pow(int, int);
long long presum(int);
int /*<<< orphan*/ printf(char *, long long);
int /*<<< orphan*/ scanf(char *, long long *);
int main() {
  long long int arr[40];
  int t, i;
  int d;
  long long int s = 0, a;
  for (t = 0;; t++) {
    scanf("%lld", &arr[t]);
    if (arr[t] == 0)
      break;
  }
  for (i = 0; i < t; i++) {
    s = 0;
    a = arr[i];
    d = Digits(a);
    s = s + presum(d - 1);
    if (d == 11)
      s = s * -1;
    s = s + Spsum(pow(10, d - 1), a, d);
    printf("%lld\n", s);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x168(%rbp)
movl   $0x0,-0x154(%rbp)
movslq -0x154(%rbp),%rax
lea    -0x150(%rbp),%rsi
shl    $0x3,%rax
add    %rax,%rsi
lea    0xe5d(%rip),%rdi
call   1070 <scanf@plt>
movslq -0x154(%rbp),%rax
cmpq   $0x0,-0x150(%rbp,%rax,8)
jne    11c3 <main+0x63>
jmp    11dc <main+0x7c>
jmp    11c8 <main+0x68>
mov    -0x154(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x154(%rbp)
jmp    1187 <main+0x27>
movl   $0x0,-0x158(%rbp)
mov    -0x158(%rbp),%eax
cmp    -0x154(%rbp),%eax
jge    12e7 <main+0x187>
movq   $0x0,-0x168(%rbp)
movslq -0x158(%rbp),%rax
mov    -0x150(%rbp,%rax,8),%rax
ff
mov    %rax,-0x170(%rbp)
mov    -0x170(%rbp),%rdi
call   1040 <Digits@plt>
mov    %eax,-0x15c(%rbp)
mov    -0x168(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x15c(%rbp),%edi
sub    $0x1,%edi
call   1060 <presum@plt>
mov    %rax,%rcx
mov    -0x178(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x168(%rbp)
cmpl   $0xb,-0x15c(%rbp)
jne    1277 <main+0x117>
imul   $0xffffffffffffffff,-0x168(%rbp),%rax
ff
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x15c(%rbp),%esi
sub    $0x1,%esi
mov    $0xa,%edi
call   1080 <pow@plt>
mov    %eax,%edi
mov    -0x170(%rbp),%rsi
mov    -0x15c(%rbp),%edx
call   1030 <Spsum@plt>
mov    %rax,%rcx
mov    -0x180(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x168(%rbp)
mov    -0x168(%rbp),%rsi
lea    0xd37(%rip),%rdi
call   1050 <printf@plt>
mov    -0x158(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x158(%rbp)
jmp    11e6 <main+0x86>
xor    %eax,%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    $0xffffffff,%ebp
mov    %rsp,%rbx
lea    0xe80(%rip),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%ebp
cmpq   $0x0,(%rbx)
lea    0x8(%rbx),%rbx
jne    1180 <main+0x20>
test   %ebp,%ebp
je     120b <main+0xab>
mov    %ebp,%r13d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp,%r14,8),%r15
mov    %r15,%rdi
call   1040 <Digits@plt>
mov    %eax,%ebx
lea    -0x1(%rbx),%r12d
mov    %r12d,%edi
call   1060 <presum@plt>
mov    %rax,%rbp
neg    %rbp
cmp    $0xb,%ebx
cmovne %rax,%rbp
mov    $0xa,%edi
mov    %r12d,%esi
call   1080 <pow@plt>
mov    %eax,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <Spsum@plt>
add    %rax,%rbp
lea    0xe0b(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    11b0 <main+0x50>
xor    %eax,%eax
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [40 x i64]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %6
store i32 0, i32* %3
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [40 x i64], [40 x i64]* %2, i64 0, i64 %10
%12 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %11)
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [40 x i64], [40 x i64]* %2, i64 0, i64 %14
%16 = load i64, i64* %15
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %8
br label %23
19: ; preds = %8
br label %20
20: ; preds = %19
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %8
23: ; preds = %18
store i32 0, i32* %4
br label %24
24: ; preds = %56, %23
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %59
28: ; preds = %24
store i64 0, i64* %6
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [40 x i64], [40 x i64]* %2, i64 0, i64 %30
%32 = load i64, i64* %31
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = call i32 @Digits(i64 %33)
store i32 %34, i32* %5
%35 = load i64, i64* %6
%36 = load i32, i32* %5
%37 = sub nsw i32 %36, 1
%38 = call i64 @presum(i32 %37)
%39 = add nsw i64 %35, %38
store i64 %39, i64* %6
%40 = load i32, i32* %5
%41 = icmp eq i32 %40, 11
br i1 %41, label %42, label %45
42: ; preds = %28
%43 = load i64, i64* %6
%44 = mul nsw i64 %43, -1
store i64 %44, i64* %6
br label %45
45: ; preds = %42, %28
%46 = load i64, i64* %6
%47 = load i32, i32* %5
%48 = sub nsw i32 %47, 1
%49 = call i32 @pow(i32 10, i32 %48)
%50 = load i64, i64* %7
%51 = load i32, i32* %5
%52 = call i64 @Spsum(i32 %49, i64 %50, i32 %51)
%53 = add nsw i64 %46, %52
store i64 %53, i64* %6
%54 = load i64, i64* %6
%55 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %54)
br label %56
56: ; preds = %45
%57 = load i32, i32* %4
%58 = add nsw i32 %57, 1
store i32 %58, i32* %4
br label %24
59: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"%lld\00"
@.str.1 = [6 x i8] c"%lld\0A\00"
define i32 @main() {
%1 = alloca [40 x i64]
%2 = bitcast [40 x i64]* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = phi i64 [ %9, %3 ], [ 0, %0 ]
%5 = getelementptr inbounds [40 x i64], [40 x i64]* %1, i64 0, i64 %4
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %5)
%7 = load i64, i64* %5
%8 = icmp eq i64 %7, 0
%9 = add nuw i64 %4, 1
br i1 %8, label %10, label %3
10: ; preds = %3
%11 = trunc i64 %4 to i32
%12 = icmp eq i32 %11, 0
br i1 %12, label %31, label %13
13: ; preds = %10
%14 = and i64 %4, 4294967295
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %29, %15 ]
%17 = getelementptr inbounds [40 x i64], [40 x i64]* %1, i64 0, i64 %16
%18 = load i64, i64* %17
%19 = call i32 @Digits(i64 %18)
%20 = add nsw i32 %19, -1
%21 = call i64 @presum(i32 %20)
%22 = icmp eq i32 %19, 11
%23 = sub nsw i64 0, %21
%24 = select i1 %22, i64 %23, i64 %21
%25 = call i32 @pow(i32 10, i32 %20)
%26 = call i64 @Spsum(i32 %25, i64 %18, i32 %19)
%27 = add nsw i64 %26, %24
%28 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i64 %27)
%29 = add nuw nsw i64 %16, 1
%30 = icmp eq i64 %29, %14
br i1 %30, label %31, label %15
31: ; preds = %15, %10
ret i32 0
}