#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*/ add(unsigned char *, unsigned char *, unsigned char *,
                       size_t const);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, size_t const);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  const size_t K = 1000;
  unsigned char A[3][K];
  size_t n, x, y, z, i;
  x = 0;
  y = 1;
  z = 2;
  memset(A[x], 0, K);
  memset(A[y], 0, K);
  memset(A[z], 0, K);
  A[x][0] = 1;
  A[y][0] = 1;
  n = 2;
  while (A[y][K - 1] == 0) {
    add(A[x], A[y], A[z], K);
    x = (x + 1) % 3;
    y = (y + 1) % 3;
    z = (z + 1) % 3;
    n += 1;
  }
  printf("n=%zu\n", n);
  if (0) {
    for (i = 0; i < K; ++i) {
      printf("%u", A[y][K - 1 - i]);
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc00,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x3e8,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x1,-0x30(%rbp)
movq   $0x2,-0x38(%rbp)
imul   $0x3e8,-0x28(%rbp),%rax
lea    -0xc00(%rbp),%rdi
add    %rax,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
imul   $0x3e8,-0x30(%rbp),%rax
lea    -0xc00(%rbp),%rdi
add    %rax,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
imul   $0x3e8,-0x38(%rbp),%rax
lea    -0xc00(%rbp),%rdi
add    %rax,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
imul   $0x3e8,-0x28(%rbp),%rax
movb   $0x1,-0xc00(%rbp,%rax,1)
01
imul   $0x3e8,-0x30(%rbp),%rax
movb   $0x1,-0xc00(%rbp,%rax,1)
01
movq   $0x2,-0x20(%rbp)
imul   $0x3e8,-0x30(%rbp),%rax
movzbl -0x819(%rbp,%rax,1),%eax
ff
cmp    $0x0,%eax
jne    1297 <main+0x167>
imul   $0x3e8,-0x28(%rbp),%rax
lea    -0xc00(%rbp),%rdi
add    %rax,%rdi
imul   $0x3e8,-0x30(%rbp),%rax
lea    -0xc00(%rbp),%rsi
add    %rax,%rsi
imul   $0x3e8,-0x38(%rbp),%rax
lea    -0xc00(%rbp),%rdx
add    %rax,%rdx
mov    $0x3e8,%ecx
call   1030 <add@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    $0x3,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,-0x38(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11eb <main+0xbb>
mov    -0x20(%rbp),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
add    $0xc00,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xbb8,%rsp
mov    %rsp,%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x3e8(%rsp),%r14
mov    $0x3e8,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x7d0(%rsp),%rdi
mov    $0x3e8,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movb   $0x1,(%rsp)
movb   $0x1,0x3e8(%rsp)
01
mov    $0x2,%r15d
cmpb   $0x0,0x7cf(%rsp)
jne    1239 <main+0x109>
mov    $0x1,%r12d
mov    $0x2,%r13d
xor    %ebx,%ebx
mov    $0xaaaaaaab,%ebp
mov    $0x2,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
imul   $0x3e8,%rbx,%rax
lea    (%rsp,%rax,1),%rdi
imul   $0x3e8,%r13,%rax
lea    (%rsp,%rax,1),%rdx
mov    $0x3e8,%ecx
mov    %r14,%rsi
call   1030 <add@plt>
add    $0x1,%rbx
mov    %ebx,%eax
imul   %rbp,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
sub    %eax,%ebx
add    $0x1,%r12
mov    %r12d,%eax
imul   %rbp,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
sub    %eax,%r12d
add    $0x1,%r13
mov    %r13d,%eax
imul   %rbp,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
sub    %eax,%r13d
add    $0x1,%r15
imul   $0x3e8,%r12,%rax
lea    (%rsp,%rax,1),%r14
cmpb   $0x0,0x3e7(%rsp,%rax,1)
je     11c0 <main+0x90>
lea    0xdc0(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xbb8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"n=%zu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32 0, i32* %1
store i64 1000, i64* %2
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 3000
store i64 0, i64* %5
store i64 1, i64* %6
store i64 2, i64* %7
%11 = load i64, i64* %5
%12 = mul nsw i64 %11, 1000
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = call i32 @memset(i8* %13, i32 0, i64 1000)
%15 = load i64, i64* %6
%16 = mul nsw i64 %15, 1000
%17 = getelementptr inbounds i8, i8* %10, i64 %16
%18 = call i32 @memset(i8* %17, i32 0, i64 1000)
%19 = load i64, i64* %7
%20 = mul nsw i64 %19, 1000
%21 = getelementptr inbounds i8, i8* %10, i64 %20
%22 = call i32 @memset(i8* %21, i32 0, i64 1000)
%23 = load i64, i64* %5
%24 = mul nsw i64 %23, 1000
%25 = getelementptr inbounds i8, i8* %10, i64 %24
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 1, i8* %26
%27 = load i64, i64* %6
%28 = mul nsw i64 %27, 1000
%29 = getelementptr inbounds i8, i8* %10, i64 %28
%30 = getelementptr inbounds i8, i8* %29, i64 0
store i8 1, i8* %30
store i64 2, i64* %4
br label %31
31: ; preds = %39, %0
%32 = load i64, i64* %6
%33 = mul nsw i64 %32, 1000
%34 = getelementptr inbounds i8, i8* %10, i64 %33
%35 = getelementptr inbounds i8, i8* %34, i64 999
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %39, label %61
39: ; preds = %31
%40 = load i64, i64* %5
%41 = mul nsw i64 %40, 1000
%42 = getelementptr inbounds i8, i8* %10, i64 %41
%43 = load i64, i64* %6
%44 = mul nsw i64 %43, 1000
%45 = getelementptr inbounds i8, i8* %10, i64 %44
%46 = load i64, i64* %7
%47 = mul nsw i64 %46, 1000
%48 = getelementptr inbounds i8, i8* %10, i64 %47
%49 = call i32 @add(i8* %42, i8* %45, i8* %48, i64 1000)
%50 = load i64, i64* %5
%51 = add i64 %50, 1
%52 = urem i64 %51, 3
store i64 %52, i64* %5
%53 = load i64, i64* %6
%54 = add i64 %53, 1
%55 = urem i64 %54, 3
store i64 %55, i64* %6
%56 = load i64, i64* %7
%57 = add i64 %56, 1
%58 = urem i64 %57, 3
store i64 %58, i64* %7
%59 = load i64, i64* %4
%60 = add i64 %59, 1
store i64 %60, i64* %4
br label %31
61: ; preds = %31
%62 = load i64, i64* %4
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %62)
store i32 0, i32* %1
%64 = load i8*, i8** %3
%65 = load i32, i32* %1
ret i32 %65
}

LLVM IR (-O2):
@.str = [7 x i8] c"n=%zu\0A\00"
define i32 @main() {
%1 = alloca [3000 x i8]
%2 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 0
%3 = call i32 @memset(i8* %2, i32 0, i64 1000)
%4 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 1000
%5 = call i32 @memset(i8* %4, i32 0, i64 1000)
%6 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 2000
%7 = call i32 @memset(i8* %6, i32 0, i64 1000)
store i8 1, i8* %2
store i8 1, i8* %4
%8 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 1999
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %0, %11
%12 = phi i8* [ %30, %11 ], [ %4, %0 ]
%13 = phi i64 [ %27, %11 ], [ 2, %0 ]
%14 = phi i64 [ %25, %11 ], [ 1, %0 ]
%15 = phi i64 [ %23, %11 ], [ 0, %0 ]
%16 = phi i64 [ %28, %11 ], [ 2, %0 ]
%17 = mul nuw nsw i64 %15, 1000
%18 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 %17
%19 = mul nuw nsw i64 %13, 1000
%20 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 %19
%21 = call i32 @add(i8* %18, i8* %12, i8* %20, i64 1000)
%22 = add nuw nsw i64 %15, 1
%23 = urem i64 %22, 3
%24 = add nuw nsw i64 %14, 1
%25 = urem i64 %24, 3
%26 = add nuw nsw i64 %13, 1
%27 = urem i64 %26, 3
%28 = add i64 %16, 1
%29 = mul nuw nsw i64 %25, 1000
%30 = getelementptr inbounds [3000 x i8], [3000 x i8]* %1, i64 0, i64 %29
%31 = getelementptr inbounds i8, i8* %30, i64 999
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %11, label %34
34: ; preds = %11, %0
%35 = phi i64 [ 2, %0 ], [ %28, %11 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %35)
ret i32 0
}