#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*/ printf(char *);
unsigned long long tile_coordinate_to_serial_64(unsigned int, unsigned int,
                                                unsigned int);
int /*<<< orphan*/ tile_serial_to_coordinate_64(unsigned long long,
                                                unsigned int *, unsigned int *,
                                                unsigned int *);
int test_tile_serial() {
  unsigned c = 0;
  unsigned long long serial;
  unsigned pz, px, py;
  for (unsigned z = 0; z < 22; ++z) {
    for (unsigned x = 0; x < (1 << z); x += 1319) {
      for (unsigned y = 0; y < (1 << z); y += 1421) {
        serial = tile_coordinate_to_serial_64(z, x, y);
        tile_serial_to_coordinate_64(serial, &pz, &px, &py);
        if (px != x || py != y || pz != z) {
          printf("~~~~ failed! ~~~~\n");
          return 0;
        }
        ++c;
      }
    }
  }
  return c;
}


x86 assembly (clang, -O0):
<test_tile_serial>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x16,-0x20(%rbp)
jae    1230 <test_tile_serial+0x100>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jae    121d <test_tile_serial+0xed>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
cmp    %ecx,%eax
jae    1208 <test_tile_serial+0xd8>
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
call   1050 <tile_coordinate_to_serial_64@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <tile_serial_to_coordinate_64@plt>
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    11d7 <test_tile_serial+0xa7>
mov    -0x1c(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    11d7 <test_tile_serial+0xa7>
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11ef <test_tile_serial+0xbf>
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1236 <test_tile_serial+0x106>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x28(%rbp),%eax
add    $0x58d,%eax
mov    %eax,-0x28(%rbp)
jmp    1175 <test_tile_serial+0x45>
jmp    120d <test_tile_serial+0xdd>
mov    -0x24(%rbp),%eax
add    $0x527,%eax
mov    %eax,-0x24(%rbp)
jmp    1157 <test_tile_serial+0x27>
jmp    1222 <test_tile_serial+0xf2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1146 <test_tile_serial+0x16>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_tile_serial>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r13d,%r13d
lea    0xc(%rsp),%r12
xor    %ebp,%ebp
mov    $0x1,%r15d
mov    %r13d,%ecx
shl    %cl,%r15d
xor    %ebx,%ebx
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %ebx,%esi
mov    %r14d,%edx
call   1050 <tile_coordinate_to_serial_64@plt>
mov    %rax,%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %r12,%rcx
call   1040 <tile_serial_to_coordinate_64@plt>
cmp    %ebx,0x10(%rsp)
jne    11bc <test_tile_serial+0x8c>
cmp    0xc(%rsp),%r14d
jne    11bc <test_tile_serial+0x8c>
cmp    %r13d,0x14(%rsp)
jne    11bc <test_tile_serial+0x8c>
add    $0x1,%ebp
add    $0x58d,%r14d
cmp    %r15d,%r14d
jb     1160 <test_tile_serial+0x30>
add    $0x527,%ebx
cmp    %r15d,%ebx
jb     1156 <test_tile_serial+0x26>
add    $0x1,%r13d
cmp    $0x16,%r13d
jne    1148 <test_tile_serial+0x18>
jmp    11ca <test_tile_serial+0x9a>
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"~~~~ failed! ~~~~\0A\00"
define i32 @test_tile_serial() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %2
store i32 0, i32* %7
br label %10
10: ; preds = %56, %0
%11 = load i32, i32* %7
%12 = icmp ult i32 %11, 22
br i1 %12, label %13, label %59
13: ; preds = %10
store i32 0, i32* %8
br label %14
14: ; preds = %52, %13
%15 = load i32, i32* %8
%16 = load i32, i32* %7
%17 = shl i32 1, %16
%18 = icmp ult i32 %15, %17
br i1 %18, label %19, label %55
19: ; preds = %14
store i32 0, i32* %9
br label %20
20: ; preds = %48, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = shl i32 1, %22
%24 = icmp ult i32 %21, %23
br i1 %24, label %25, label %51
25: ; preds = %20
%26 = load i32, i32* %7
%27 = load i32, i32* %8
%28 = load i32, i32* %9
%29 = call i64 @tile_coordinate_to_serial_64(i32 %26, i32 %27, i32 %28)
store i64 %29, i64* %3
%30 = load i64, i64* %3
%31 = call i32 @tile_serial_to_coordinate_64(i64 %30, i32* %4, i32* %5, i32* %6)
%32 = load i32, i32* %5
%33 = load i32, i32* %8
%34 = icmp ne i32 %32, %33
br i1 %34, label %43, label %35
35: ; preds = %25
%36 = load i32, i32* %6
%37 = load i32, i32* %9
%38 = icmp ne i32 %36, %37
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32, i32* %4
%41 = load i32, i32* %7
%42 = icmp ne i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39, %35, %25
%44 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %61
45: ; preds = %39
%46 = load i32, i32* %2
%47 = add i32 %46, 1
store i32 %47, i32* %2
br label %48
48: ; preds = %45
%49 = load i32, i32* %9
%50 = add i32 %49, 1421
store i32 %50, i32* %9
br label %20
51: ; preds = %20
br label %52
52: ; preds = %51
%53 = load i32, i32* %8
%54 = add i32 %53, 1319
store i32 %54, i32* %8
br label %14
55: ; preds = %14
br label %56
56: ; preds = %55
%57 = load i32, i32* %7
%58 = add i32 %57, 1
store i32 %58, i32* %7
br label %10
59: ; preds = %10
%60 = load i32, i32* %2
store i32 %60, i32* %1
br label %61
61: ; preds = %59, %43
%62 = load i32, i32* %1
ret i32 %62
}

LLVM IR (-O2):
@str = [18 x i8] c"~~~~ failed! ~~~~\00"
define i32 @test_tile_serial() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %0, %34
%8 = phi i32 [ 0, %0 ], [ %35, %34 ]
%9 = phi i32 [ 0, %0 ], [ %28, %34 ]
%10 = shl nuw i32 1, %8
br label %11
11: ; preds = %7, %31
%12 = phi i32 [ 0, %7 ], [ %32, %31 ]
%13 = phi i32 [ %9, %7 ], [ %28, %31 ]
br label %14
14: ; preds = %11, %27
%15 = phi i32 [ 0, %11 ], [ %29, %27 ]
%16 = phi i32 [ %13, %11 ], [ %28, %27 ]
%17 = call i64 @tile_coordinate_to_serial_64(i32 %8, i32 %12, i32 %15)
%18 = call i32 @tile_serial_to_coordinate_64(i64 %17, i32* %1, i32* %2, i32* %3)
%19 = load i32, i32* %2
%20 = icmp eq i32 %19, %12
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, %15
%23 = select i1 %20, i1 %22, i1 false
%24 = load i32, i32* %1
%25 = icmp eq i32 %24, %8
%26 = select i1 %23, i1 %25, i1 false
br i1 %26, label %27, label %37
27: ; preds = %14
%28 = add i32 %16, 1
%29 = add i32 %15, 1421
%30 = icmp ult i32 %29, %10
br i1 %30, label %14, label %31
31: ; preds = %27
%32 = add i32 %12, 1319
%33 = icmp ult i32 %32, %10
br i1 %33, label %11, label %34
34: ; preds = %31
%35 = add nuw nsw i32 %8, 1
%36 = icmp eq i32 %35, 22
br i1 %36, label %39, label %7
37: ; preds = %14
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
br label %39
39: ; preds = %34, %37
%40 = phi i32 [ 0, %37 ], [ %28, %34 ]
ret i32 %40
}