#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__ EOF;
int /*<<< orphan*/ free(int *);
int *hop(int *);
scalar_t__ is_in_bound(int *, int, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ realloc(int *, int);
scalar_t__ scanf(char *, int *);
int main() {
  int size = 0;
  int *arr = (int *)malloc(sizeof(int));
  while (scanf("%d", &arr[size]) != EOF) {
    arr = (int *)realloc(arr, sizeof(int) * (++size + 1));
  }
  int *ptr = &arr[0], hops = 0;
  while (is_in_bound(arr, size, ptr) && ++hops < 50) {
    if (*ptr == 0) {
      printf("1\n%d", hops - 1);
      free(arr);
      return 0;
    }
    ptr = hop(ptr);
  }
  printf("0\n%d", is_in_bound(arr, size, ptr) ? 50 : hops - 1);
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe5d(%rip),%rdi
call   1080 <scanf@plt>
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
je     11e5 <main+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%esi
call   1070 <realloc@plt>
mov    %rax,-0x10(%rbp)
jmp    1194 <main+0x24>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1090 <is_in_bound@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
je     1228 <main+0xb8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x32,%eax
setl   %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1238 <main+0xc8>
jmp    127e <main+0x10e>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    126c <main+0xfc>
mov    -0x1c(%rbp),%esi
sub    $0x1,%esi
lea    0xdae(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cd <main+0x15d>
mov    -0x18(%rbp),%rdi
call   1040 <hop@plt>
mov    %rax,-0x18(%rbp)
jmp    11f4 <main+0x84>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1090 <is_in_bound@plt>
cmp    $0x0,%rax
je     12a5 <main+0x135>
mov    $0x32,%eax
mov    %eax,-0x24(%rbp)
jmp    12ae <main+0x13e>
mov    -0x1c(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd4d(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
lea    0xe78(%rip),%rdi
mov    %rax,%rsi
call   1080 <scanf@plt>
mov    0x2e4a(%rip),%r12
xor    %r14d,%r14d
mov    $0x0,%r13d
cmp    (%r12),%rax
je     11f0 <main+0x80>
mov    $0x4,%ebx
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x4(%rbx),%rbp
mov    %r15,%rdi
mov    %ebp,%esi
call   1070 <realloc@plt>
mov    %rax,%r15
add    %rax,%rbx
lea    0xe2c(%rip),%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
add    $0x1,%r13d
mov    %rbp,%rbx
cmp    (%r12),%rax
jne    11c0 <main+0x50>
mov    %r15,%rdi
mov    %r13d,%esi
mov    %r15,%rdx
call   1090 <is_in_bound@plt>
mov    %r15,%rbx
test   %rax,%rax
je     1245 <main+0xd5>
xor    %r14d,%r14d
mov    %r15,%rbx
nopl   0x0(%rax)
cmp    $0x31,%r14d
je     123f <main+0xcf>
cmpl   $0x0,(%rbx)
je     126c <main+0xfc>
mov    %rbx,%rdi
call   1040 <hop@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r13d,%esi
mov    %rax,%rdx
call   1090 <is_in_bound@plt>
add    $0x1,%r14d
test   %rax,%rax
jne    1210 <main+0xa0>
jmp    1245 <main+0xd5>
mov    $0x32,%r14d
mov    %r15,%rdi
mov    %r13d,%esi
mov    %rbx,%rdx
call   1090 <is_in_bound@plt>
add    $0xffffffff,%r14d
test   %rax,%rax
mov    $0x32,%esi
cmove  %r14d,%esi
lea    0xd9b(%rip),%rdi
jmp    1276 <main+0x106>
lea    0xd8d(%rip),%rdi
mov    %r14d,%esi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"1\0A%d\00"
@.str.2 = [5 x i8] c"0\0A%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i64 @malloc(i32 4)
%7 = inttoptr i64 %6 to i32*
store i32* %7, i32** %3
br label %8
8: ; preds = %16, %0
%9 = load i32*, i32** %3
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i32, i32* %9, i64 %11
%13 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %12)
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %8
%17 = load i32*, i32** %3
%18 = load i32, i32* %2
%19 = add nsw i32 %18, 1
store i32 %19, i32* %2
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = mul i64 4, %21
%23 = trunc i64 %22 to i32
%24 = call i64 @realloc(i32* %17, i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %3
br label %8
26: ; preds = %8
%27 = load i32*, i32** %3
%28 = getelementptr inbounds i32, i32* %27, i64 0
store i32* %28, i32** %4
store i32 0, i32* %5
br label %29
29: ; preds = %51, %26
%30 = load i32*, i32** %3
%31 = load i32, i32* %2
%32 = load i32*, i32** %4
%33 = call i64 @is_in_bound(i32* %30, i32 %31, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
%38 = icmp slt i32 %37, 50
br label %39
39: ; preds = %35, %29
%40 = phi i1 [ false, %29 ], [ %38, %35 ]
br i1 %40, label %41, label %54
41: ; preds = %39
%42 = load i32*, i32** %4
%43 = load i32, i32* %42
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %51
45: ; preds = %41
%46 = load i32, i32* %5
%47 = sub nsw i32 %46, 1
%48 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %47)
%49 = load i32*, i32** %3
%50 = call i32 @free(i32* %49)
store i32 0, i32* %1
br label %69
51: ; preds = %41
%52 = load i32*, i32** %4
%53 = call i32* @hop(i32* %52)
store i32* %53, i32** %4
br label %29
54: ; preds = %39
%55 = load i32*, i32** %3
%56 = load i32, i32* %2
%57 = load i32*, i32** %4
%58 = call i64 @is_in_bound(i32* %55, i32 %56, i32* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %54
br label %64
61: ; preds = %54
%62 = load i32, i32* %5
%63 = sub nsw i32 %62, 1
br label %64
64: ; preds = %61, %60
%65 = phi i32 [ 50, %60 ], [ %63, %61 ]
%66 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %65)
%67 = load i32*, i32** %3
%68 = call i32 @free(i32* %67)
store i32 0, i32* %1
br label %69
69: ; preds = %64, %45
%70 = load i32, i32* %1
ret i32 %70
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c"1\0A%d\00"
@.str.2 = [5 x i8] c"0\0A%d\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 4)
%2 = inttoptr i64 %1 to i32*
%3 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%4 = load i64, i64* @EOF
%5 = icmp eq i64 %3, %4
br i1 %5, label %9, label %14
6: ; preds = %14
%7 = inttoptr i64 %21 to i32*
%8 = trunc i64 %17 to i32
br label %9
9: ; preds = %6, %0
%10 = phi i32* [ %7, %6 ], [ %2, %0 ]
%11 = phi i32 [ %8, %6 ], [ 0, %0 ]
%12 = tail call i64 @is_in_bound(i32* %10, i32 %11, i32* %10)
%13 = icmp eq i64 %12, 0
br i1 %13, label %41, label %27
14: ; preds = %0, %14
%15 = phi i64 [ %17, %14 ], [ 0, %0 ]
%16 = phi i32* [ %22, %14 ], [ %2, %0 ]
%17 = add nuw i64 %15, 1
%18 = trunc i64 %15 to i32
%19 = shl i32 %18, 2
%20 = add i32 %19, 8
%21 = tail call i64 @realloc(i32* %16, i32 %20)
%22 = inttoptr i64 %21 to i32*
%23 = getelementptr inbounds i32, i32* %22, i64 %17
%24 = tail call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %23)
%25 = load i64, i64* @EOF
%26 = icmp eq i64 %24, %25
br i1 %26, label %6, label %14
27: ; preds = %9, %37
%28 = phi i32 [ %30, %37 ], [ 0, %9 ]
%29 = phi i32* [ %38, %37 ], [ %10, %9 ]
%30 = add nuw nsw i32 %28, 1
%31 = icmp eq i32 %28, 49
br i1 %31, label %41, label %32
32: ; preds = %27
%33 = load i32, i32* %29
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %49
37: ; preds = %32
%38 = tail call i32* @hop(i32* %29)
%39 = tail call i64 @is_in_bound(i32* %10, i32 %11, i32* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %27
41: ; preds = %27, %37, %9
%42 = phi i32* [ %10, %9 ], [ %29, %27 ], [ %38, %37 ]
%43 = phi i32 [ 0, %9 ], [ 50, %27 ], [ %30, %37 ]
%44 = tail call i64 @is_in_bound(i32* %10, i32 %11, i32* %42)
%45 = icmp eq i64 %44, 0
%46 = add nsw i32 %43, -1
%47 = select i1 %45, i32 %46, i32 50
%48 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %47)
br label %49
49: ; preds = %41, %35
%50 = tail call i32 @free(i32* %10)
ret i32 0
}