#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 char int16_t;

/* Variables and functions */
char getchar();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  int16_t n, s, t;
  while ((t = getchar()) != '0') {
    getchar();
    s = 0;
    while ((n = getchar()) != '\n') {
      if (n != t) {
        s += n - '0';
        if (s != 0) {
          printf("%c", n);
        }
      }
    }
    if (s == 0) {
      printf("%d", 0);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x7(%rbp)
movsbl %al,%eax
cmp    $0x30,%eax
je     11df <main+0xbf>
mov    $0x0,%al
call   1040 <getchar@plt>
movb   $0x0,-0x6(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %al,-0x5(%rbp)
movsbl %al,%eax
cmp    $0xa,%eax
je     11af <main+0x8f>
movsbl -0x5(%rbp),%eax
movsbl -0x7(%rbp),%ecx
cmp    %ecx,%eax
je     11aa <main+0x8a>
movsbl -0x5(%rbp),%ecx
sub    $0x30,%ecx
movsbl -0x6(%rbp),%eax
add    %ecx,%eax
mov    %al,-0x6(%rbp)
movsbl -0x6(%rbp),%eax
cmp    $0x0,%eax
je     11a5 <main+0x85>
movsbl -0x5(%rbp),%esi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11aa <main+0x8a>
jmp    1150 <main+0x30>
movsbl -0x6(%rbp),%eax
cmp    $0x0,%eax
jne    11cc <main+0xac>
lea    0xe40(%rip),%rdi
xor    %esi,%esi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    112f <main+0xf>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0x30,%al
jne    1146 <main+0x16>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebx
lea    0xeb1(%rip),%r14
jmp    1183 <main+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
cmp    $0x30,%al
je     113f <main+0xf>
xor    %eax,%eax
call   1050 <getchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     1160 <main+0x30>
xor    %ebp,%ebp
jmp    11b3 <main+0x83>
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%al
je     11d0 <main+0xa0>
cmp    %bl,%al
je     11a8 <main+0x78>
add    %al,%bpl
add    $0xd0,%bpl
jne    11a0 <main+0x70>
xor    %ebp,%ebp
jmp    11a8 <main+0x78>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %bpl,%bpl
jne    116c <main+0x3c>
jmp    1160 <main+0x30>

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

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