#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 */

/* Variables and functions */
int bmm050_set_datarate(int);
int bmm050_set_repetitions_XY(int);
int bmm050_set_repetitions_Z(int);
int bmm050_set_presetmode(unsigned char mode) {
  int comres = 0;
  switch (mode) {
  case 1:
    comres = bmm050_set_datarate(0);
    comres += bmm050_set_repetitions_XY(1);
    comres += bmm050_set_repetitions_Z(2);
    break;
  case 2:
    comres = bmm050_set_datarate(0);
    comres += bmm050_set_repetitions_XY(4);
    comres += bmm050_set_repetitions_Z(15);
    break;
  case 3:
    comres = bmm050_set_datarate(5);
    comres += bmm050_set_repetitions_XY(23);
    comres += bmm050_set_repetitions_Z(82);
    break;
  case 4:
    comres = bmm050_set_datarate(0);
    comres += bmm050_set_repetitions_XY(7);
    comres += bmm050_set_repetitions_Z(26);
    break;
  default:
    comres = ((signed char)-2);
    break;
  }
  return comres;
}


x86 assembly (clang, -O0):
<bmm050_set_presetmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movzbl -0x1(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     122e <bmm050_set_presetmode+0xfe>
mov    -0x10(%rbp),%rax
lea    0xe9a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %edi,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %eax,-0x8(%rbp)
mov    $0x1,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x2,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1235 <bmm050_set_presetmode+0x105>
xor    %edi,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %eax,-0x8(%rbp)
mov    $0x4,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0xf,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1235 <bmm050_set_presetmode+0x105>
mov    $0x5,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %eax,-0x8(%rbp)
mov    $0x17,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x52,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1235 <bmm050_set_presetmode+0x105>
xor    %edi,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %eax,-0x8(%rbp)
mov    $0x7,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x1a,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
jmp    1235 <bmm050_set_presetmode+0x105>
movl   $0xfffffffe,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmm050_set_presetmode>:
add    $0xff,%dil
mov    $0xfffffffe,%eax
cmp    $0x3,%dil
ja     1186 <bmm050_set_presetmode+0x56>
push   %rbp
push   %r14
push   %rbx
movsbq %dil,%rax
lea    0xeb2(%rip),%rcx
mov    (%rcx,%rax,4),%edi
lea    0xeb8(%rip),%rcx
mov    (%rcx,%rax,4),%ebx
lea    0xebe(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
call   1050 <bmm050_set_datarate@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r14d,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
add    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bmm050_set_presetmode(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %3
%4 = load i8, i8* %2
%5 = zext i8 %4 to i32
switch i32 %5, label %38 [
i32 1, label %6
i32 2, label %14
i32 3, label %22
i32 4, label %30
]
6: ; preds = %1
%7 = call i32 @bmm050_set_datarate(i32 0)
store i32 %7, i32* %3
%8 = call i32 @bmm050_set_repetitions_XY(i32 1)
%9 = load i32, i32* %3
%10 = add nsw i32 %9, %8
store i32 %10, i32* %3
%11 = call i32 @bmm050_set_repetitions_Z(i32 2)
%12 = load i32, i32* %3
%13 = add nsw i32 %12, %11
store i32 %13, i32* %3
br label %39
14: ; preds = %1
%15 = call i32 @bmm050_set_datarate(i32 0)
store i32 %15, i32* %3
%16 = call i32 @bmm050_set_repetitions_XY(i32 4)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, %16
store i32 %18, i32* %3
%19 = call i32 @bmm050_set_repetitions_Z(i32 15)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, %19
store i32 %21, i32* %3
br label %39
22: ; preds = %1
%23 = call i32 @bmm050_set_datarate(i32 5)
store i32 %23, i32* %3
%24 = call i32 @bmm050_set_repetitions_XY(i32 23)
%25 = load i32, i32* %3
%26 = add nsw i32 %25, %24
store i32 %26, i32* %3
%27 = call i32 @bmm050_set_repetitions_Z(i32 82)
%28 = load i32, i32* %3
%29 = add nsw i32 %28, %27
store i32 %29, i32* %3
br label %39
30: ; preds = %1
%31 = call i32 @bmm050_set_datarate(i32 0)
store i32 %31, i32* %3
%32 = call i32 @bmm050_set_repetitions_XY(i32 7)
%33 = load i32, i32* %3
%34 = add nsw i32 %33, %32
store i32 %34, i32* %3
%35 = call i32 @bmm050_set_repetitions_Z(i32 26)
%36 = load i32, i32* %3
%37 = add nsw i32 %36, %35
store i32 %37, i32* %3
br label %39
38: ; preds = %1
store i32 -2, i32* %3
br label %39
39: ; preds = %38, %30, %22, %14, %6
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@switch.table.bmm050_set_presetmode = [4 x i32] [i32 0, i32 0, i32 5, i32 0]
@switch.table.bmm050_set_presetmode.1 = [4 x i32] [i32 1, i32 4, i32 23, i32 7]
@switch.table.bmm050_set_presetmode.2 = [4 x i32] [i32 2, i32 15, i32 82, i32 26]
define i32 @bmm050_set_presetmode(i8 zeroext %0) {
%2 = add i8 %0, -1
%3 = icmp ult i8 %2, 4
br i1 %3, label %4, label %19
4: ; preds = %1
%5 = sext i8 %2 to i64
%6 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.bmm050_set_presetmode, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = sext i8 %2 to i64
%9 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.bmm050_set_presetmode.1, i64 0, i64 %8
%10 = load i32, i32* %9
%11 = sext i8 %2 to i64
%12 = getelementptr inbounds [4 x i32], [4 x i32]* @switch.table.bmm050_set_presetmode.2, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 @bmm050_set_datarate(i32 %7)
%15 = tail call i32 @bmm050_set_repetitions_XY(i32 %10)
%16 = add nsw i32 %15, %14
%17 = tail call i32 @bmm050_set_repetitions_Z(i32 %13)
%18 = add nsw i32 %16, %17
br label %19
19: ; preds = %1, %4
%20 = phi i32 [ -2, %1 ], [ %18, %4 ]
ret i32 %20
}