to_edge(edge, i) register edge[8], i;
{
  register j, total = 0;
  for (j = 8 - 1; j >= 0; j--) {
    edge[j] = i % 3;
    i /= 3;
  }
  for (j = 0; j < 8; j++)
    total = 4 * total + edge[j];
  return (total);
}


x86 assembly (clang, -O0):
<to_edge>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x7,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1155 <to_edge+0x55>
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1119 <to_edge+0x19>
movl   $0x0,-0x10(%rbp)
cmpl   $0x8,-0x10(%rbp)
jge    1188 <to_edge+0x88>
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
add    (%rcx,%rdx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    115c <to_edge+0x5c>
mov    -0x14(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_edge>:
push   %r15
push   %r14
push   %rbx
movslq %esi,%r10
imul   $0x55555556,%r10,%r9
mov    %r9,%rax
shr    $0x3f,%rax
shr    $0x20,%r9
add    %eax,%r9d
lea    (%r9,%r9,2),%r8d
imul   $0x38e38e39,%r10,%r11
imul   $0x4bda12f7,%r10,%r14
imul   $0x1948b0fd,%r10,%r15
imul   $0xffffffff86d90545,%r10,%rcx
shr    $0x20,%rcx
add    %r10d,%ecx
imul   $0x59e60383,%r10,%rsi
imul   $0x1df75681,%r10,%rax
sub    %r8d,%r10d
mov    %r10d,0x1c(%rdi)
movslq %r9d,%r8
imul   $0x55555556,%r8,%rdx
mov    %rdx,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rdx
add    %ebx,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%r8d
mov    %r8d,0x18(%rdi)
mov    %r11,%rdx
shr    $0x3f,%rdx
shr    $0x20,%r11
sar    %r11d
add    %edx,%r11d
movslq %r11d,%r9
imul   $0x55555556,%r9,%rdx
mov    %rdx,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rdx
add    %ebx,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%r9d
mov    %r9d,0x14(%rdi)
mov    %r14,%rdx
shr    $0x3f,%rdx
shr    $0x20,%r14
sar    $0x3,%r14d
add    %edx,%r14d
movslq %r14d,%r11
imul   $0x55555556,%r11,%rbx
mov    %rbx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rbx
add    %edx,%ebx
lea    (%rbx,%rbx,2),%edx
sub    %edx,%r11d
mov    %r11d,0x10(%rdi)
mov    %r15,%rdx
shr    $0x3f,%rdx
shr    $0x20,%r15
sar    $0x3,%r15d
add    %edx,%r15d
movslq %r15d,%r14
imul   $0x55555556,%r14,%rdx
mov    %rdx,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rdx
add    %ebx,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%r14d
mov    %r14d,0xc(%rdi)
mov    %ecx,%edx
shr    $0x1f,%edx
sar    $0x7,%ecx
add    %edx,%ecx
movslq %ecx,%rcx
imul   $0x55555556,%rcx,%rdx
mov    %rdx,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rdx
add    %ebx,%edx
lea    (%rdx,%rdx,2),%edx
sub    %edx,%ecx
mov    %ecx,0x8(%rdi)
mov    %rsi,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rsi
sar    $0x8,%esi
add    %edx,%esi
movslq %esi,%rdx
imul   $0x55555556,%rdx,%rsi
mov    %rsi,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rsi
add    %ebx,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%edx
mov    %edx,0x4(%rdi)
mov    %rax,%rsi
shr    $0x3f,%rsi
shr    $0x20,%rax
sar    $0x8,%eax
add    %esi,%eax
cltq
imul   $0x55555556,%rax,%rsi
mov    %rsi,%rbx
shr    $0x3f,%rbx
shr    $0x20,%rsi
add    %ebx,%esi
lea    (%rsi,%rsi,2),%esi
sub    %esi,%eax
mov    %eax,(%rdi)
lea    (%rdx,%rax,4),%eax
lea    (%rcx,%rax,4),%eax
lea    (%r14,%rax,4),%eax
lea    (%r11,%rax,4),%eax
lea    (%r9,%rax,4),%eax
lea    (%r8,%rax,4),%eax
lea    (%r10,%rax,4),%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @to_edge(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i32 7, i32* %5
br label %7
7: ; preds = %19, %2
%8 = load i32, i32* %5
%9 = icmp sge i32 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %7
%11 = load i32, i32* %4
%12 = srem i32 %11, 3
%13 = load i32*, i32** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32 %12, i32* %16
%17 = load i32, i32* %4
%18 = sdiv i32 %17, 3
store i32 %18, i32* %4
br label %19
19: ; preds = %10
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
br label %7
22: ; preds = %7
store i32 0, i32* %5
br label %23
23: ; preds = %35, %22
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 8
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = load i32, i32* %6
%28 = mul nsw i32 4, %27
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = add nsw i32 %28, %33
store i32 %34, i32* %6
br label %35
35: ; preds = %26
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %23
38: ; preds = %23
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
define i32 @to_edge(i32* nocapture %0, i32 %1) {
%3 = srem i32 %1, 3
%4 = getelementptr inbounds i32, i32* %0, i64 7
store i32 %3, i32* %4
%5 = sdiv i32 %1, 3
%6 = srem i32 %5, 3
%7 = getelementptr inbounds i32, i32* %0, i64 6
store i32 %6, i32* %7
%8 = sdiv i32 %1, 9
%9 = srem i32 %8, 3
%10 = getelementptr inbounds i32, i32* %0, i64 5
store i32 %9, i32* %10
%11 = sdiv i32 %1, 27
%12 = srem i32 %11, 3
%13 = getelementptr inbounds i32, i32* %0, i64 4
store i32 %12, i32* %13
%14 = sdiv i32 %1, 81
%15 = srem i32 %14, 3
%16 = getelementptr inbounds i32, i32* %0, i64 3
store i32 %15, i32* %16
%17 = sdiv i32 %1, 243
%18 = srem i32 %17, 3
%19 = getelementptr inbounds i32, i32* %0, i64 2
store i32 %18, i32* %19
%20 = sdiv i32 %1, 729
%21 = srem i32 %20, 3
%22 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %21, i32* %22
%23 = sdiv i32 %1, 2187
%24 = srem i32 %23, 3
store i32 %24, i32* %0
%25 = shl nsw i32 %24, 2
%26 = add nsw i32 %21, %25
%27 = shl nsw i32 %26, 2
%28 = add nsw i32 %18, %27
%29 = shl nsw i32 %28, 2
%30 = add nsw i32 %15, %29
%31 = shl nsw i32 %30, 2
%32 = add nsw i32 %12, %31
%33 = shl nsw i32 %32, 2
%34 = add nsw i32 %9, %33
%35 = shl nsw i32 %34, 2
%36 = add nsw i32 %6, %35
%37 = shl nsw i32 %36, 2
%38 = add nsw i32 %3, %37
ret i32 %38
}