void channel_pos(int channels, int pos[8]) {
  if (channels == 4) {
    pos[0] = 1;
    pos[1] = 3;
    pos[2] = 1;
    pos[3] = 3;
  } else if (channels == 3 || channels == 5 || channels == 6) {
    pos[0] = 1;
    pos[1] = 2;
    pos[2] = 3;
    pos[3] = 1;
    pos[4] = 3;
    pos[5] = 0;
  } else if (channels == 7) {
    pos[0] = 1;
    pos[1] = 2;
    pos[2] = 3;
    pos[3] = 1;
    pos[4] = 3;
    pos[5] = 2;
    pos[6] = 0;
  } else if (channels == 8) {
    pos[0] = 1;
    pos[1] = 2;
    pos[2] = 3;
    pos[3] = 1;
    pos[4] = 3;
    pos[5] = 1;
    pos[6] = 3;
    pos[7] = 0;
  }
}


x86 assembly (clang, -O0):
<channel_pos>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
jne    1145 <channel_pos+0x45>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0xc(%rax)
jmp    1274 <channel_pos+0x174>
cmpl   $0x3,-0x4(%rbp)
je     1163 <channel_pos+0x63>
cmpl   $0x5,-0x4(%rbp)
je     1163 <channel_pos+0x63>
cmpl   $0x6,-0x4(%rbp)
jne    11a9 <channel_pos+0xa9>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x14(%rax)
jmp    126f <channel_pos+0x16f>
cmpl   $0x7,-0x4(%rbp)
jne    1204 <channel_pos+0x104>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x14(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x18(%rax)
jmp    126a <channel_pos+0x16a>
cmpl   $0x8,-0x4(%rbp)
jne    1265 <channel_pos+0x165>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x2,0x4(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0xc(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x10(%rax)
mov    -0x10(%rbp),%rax
movl   $0x1,0x14(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,0x18(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x1c(%rax)
jmp    126a <channel_pos+0x16a>
jmp    126f <channel_pos+0x16f>
jmp    1274 <channel_pos+0x174>
pop    %rbp
ret

x86 assembly (clang, -O2):
<channel_pos>:
add    $0xfffffffd,%edi
cmp    $0x5,%edi
ja     11d9 <channel_pos+0xd9>
lea    0xefd(%rip),%rax
movslq (%rax,%rdi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
movabs $0x200000001,%rax
mov    %rax,(%rsi)
movl   $0x3,0x8(%rsi)
xor    %edx,%edx
mov    $0x5,%r8d
mov    $0x3,%r9d
mov    $0x4,%edi
mov    $0x1,%eax
mov    $0x3,%ecx
jmp    11ce <channel_pos+0xce>
movl   $0x1,(%rsi)
mov    $0x3,%r8d
mov    $0x1,%r9d
mov    $0x2,%edi
mov    $0x3,%eax
mov    $0x1,%ecx
mov    $0x3,%edx
jmp    11ce <channel_pos+0xce>
movaps 0xe82(%rip),%xmm0
movups %xmm0,(%rsi)
movl   $0x3,0x10(%rsi)
xor    %edx,%edx
mov    $0x7,%r8d
mov    $0x3,%r9d
mov    $0x6,%edi
mov    $0x1,%eax
mov    $0x5,%ecx
jmp    11ce <channel_pos+0xce>
movaps 0xe52(%rip),%xmm0
movups %xmm0,(%rsi)
xor    %edx,%edx
mov    $0x6,%r8d
mov    $0x2,%r9d
mov    $0x5,%edi
mov    $0x3,%eax
mov    $0x4,%ecx
mov    %eax,(%rsi,%rcx,4)
mov    %r9d,(%rsi,%rdi,4)
mov    %edx,(%rsi,%r8,4)
ret

LLVM IR (-O0):
define void @channel_pos(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
store i32 %0, i32* %3
store i32* %1, i32** %4
%5 = load i32, i32* %3
%6 = icmp eq i32 %5, 4
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load i32*, i32** %4
%9 = getelementptr inbounds i32, i32* %8, i64 0
store i32 1, i32* %9
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 1
store i32 3, i32* %11
%12 = load i32*, i32** %4
%13 = getelementptr inbounds i32, i32* %12, i64 2
store i32 1, i32* %13
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 3
store i32 3, i32* %15
br label %79
16: ; preds = %2
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 3
br i1 %18, label %25, label %19
19: ; preds = %16
%20 = load i32, i32* %3
%21 = icmp eq i32 %20, 5
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 6
br i1 %24, label %25, label %38
25: ; preds = %22, %19, %16
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 0
store i32 1, i32* %27
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 1
store i32 2, i32* %29
%30 = load i32*, i32** %4
%31 = getelementptr inbounds i32, i32* %30, i64 2
store i32 3, i32* %31
%32 = load i32*, i32** %4
%33 = getelementptr inbounds i32, i32* %32, i64 3
store i32 1, i32* %33
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 4
store i32 3, i32* %35
%36 = load i32*, i32** %4
%37 = getelementptr inbounds i32, i32* %36, i64 5
store i32 0, i32* %37
br label %78
38: ; preds = %22
%39 = load i32, i32* %3
%40 = icmp eq i32 %39, 7
br i1 %40, label %41, label %56
41: ; preds = %38
%42 = load i32*, i32** %4
%43 = getelementptr inbounds i32, i32* %42, i64 0
store i32 1, i32* %43
%44 = load i32*, i32** %4
%45 = getelementptr inbounds i32, i32* %44, i64 1
store i32 2, i32* %45
%46 = load i32*, i32** %4
%47 = getelementptr inbounds i32, i32* %46, i64 2
store i32 3, i32* %47
%48 = load i32*, i32** %4
%49 = getelementptr inbounds i32, i32* %48, i64 3
store i32 1, i32* %49
%50 = load i32*, i32** %4
%51 = getelementptr inbounds i32, i32* %50, i64 4
store i32 3, i32* %51
%52 = load i32*, i32** %4
%53 = getelementptr inbounds i32, i32* %52, i64 5
store i32 2, i32* %53
%54 = load i32*, i32** %4
%55 = getelementptr inbounds i32, i32* %54, i64 6
store i32 0, i32* %55
br label %77
56: ; preds = %38
%57 = load i32, i32* %3
%58 = icmp eq i32 %57, 8
br i1 %58, label %59, label %76
59: ; preds = %56
%60 = load i32*, i32** %4
%61 = getelementptr inbounds i32, i32* %60, i64 0
store i32 1, i32* %61
%62 = load i32*, i32** %4
%63 = getelementptr inbounds i32, i32* %62, i64 1
store i32 2, i32* %63
%64 = load i32*, i32** %4
%65 = getelementptr inbounds i32, i32* %64, i64 2
store i32 3, i32* %65
%66 = load i32*, i32** %4
%67 = getelementptr inbounds i32, i32* %66, i64 3
store i32 1, i32* %67
%68 = load i32*, i32** %4
%69 = getelementptr inbounds i32, i32* %68, i64 4
store i32 3, i32* %69
%70 = load i32*, i32** %4
%71 = getelementptr inbounds i32, i32* %70, i64 5
store i32 1, i32* %71
%72 = load i32*, i32** %4
%73 = getelementptr inbounds i32, i32* %72, i64 6
store i32 3, i32* %73
%74 = load i32*, i32** %4
%75 = getelementptr inbounds i32, i32* %74, i64 7
store i32 0, i32* %75
br label %76
76: ; preds = %59, %56
br label %77
77: ; preds = %76, %41
br label %78
78: ; preds = %77, %25
br label %79
79: ; preds = %78, %7
ret void
}

LLVM IR (-O2):
define void @channel_pos(i32 %0, i32* writeonly %1) {
switch i32 %0, label %22 [
i32 4, label %3
i32 6, label %4
i32 5, label %4
i32 3, label %4
i32 7, label %7
i32 8, label %9
]
3: ; preds = %2
store i32 1, i32* %1
br label %12
4: ; preds = %2, %2, %2
store i32 1, i32* %1
%5 = getelementptr inbounds i32, i32* %1, i64 1
store i32 2, i32* %5
%6 = getelementptr inbounds i32, i32* %1, i64 2
store i32 3, i32* %6
br label %12
7: ; preds = %2
%8 = bitcast i32* %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 1>, <4 x i32>* %8
br label %12
9: ; preds = %2
%10 = bitcast i32* %1 to <4 x i32>*
store <4 x i32> <i32 1, i32 2, i32 3, i32 1>, <4 x i32>* %10
%11 = getelementptr inbounds i32, i32* %1, i64 4
store i32 3, i32* %11
br label %12
12: ; preds = %3, %7, %9, %4
%13 = phi i64 [ 3, %4 ], [ 5, %9 ], [ 4, %7 ], [ 1, %3 ]
%14 = phi i32 [ 1, %4 ], [ 1, %9 ], [ 3, %7 ], [ 3, %3 ]
%15 = phi i64 [ 4, %4 ], [ 6, %9 ], [ 5, %7 ], [ 2, %3 ]
%16 = phi i32 [ 3, %4 ], [ 3, %9 ], [ 2, %7 ], [ 1, %3 ]
%17 = phi i64 [ 5, %4 ], [ 7, %9 ], [ 6, %7 ], [ 3, %3 ]
%18 = phi i32 [ 0, %4 ], [ 0, %9 ], [ 0, %7 ], [ 3, %3 ]
%19 = getelementptr inbounds i32, i32* %1, i64 %13
store i32 %14, i32* %19
%20 = getelementptr inbounds i32, i32* %1, i64 %15
store i32 %16, i32* %20
%21 = getelementptr inbounds i32, i32* %1, i64 %17
store i32 %18, i32* %21
br label %22
22: ; preds = %12, %2
ret void
}