#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 int uint64_t;
typedef int uint32_t;

/* Variables and functions */
int compress_coords(int, int, int, int, int, int, int);
void tetra_corners(uint64_t id, uint32_t grid_width, uint32_t dir_flag,
                   uint64_t *out) {
  (void)dir_flag;
  int x = id % grid_width;
  int y = id % (grid_width * grid_width) / grid_width;
  int z = id / (grid_width * grid_width);
  out[0] = compress_coords(x, y, z, 0, 0, 1, grid_width);
  out[1] = compress_coords(x, y, z, 0, 1, 0, grid_width);
  out[2] = compress_coords(x, y, z, 1, 0, 0, grid_width);
}


x86 assembly (clang, -O0):
<tetra_corners>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0x8(%rbp),%ecx
cltd
idiv   %ecx
mov    %edx,%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    -0x8(%rbp),%ecx
imul   -0x8(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%eax
xor    %r8d,%r8d
mov    $0x1,%r9d
mov    %r8d,%ecx
mov    %eax,(%rsp)
call   1030 <compress_coords@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%eax
xor    %r9d,%r9d
mov    $0x1,%r8d
mov    %r9d,%ecx
mov    %eax,(%rsp)
call   1030 <compress_coords@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    -0x8(%rbp),%eax
mov    $0x1,%ecx
xor    %r9d,%r9d
mov    %r9d,%r8d
mov    %eax,(%rsp)
call   1030 <compress_coords@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tetra_corners>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %esi,%ebp
mov    %edi,%eax
cltd
idiv   %esi
mov    %edx,%r15d
mov    %esi,%ecx
imul   %esi,%ecx
mov    %edi,%eax
cltd
idiv   %ecx
mov    %eax,%r12d
mov    %edx,%eax
cltd
idiv   %esi
mov    %eax,%ebx
mov    %esi,(%rsp)
mov    %r15d,%edi
mov    %eax,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
mov    $0x1,%r9d
call   1030 <compress_coords@plt>
mov    %eax,(%r14)
mov    %ebp,(%rsp)
mov    %r15d,%edi
mov    %ebx,%esi
mov    %r12d,%edx
xor    %ecx,%ecx
mov    $0x1,%r8d
xor    %r9d,%r9d
call   1030 <compress_coords@plt>
mov    %eax,0x4(%r14)
mov    %ebp,(%rsp)
mov    %r15d,%edi
mov    %ebx,%esi
mov    %r12d,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1030 <compress_coords@plt>
mov    %eax,0x8(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @tetra_corners(i32 %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%12 = load i32, i32* %7
%13 = load i32, i32* %5
%14 = load i32, i32* %6
%15 = srem i32 %13, %14
store i32 %15, i32* %9
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = load i32, i32* %6
%19 = mul nsw i32 %17, %18
%20 = srem i32 %16, %19
%21 = load i32, i32* %6
%22 = sdiv i32 %20, %21
store i32 %22, i32* %10
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = load i32, i32* %6
%26 = mul nsw i32 %24, %25
%27 = sdiv i32 %23, %26
store i32 %27, i32* %11
%28 = load i32, i32* %9
%29 = load i32, i32* %10
%30 = load i32, i32* %11
%31 = load i32, i32* %6
%32 = call i32 @compress_coords(i32 %28, i32 %29, i32 %30, i32 0, i32 0, i32 1, i32 %31)
%33 = load i32*, i32** %8
%34 = getelementptr inbounds i32, i32* %33, i64 0
store i32 %32, i32* %34
%35 = load i32, i32* %9
%36 = load i32, i32* %10
%37 = load i32, i32* %11
%38 = load i32, i32* %6
%39 = call i32 @compress_coords(i32 %35, i32 %36, i32 %37, i32 0, i32 1, i32 0, i32 %38)
%40 = load i32*, i32** %8
%41 = getelementptr inbounds i32, i32* %40, i64 1
store i32 %39, i32* %41
%42 = load i32, i32* %9
%43 = load i32, i32* %10
%44 = load i32, i32* %11
%45 = load i32, i32* %6
%46 = call i32 @compress_coords(i32 %42, i32 %43, i32 %44, i32 1, i32 0, i32 0, i32 %45)
%47 = load i32*, i32** %8
%48 = getelementptr inbounds i32, i32* %47, i64 2
store i32 %46, i32* %48
ret void
}

LLVM IR (-O2):
define void @tetra_corners(i32 %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = srem i32 %0, %1
%6 = mul nsw i32 %1, %1
%7 = srem i32 %0, %6
%8 = sdiv i32 %7, %1
%9 = sdiv i32 %0, %6
%10 = tail call i32 @compress_coords(i32 %5, i32 %8, i32 %9, i32 0, i32 0, i32 1, i32 %1)
store i32 %10, i32* %3
%11 = tail call i32 @compress_coords(i32 %5, i32 %8, i32 %9, i32 0, i32 1, i32 0, i32 %1)
%12 = getelementptr inbounds i32, i32* %3, i64 1
store i32 %11, i32* %12
%13 = tail call i32 @compress_coords(i32 %5, i32 %8, i32 %9, i32 1, i32 0, i32 0, i32 %1)
%14 = getelementptr inbounds i32, i32* %3, i64 2
store i32 %13, i32* %14
ret void
}