#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_pga(uint8_t config, uint8_t gain) {
  switch (gain) {
  case 1:
    config = update_byte(config, 0, 0);
    config = update_byte(config, 1, 0);
    break;
  case 2:
    config = update_byte(config, 0, 1);
    config = update_byte(config, 1, 0);
    break;
  case 4:
    config = update_byte(config, 0, 0);
    config = update_byte(config, 1, 1);
    break;
  case 8:
    config = update_byte(config, 0, 1);
    config = update_byte(config, 1, 1);
    break;
  default:
    break;
  }
  return (config);
}


x86 assembly (clang, -O0):
<set_pga>:
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    $0x7,%eax
ja     11e5 <set_pga+0xd5>
mov    -0x10(%rbp),%rax
lea    0xec2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <set_pga+0xda>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <set_pga+0xda>
mov    -0x4(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <set_pga+0xda>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <update_byte@plt>
mov    %eax,-0x4(%rbp)
jmp    11ea <set_pga+0xda>
jmp    11ea <set_pga+0xda>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pga>:
add    $0xffffffff,%esi
cmp    $0x7,%esi
ja     1122 <set_pga+0x12>
mov    $0x8b,%eax
bt     %esi,%eax
jb     1125 <set_pga+0x15>
mov    %edi,%eax
ret
push   %rbx
movslq %esi,%rax
lea    0xed0(%rip),%rcx
mov    (%rcx,%rax,4),%edx
lea    0xee6(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
xor    %esi,%esi
call   1030 <update_byte@plt>
mov    %eax,%edi
mov    $0x1,%esi
mov    %ebx,%edx
pop    %rbx
jmp    1030 <update_byte@plt>

LLVM IR (-O0):
define i32 @set_pga(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 4, label %16
i32 8, label %21
]
6: ; preds = %2
%7 = load i32, i32* %3
%8 = call i32 @update_byte(i32 %7, i32 0, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = call i32 @update_byte(i32 %9, i32 1, i32 0)
store i32 %10, i32* %3
br label %27
11: ; preds = %2
%12 = load i32, i32* %3
%13 = call i32 @update_byte(i32 %12, i32 0, i32 1)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @update_byte(i32 %14, i32 1, i32 0)
store i32 %15, i32* %3
br label %27
16: ; preds = %2
%17 = load i32, i32* %3
%18 = call i32 @update_byte(i32 %17, i32 0, i32 0)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = call i32 @update_byte(i32 %19, i32 1, i32 1)
store i32 %20, i32* %3
br label %27
21: ; preds = %2
%22 = load i32, i32* %3
%23 = call i32 @update_byte(i32 %22, i32 0, i32 1)
store i32 %23, i32* %3
%24 = load i32, i32* %3
%25 = call i32 @update_byte(i32 %24, i32 1, i32 1)
store i32 %25, i32* %3
br label %27
26: ; preds = %2
br label %27
27: ; preds = %26, %21, %16, %11, %6
%28 = load i32, i32* %3
ret i32 %28
}

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