#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 */
scalar_t__ gets(char *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main() {
  int i, len, r, sum;
  char s[1020];
  while (gets(s)) {
    r = 0;
    if (s[0] == '0' && s[1] == '\0')
      break;
    len = strlen(s);
    for (i = 0; i < len; i++) {
      sum = r * 10 + (s[i] - '0');
      r = sum % 17;
      printf("%d %d\n", sum, r);
    }
    if (r == 0)
      printf("1\n");
    else
      printf("0\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <gets@plt>
cmp    $0x0,%rax
je     121e <main+0xee>
movl   $0x0,-0x10(%rbp)
movsbl -0x410(%rbp),%eax
cmp    $0x30,%eax
jne    1184 <main+0x54>
movsbl -0x40f(%rbp),%eax
cmp    $0x0,%eax
jne    1184 <main+0x54>
jmp    121e <main+0xee>
lea    -0x410(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ee <main+0xbe>
imul   $0xa,-0x10(%rbp),%eax
movslq -0x8(%rbp),%rcx
movsbl -0x410(%rbp,%rcx,1),%ecx
ff
sub    $0x30,%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x11,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x14(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    119a <main+0x6a>
cmpl   $0x0,-0x10(%rbp)
jne    120b <main+0xdb>
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1219 <main+0xe9>
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1142 <main+0x12>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     1217 <main+0xd7>
mov    %rsp,%r14
lea    0xe9d(%rip),%r12
lea    0xe8d(%rip),%r15
jmp    1196 <main+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <puts@plt>
mov    %r14,%rdi
call   1060 <gets@plt>
test   %rax,%rax
je     1217 <main+0xd7>
cmpb   $0x30,(%rsp)
jne    11a3 <main+0x63>
cmpb   $0x0,0x1(%rsp)
je     1217 <main+0xd7>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r12,%rdi
test   %eax,%eax
jle    1180 <main+0x40>
mov    %eax,%ebp
xor    %r13d,%r13d
xor    %ebx,%ebx
nopl   0x0(%rax)
lea    (%rbx,%rbx,4),%eax
movsbl (%rsp,%r13,1),%ecx
lea    (%rcx,%rax,2),%eax
add    $0xffffffd0,%eax
movslq %eax,%rsi
imul   $0x78787879,%rsi,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x23,%rax
add    %ecx,%eax
mov    %eax,%ecx
shl    $0x4,%ecx
add    %eax,%ecx
mov    %esi,%ebx
sub    %ecx,%ebx
mov    %r15,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%r13
cmp    %r13,%rbp
jne    11c0 <main+0x80>
test   %ebx,%ebx
lea    0xdf9(%rip),%rdi
cmove  %r12,%rdi
jmp    1180 <main+0x40>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%d %d\0A\00"
@str = [2 x i8] c"0\00"
@str.3 = [2 x i8] c"1\00"
define i32 @main() {
%1 = alloca [1020 x i8]
%2 = getelementptr inbounds [1020 x i8], [1020 x i8]* %1, i64 0, i64 0
%3 = call i64 @gets(i8* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %39, label %5
5: ; preds = %0
%6 = getelementptr inbounds [1020 x i8], [1020 x i8]* %1, i64 0, i64 1
br label %7
7: ; preds = %5, %34
%8 = load i8, i8* %2
%9 = icmp eq i8 %8, 48
%10 = load i8, i8* %6
%11 = icmp eq i8 %10, 0
%12 = select i1 %9, i1 %11, i1 false
br i1 %12, label %39, label %13
13: ; preds = %7
%14 = call i32 @strlen(i8* %2)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = zext i32 %14 to i64
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %29, %18 ]
%20 = phi i32 [ 0, %16 ], [ %27, %18 ]
%21 = mul nsw i32 %20, 10
%22 = getelementptr inbounds [1020 x i8], [1020 x i8]* %1, i64 0, i64 %19
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = add nsw i32 %21, -48
%26 = add nsw i32 %25, %24
%27 = srem i32 %26, 17
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %27)
%29 = add nuw nsw i64 %19, 1
%30 = icmp eq i64 %29, %17
br i1 %30, label %31, label %18
31: ; preds = %18
%32 = icmp eq i32 %27, 0
%33 = select i1 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0)
br label %34
34: ; preds = %31, %13
%35 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0), %13 ], [ %33, %31 ]
%36 = call i32 @puts(i8* dereferenceable(1) %35)
%37 = call i64 @gets(i8* %2)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %7
39: ; preds = %34, %7, %0
ret i32 0
}