#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
char *calloc(int, int);
int chain(int, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, int);
int strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int roof = strtol(argv[1], NULL, 10);
  char *memo = calloc(10 * 1000 * 1000, sizeof(char));
  int counter = 0, i;
  assert(memo != NULL);
  for (i = 1; i < roof; ++i) {
    if (chain(i, memo) == 89)
      ++counter;
  }
  printf("%d\n", counter);
  free(memo);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    $0x989680,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x1,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ff <main+0x9f>
mov    -0x28(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1080 <chain@plt>
cmp    $0x59,%eax
jne    11ec <main+0x8c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f1 <main+0x91>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11c2 <main+0x62>
mov    -0x24(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0xa,%edx
call   1070 <strtol@plt>
mov    %eax,%r15d
mov    $0x1,%ebp
mov    $0x989680,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1060 <assert@plt>
cmp    $0x2,%r15d
jl     11cc <main+0x6c>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %r14,%rsi
call   1080 <chain@plt>
xor    %ecx,%ecx
cmp    $0x59,%eax
sete   %cl
add    %ecx,%ebx
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    11b0 <main+0x50>
lea    0xe2d(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [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 i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @strtol(i8* %12, i32* null, i32 10)
store i32 %13, i32* %6
%14 = call i8* @calloc(i32 10000000, i32 1)
store i8* %14, i8** %7
store i32 0, i32* %8
%15 = load i8*, i8** %7
%16 = icmp ne i8* %15, null
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
store i32 1, i32* %9
br label %19
19: ; preds = %32, %2
%20 = load i32, i32* %9
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load i32, i32* %9
%25 = load i8*, i8** %7
%26 = call i32 @chain(i32 %24, i8* %25)
%27 = icmp eq i32 %26, 89
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %31
31: ; preds = %28, %23
br label %32
32: ; preds = %31
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %19
35: ; preds = %19
%36 = load i32, i32* %8
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @strtol(i8* nocapture %4, i32* null, i32 10)
%6 = tail call dereferenceable_or_null(10000000) i8* @calloc(i32 10000000, i32 1)
%7 = icmp ne i8* %6, null
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp sgt i32 %5, 1
br i1 %10, label %11, label %20
11: ; preds = %2, %11
%12 = phi i32 [ %18, %11 ], [ 1, %2 ]
%13 = phi i32 [ %17, %11 ], [ 0, %2 ]
%14 = tail call i32 @chain(i32 %12, i8* %6)
%15 = icmp eq i32 %14, 89
%16 = zext i1 %15 to i32
%17 = add nuw nsw i32 %13, %16
%18 = add nuw nsw i32 %12, 1
%19 = icmp eq i32 %18, %5
br i1 %19, label %20, label %11
20: ; preds = %11, %2
%21 = phi i32 [ 0, %2 ], [ %17, %11 ]
%22 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = tail call i32 @free(i8* %6)
ret i32 0
}