#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 getchar();
int /*<<< orphan*/ printf(char *, int);
int putchar(int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int t, a, c;
  scanf("%d ", &t);
  while (t--) {
    for (a = 420; (c = getchar()) > 42; a += 48 - putchar(c))
      ;
    printf("%d\n", a % 10);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11cc <main+0x8c>
movl   $0x1a4,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x2a,%eax
jle    11ae <main+0x6e>
jmp    1192 <main+0x52>
mov    -0x10(%rbp),%edi
call   1030 <putchar@plt>
mov    %eax,%ecx
mov    $0x30,%eax
sub    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    117a <main+0x3a>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
lea    0xe42(%rip),%rdi
call   1040 <printf@plt>
jmp    115f <main+0x1f>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xeb6(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
subl   $0x1,0x4(%rsp)
jae    1164 <main+0x24>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe99(%rip),%rbx
jmp    119d <main+0x5d>
nopl   (%rax)
movslq %ebp,%rsi
imul   $0x66666667,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%esi
mov    %rbx,%rdi
call   1040 <printf@plt>
subl   $0x1,0x4(%rsp)
jb     115b <main+0x1b>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0x1a4,%ebp
cmp    $0x2b,%eax
jl     1170 <main+0x30>
mov    $0x1a4,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
sub    %eax,%ebp
add    $0x30,%ebp
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x2a,%eax
jg     11c0 <main+0x80>
jmp    1170 <main+0x30>

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

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