#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 findNext(int *, int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int main(int argc, char *argv[]) {
  int seq[9];
  char str[9];
  int i = 0;
  scanf("%s", str);
  while (!(str[0] == '0' && str[1] == '\0')) {
    i = -1;
    while (str[++i] != '\0')
      seq[i] = str[i] - '0';
    printf("%d\n", findNext(seq, i));
    scanf("%s", str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x50(%rbp)
lea    -0x49(%rbp),%rsi
lea    0xea8(%rip),%rdi
call   1040 <scanf@plt>
movsbl -0x49(%rbp),%ecx
xor    %eax,%eax
cmp    $0x30,%ecx
mov    %al,-0x51(%rbp)
jne    117c <main+0x4c>
movsbl -0x48(%rbp),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x51(%rbp)
mov    -0x51(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    118e <main+0x5e>
jmp    11f6 <main+0xc6>
movl   $0xffffffff,-0x50(%rbp)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
cltq
movsbl -0x49(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11c7 <main+0x97>
movslq -0x50(%rbp),%rax
movsbl -0x49(%rbp,%rax,1),%ecx
sub    $0x30,%ecx
movslq -0x50(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
jmp    1195 <main+0x65>
lea    -0x40(%rbp),%rdi
mov    -0x50(%rbp),%esi
call   1050 <findNext@plt>
mov    %eax,%esi
lea    0xe27(%rip),%rdi
call   1030 <printf@plt>
lea    -0x49(%rbp),%rsi
lea    0xe14(%rip),%rdi
call   1040 <scanf@plt>
jmp    115d <main+0x2d>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x38,%rsp
lea    0xebe(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x7(%rsp),%al
cmp    $0x30,%al
jne    115b <main+0x2b>
cmpb   $0x0,0x8(%rsp)
je     11d3 <main+0xa3>
lea    0x10(%rsp),%r14
lea    0xe9c(%rip),%r15
lea    0xe92(%rip),%r12
lea    0x7(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x0,%esi
test   %al,%al
je     11a7 <main+0x77>
xor    %esi,%esi
nopl   0x0(%rax,%rax,1)
movsbl %al,%eax
add    $0xffffffd0,%eax
mov    %eax,0x10(%rsp,%rsi,4)
movzbl 0x8(%rsp,%rsi,1),%eax
add    $0x1,%rsi
test   %al,%al
jne    1190 <main+0x60>
mov    %r14,%rdi
call   1050 <findNext@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
mov    0x7(%rsp),%al
cmp    $0x30,%al
jne    1180 <main+0x50>
cmpb   $0x0,0x8(%rsp)
jne    1180 <main+0x50>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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