#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ FLineStdin();
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int);
int isTidy(int, int /*<<< orphan*/);
int /*<<< orphan*/ numDigits(int);
int strtoi(int /*<<< orphan*/);
int main(void) {
  int iter = strtoi(FLineStdin());
  int Case;
  FILE *fWrite = fopen("tidyNumbers.out", "w");
  for (Case = 0; Case < iter; Case++) {
    int num = strtoi(FLineStdin());
    int i = 0;
    while (isTidy(num - i, numDigits(num - i)) != 1) {
      i++;
    }
    fprintf(fWrite, "Case #%d: %d\n", Case + 1, num - i);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <FLineStdin@plt>
mov    %eax,%edi
call   1050 <strtoi@plt>
mov    %eax,-0x8(%rbp)
lea    0xe79(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1221 <main+0xc1>
mov    $0x0,%al
call   1030 <FLineStdin@plt>
mov    %eax,%edi
call   1050 <strtoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
sub    -0x20(%rbp),%edi
call   1070 <numDigits@plt>
mov    -0x24(%rbp),%edi
mov    %eax,%esi
call   1040 <isTidy@plt>
cmp    $0x1,%eax
je     11f7 <main+0x97>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11c2 <main+0x62>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
lea    0xe04(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119e <main+0x3e>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1030 <FLineStdin@plt>
mov    %eax,%edi
call   1050 <strtoi@plt>
mov    %eax,%r15d
lea    0xe80(%rip),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
test   %r15d,%r15d
jle    11e2 <main+0x82>
mov    %rax,%r12
lea    0xe77(%rip),%r14
xor    %ebp,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1030 <FLineStdin@plt>
mov    %eax,%edi
call   1050 <strtoi@plt>
mov    %eax,%ebx
mov    %ebx,%edi
call   1070 <numDigits@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1040 <isTidy@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%eax
jne    11b0 <main+0x50>
add    $0x1,%ebp
add    $0x1,%ebx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1060 <fprintf@plt>
cmp    %r15d,%ebp
jne    11a0 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"tidyNumbers.out\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"Case #%d: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @FLineStdin()
%8 = call i32 @strtoi(i32 %7)
store i32 %8, i32* %2
%9 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
store i32 0, i32* %3
br label %10
10: ; preds = %38, %0
%11 = load i32, i32* %3
%12 = load i32, i32* %2
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %41
14: ; preds = %10
%15 = call i32 (...) @FLineStdin()
%16 = call i32 @strtoi(i32 %15)
store i32 %16, i32* %5
store i32 0, i32* %6
br label %17
17: ; preds = %27, %14
%18 = load i32, i32* %5
%19 = load i32, i32* %6
%20 = sub nsw i32 %18, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %6
%23 = sub nsw i32 %21, %22
%24 = call i32 @numDigits(i32 %23)
%25 = call i32 @isTidy(i32 %20, i32 %24)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %17
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %17
30: ; preds = %17
%31 = load i32*, i32** %4
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %5
%35 = load i32, i32* %6
%36 = sub nsw i32 %34, %35
%37 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %36)
br label %38
38: ; preds = %30
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %10
41: ; preds = %10
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [16 x i8] c"tidyNumbers.out\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"Case #%d: %d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @FLineStdin()
%2 = tail call i32 @strtoi(i32 %1)
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %20
5: ; preds = %0, %16
%6 = phi i32 [ %17, %16 ], [ 0, %0 ]
%7 = tail call i32 (...) @FLineStdin()
%8 = tail call i32 @strtoi(i32 %7)
br label %9
9: ; preds = %9, %5
%10 = phi i32 [ 0, %5 ], [ %15, %9 ]
%11 = sub nsw i32 %8, %10
%12 = tail call i32 @numDigits(i32 %11)
%13 = tail call i32 @isTidy(i32 %11, i32 %12)
%14 = icmp eq i32 %13, 1
%15 = add nuw nsw i32 %10, 1
br i1 %14, label %16, label %9
16: ; preds = %9
%17 = add nuw nsw i32 %6, 1
%18 = tail call i32 @fprintf(i32* %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %11)
%19 = icmp eq i32 %17, %2
br i1 %19, label %20, label %5
20: ; preds = %16, %0
ret i32 0
}