#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 */
typedef long long uint64_t;

/* Variables and functions */
long long next_code(long long);
int /*<<< orphan*/ printf(char *, int, int, long long);
int main() {
  uint64_t first_code = 20151125LL;
  int row = 1;
  int col = 1;
  while (row != 2947 || col != 3029) {
    first_code = next_code(first_code);
    if (row == 1) {
      row = col + 1;
      col = 1;
    } else {
      row--;
      col++;
    }
  }
  printf("%d %d %llu\n", row, col, first_code);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x1337b55,-0x10(%rbp)
01
movl   $0x1,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x1,%al
cmpl   $0xb83,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jne    1164 <main+0x44>
cmpl   $0xbd5,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1174 <main+0x54>
jmp    11b7 <main+0x97>
mov    -0x10(%rbp),%rdi
call   1040 <next_code@plt>
mov    %rax,-0x10(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    11a0 <main+0x80>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
jmp    11b2 <main+0x92>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <main+0x25>
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    $0x1337b55,%eax
mov    $0x1,%ebp
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ecx,%ebx
mov    %rax,%rdi
call   1040 <next_code@plt>
add    $0x1,%ebp
lea    -0x1(%rbx),%ecx
cmp    $0x1,%ebx
cmove  %ebp,%ecx
cmove  %ebx,%ebp
cmp    $0xb83,%ecx
jne    1140 <main+0x20>
cmp    $0xbd5,%ebp
jne    1140 <main+0x20>
lea    0xe90(%rip),%rdi
mov    $0xb83,%esi
mov    $0xbd5,%edx
mov    %rax,%rcx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d %d %llu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i64 20151125, i64* %2
store i32 1, i32* %3
store i32 1, i32* %4
br label %5
5: ; preds = %26, %0
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 2947
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3029
br label %11
11: ; preds = %8, %5
%12 = phi i1 [ true, %5 ], [ %10, %8 ]
br i1 %12, label %13, label %27
13: ; preds = %11
%14 = load i64, i64* %2
%15 = call i64 @next_code(i64 %14)
store i64 %15, i64* %2
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %3
store i32 1, i32* %4
br label %26
21: ; preds = %13
%22 = load i32, i32* %3
%23 = add nsw i32 %22, -1
store i32 %23, i32* %3
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %26
26: ; preds = %21, %18
br label %5
27: ; preds = %11
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = load i64, i64* %2
%31 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29, i64 %30)
%32 = load i32, i32* %1
ret i32 %32
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d %d %llu\0A\00"
define i32 @main() {
br label %1
1: ; preds = %0, %1
%2 = phi i32 [ 1, %0 ], [ %10, %1 ]
%3 = phi i32 [ 1, %0 ], [ %9, %1 ]
%4 = phi i64 [ 20151125, %0 ], [ %5, %1 ]
%5 = tail call i64 @next_code(i64 %4)
%6 = icmp eq i32 %3, 1
%7 = add nsw i32 %2, 1
%8 = add nsw i32 %3, -1
%9 = select i1 %6, i32 %7, i32 %8
%10 = select i1 %6, i32 1, i32 %7
%11 = icmp ne i32 %9, 2947
%12 = icmp ne i32 %10, 3029
%13 = select i1 %11, i1 true, i1 %12
br i1 %13, label %1, label %14
14: ; preds = %1
%15 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 2947, i32 3029, i64 %5)
ret i32 0
}