void zigzag_reorder(int *coefs) {
  int i, temp[64],
      scan[64] = {0,  1,  5,  6,  14, 15, 27, 28, 2,  4,  7,  13, 16,
                  26, 29, 42, 3,  8,  12, 17, 25, 30, 41, 43, 9,  11,
                  18, 24, 31, 40, 44, 53, 10, 19, 23, 32, 39, 45, 52,
                  54, 20, 22, 33, 38, 46, 51, 55, 60, 21, 34, 37, 47,
                  50, 56, 59, 61, 35, 36, 48, 49, 57, 58, 62, 63};
  for (i = 0; i < 64; i++)
    temp[i] = coefs[scan[i]];
  for (i = 0; i < 64; i++)
    coefs[i] = temp[i];
}


x86 assembly (clang, -O0):
<zigzag_reorder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x210(%rbp),%rdi
lea    0xed3(%rip),%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x40,-0xc(%rbp)
jge    1174 <zigzag_reorder+0x64>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
movslq -0x210(%rbp,%rcx,4),%rcx
ff
mov    (%rax,%rcx,4),%ecx
movslq -0xc(%rbp),%rax
mov    %ecx,-0x110(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    113e <zigzag_reorder+0x2e>
movl   $0x0,-0xc(%rbp)
cmpl   $0x40,-0xc(%rbp)
jge    11a9 <zigzag_reorder+0x99>
movslq -0xc(%rbp),%rax
mov    -0x110(%rbp,%rax,4),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117b <zigzag_reorder+0x6b>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zigzag_reorder>:
sub    $0x108,%rsp
xor    %eax,%eax
lea    0xee0(%rip),%rcx
movslq (%rcx,%rax,4),%rdx
mov    (%rdi,%rdx,4),%edx
mov    %edx,(%rsp,%rax,4)
movslq 0x4(%rcx,%rax,4),%rdx
mov    (%rdi,%rdx,4),%edx
mov    %edx,0x4(%rsp,%rax,4)
movslq 0x8(%rcx,%rax,4),%rdx
mov    (%rdi,%rdx,4),%edx
mov    %edx,0x8(%rsp,%rax,4)
movslq 0xc(%rcx,%rax,4),%rdx
mov    (%rdi,%rdx,4),%edx
mov    %edx,0xc(%rsp,%rax,4)
add    $0x4,%rax
cmp    $0x40,%rax
jne    1120 <zigzag_reorder+0x10>
mov    %rsp,%rsi
mov    $0x100,%edx
call   1030 <memcpy@plt>
add    $0x108,%rsp
ret

LLVM IR (-O0):
@__const.zigzag_reorder.scan = [64 x i32] [i32 0, i32 1, i32 5, i32 6, i32 14, i32 15, i32 27, i32 28, i32 2, i32 4, i32 7, i32 13, i32 16, i32 26, i32 29, i32 42, i32 3, i32 8, i32 12, i32 17, i32 25, i32 30, i32 41, i32 43, i32 9, i32 11, i32 18, i32 24, i32 31, i32 40, i32 44, i32 53, i32 10, i32 19, i32 23, i32 32, i32 39, i32 45, i32 52, i32 54, i32 20, i32 22, i32 33, i32 38, i32 46, i32 51, i32 55, i32 60, i32 21, i32 34, i32 37, i32 47, i32 50, i32 56, i32 59, i32 61, i32 35, i32 36, i32 48, i32 49, i32 57, i32 58, i32 62, i32 63]
define void @zigzag_reorder(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [64 x i32]
%5 = alloca [64 x i32]
store i32* %0, i32** %2
%6 = bitcast [64 x i32]* %5 to i8*
store i32 0, i32* %3
br label %7
7: ; preds = %22, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 64
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32*, i32** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [64 x i32], [64 x i32]* %5, i64 0, i64 %13
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i32, i32* %11, i64 %16
%18 = load i32, i32* %17
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %20
store i32 %18, i32* %21
br label %22
22: ; preds = %10
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %7
25: ; preds = %7
store i32 0, i32* %3
br label %26
26: ; preds = %38, %25
%27 = load i32, i32* %3
%28 = icmp slt i32 %27, 64
br i1 %28, label %29, label %41
29: ; preds = %26
%30 = load i32, i32* %3
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %2
%35 = load i32, i32* %3
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
br label %38
38: ; preds = %29
%39 = load i32, i32* %3
%40 = add nsw i32 %39, 1
store i32 %40, i32* %3
br label %26
41: ; preds = %26
ret void
}

LLVM IR (-O2):
@__const.zigzag_reorder.scan = [64 x i32] [i32 0, i32 1, i32 5, i32 6, i32 14, i32 15, i32 27, i32 28, i32 2, i32 4, i32 7, i32 13, i32 16, i32 26, i32 29, i32 42, i32 3, i32 8, i32 12, i32 17, i32 25, i32 30, i32 41, i32 43, i32 9, i32 11, i32 18, i32 24, i32 31, i32 40, i32 44, i32 53, i32 10, i32 19, i32 23, i32 32, i32 39, i32 45, i32 52, i32 54, i32 20, i32 22, i32 33, i32 38, i32 46, i32 51, i32 55, i32 60, i32 21, i32 34, i32 37, i32 47, i32 50, i32 56, i32 59, i32 61, i32 35, i32 36, i32 48, i32 49, i32 57, i32 58, i32 62, i32 63]
define void @zigzag_reorder(i32* nocapture %0) {
%2 = alloca [64 x i32]
%3 = bitcast [64 x i32]* %2 to i8*
br label %4
4: ; preds = %4, %1
%5 = phi i64 [ 0, %1 ], [ %33, %4 ]
%6 = getelementptr inbounds [64 x i32], [64 x i32]* @__const.zigzag_reorder.scan, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %5
store i32 %10, i32* %11
%12 = or i64 %5, 1
%13 = getelementptr inbounds [64 x i32], [64 x i32]* @__const.zigzag_reorder.scan, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %12
store i32 %17, i32* %18
%19 = or i64 %5, 2
%20 = getelementptr inbounds [64 x i32], [64 x i32]* @__const.zigzag_reorder.scan, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %0, i64 %22
%24 = load i32, i32* %23
%25 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %19
store i32 %24, i32* %25
%26 = or i64 %5, 3
%27 = getelementptr inbounds [64 x i32], [64 x i32]* @__const.zigzag_reorder.scan, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %0, i64 %29
%31 = load i32, i32* %30
%32 = getelementptr inbounds [64 x i32], [64 x i32]* %2, i64 0, i64 %26
store i32 %31, i32* %32
%33 = add nuw nsw i64 %5, 4
%34 = icmp eq i64 %33, 64
br i1 %34, label %35, label %4
35: ; preds = %4
%36 = bitcast i32* %0 to i8*
ret void
}