#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*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, long *);
int main() {
  long number;
  scanf("%ld", &number);
  int sum = 0;
  int next = 3;
  while (number) {
    int digit = number % 10;
    number /= 10;
    sum += digit * next;
    next = next == 3 ? 1 : 3;
  }
  int checksumDigit = (sum / 10 + 1) * 10 - sum;
  printf("%d\n", checksumDigit);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x3,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11a5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %edx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    $0xa,%ecx
cqto
idiv   %rcx
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
imul   -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x3,%eax
mov    $0x1,%ecx
cmp    $0x3,%edx
cmove  %ecx,%eax
mov    %eax,-0x18(%rbp)
jmp    114d <main+0x2d>
mov    -0x14(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
imul   $0xa,%eax,%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xed8(%rip),%rdi
mov    %rsp,%rsi
call   1040 <scanf@plt>
mov    (%rsp),%rdx
test   %rdx,%rdx
je     11b7 <main+0x97>
mov    $0x3,%edi
xor    %esi,%esi
movabs $0x6666666666666667,%r8
66 66 66
nopw   0x0(%rax,%rax,1)
mov    %rdx,%rcx
mov    %rdx,%rax
imul   %r8
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
lea    (%rdx,%rdx,1),%eax
lea    (%rax,%rax,4),%r9d
mov    %ecx,%eax
sub    %r9d,%eax
imul   %edi,%eax
add    %eax,%esi
xor    %eax,%eax
cmp    $0x3,%edi
setne  %al
lea    (%rax,%rax,1),%edi
add    $0x1,%edi
add    $0x9,%rcx
cmp    $0x12,%rcx
ja     1150 <main+0x30>
mov    %rdx,(%rsp)
movslq %esi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%esi
sub    %eax,%esi
add    $0xa,%esi
jmp    11bc <main+0x9c>
mov    $0xa,%esi
lea    0xe41(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

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

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