#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 uint8_t;

/* Variables and functions */
int update_byte(int, int, int);
uint8_t set_channel(uint8_t config, uint8_t channel) {
  switch (channel) {
  case 1:
    config = update_byte(config, 5, 0);
    config = update_byte(config, 6, 0);
    break;
  case 2:
    config = update_byte(config, 5, 1);
    config = update_byte(config, 6, 0);
    break;
  case 3:
    config = update_byte(config, 5, 0);
    config = update_byte(config, 6, 1);
    break;
  case 4:
    config = update_byte(config, 5, 1);
    config = update_byte(config, 6, 1);
    break;
  }
  return (config);
}


x86 assembly (clang, -O0):
<set_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     11f2 <set_channel+0xe2>
mov    -0x10(%rbp),%rax
lea    0xec2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x6,%esi
xor    %edx,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <set_channel+0xe2>
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
mov    $0x1,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x6,%esi
xor    %edx,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <set_channel+0xe2>
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x6,%esi
mov    $0x1,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11f2 <set_channel+0xe2>
mov    -0x4(%rbp),%edi
mov    $0x5,%esi
mov    $0x1,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x6,%esi
mov    $0x1,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_channel>:
add    $0xffffffff,%esi
cmp    $0x3,%esi
ja     1149 <set_channel+0x39>
push   %rbx
movslq %esi,%rax
lea    0xedd(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0xee3(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
mov    $0x5,%esi
call   1030 <update_byte@plt>
mov    %eax,%edi
mov    $0x6,%esi
mov    %ebx,%edx
pop    %rbx
jmp    1030 <update_byte@plt>
mov    %edi,%eax
ret

LLVM IR (-O0):
define i32 @set_channel(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %26 [
i32 1, label %6
i32 2, label %11
i32 3, label %16
i32 4, label %21
]
6: ; preds = %2
%7 = load i32, i32* %3
%8 = call i32 @update_byte(i32 %7, i32 5, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 @update_byte(i32 %9, i32 6, i32 0)
store i32 %10, i32* %3
br label %26
11: ; preds = %2
%12 = load i32, i32* %3
%13 = call i32 @update_byte(i32 %12, i32 5, i32 1)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @update_byte(i32 %14, i32 6, i32 0)
store i32 %15, i32* %3
br label %26
16: ; preds = %2
%17 = load i32, i32* %3
%18 = call i32 @update_byte(i32 %17, i32 5, i32 0)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = call i32 @update_byte(i32 %19, i32 6, i32 1)
store i32 %20, i32* %3
br label %26
21: ; preds = %2
%22 = load i32, i32* %3
%23 = call i32 @update_byte(i32 %22, i32 5, i32 1)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = call i32 @update_byte(i32 %24, i32 6, i32 1)
store i32 %25, i32* %3
br label %26
26: ; preds = %2, %21, %16, %11, %6
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
@switch.table.set_channel = [4 x i32] [i32 0, i32 1, i32 0, i32 1]
@switch.table.set_channel.1 = [4 x i32] [i32 0, i32 0, i32 1, i32 1]
define i32 @set_channel(i32 %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp ult i32 %3, 4
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.set_channel, i64 0, i64 %6
%8 = load i32, i32* %7
%9 = sext i32 %3 to i64
%10 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.set_channel.1, i64 0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @update_byte(i32 %0, i32 5, i32 %8)
%13 = tail call i32 @update_byte(i32 %12, i32 6, i32 %11)
br label %14
14: ; preds = %2, %5
%15 = phi i32 [ %0, %2 ], [ %13, %5 ]
ret i32 %15
}