#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 */
char bmm050_set_datarate(int);
char bmm050_set_repetitions_XY(int);
char bmm050_set_repetitions_Z(int);
char bmm050_set_presetmode(unsigned char mode) {
  char 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(14);
    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 = ((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)
movb   $0x0,-0x2(%rbp)
movzbl -0x1(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     125b <bmm050_set_presetmode+0x12b>
mov    -0x10(%rbp),%rax
lea    0xe9d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
xor    %edi,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %al,-0x2(%rbp)
mov    $0x1,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
mov    $0x2,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
jmp    125f <bmm050_set_presetmode+0x12f>
xor    %edi,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %al,-0x2(%rbp)
mov    $0x4,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
mov    $0xe,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
jmp    125f <bmm050_set_presetmode+0x12f>
mov    $0x5,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %al,-0x2(%rbp)
mov    $0x17,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
mov    $0x52,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
jmp    125f <bmm050_set_presetmode+0x12f>
xor    %edi,%edi
call   1050 <bmm050_set_datarate@plt>
mov    %al,-0x2(%rbp)
mov    $0x7,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
mov    $0x1a,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
movsbl %al,%ecx
movsbl -0x2(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x2(%rbp)
jmp    125f <bmm050_set_presetmode+0x12f>
movb   $0xfe,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmm050_set_presetmode>:
add    $0xff,%dil
mov    $0xfe,%al
cmp    $0x3,%dil
ja     118e <bmm050_set_presetmode+0x5e>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
movsbq %dil,%rax
lea    0xeb2(%rip),%rcx
mov    (%rcx,%rax,4),%edi
lea    0xeb8(%rip),%rcx
mov    (%rcx,%rax,4),%ebp
lea    0xebe(%rip),%rcx
mov    (%rcx,%rax,4),%r14d
call   1050 <bmm050_set_datarate@plt>
mov    %eax,%r15d
mov    %ebp,%edi
call   1040 <bmm050_set_repetitions_XY@plt>
mov    %eax,%ebx
or     %r15b,%bl
mov    %r14d,%edi
call   1030 <bmm050_set_repetitions_Z@plt>
or     %bl,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @bmm050_set_presetmode(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %2
store i8 0, i8* %3
%4 = load i8, i8* %2
%5 = zext i8 %4 to i32
switch i32 %5, label %62 [
i32 1, label %6
i32 2, label %20
i32 3, label %34
i32 4, label %48
]
6: ; preds = %1
%7 = call signext i8 @bmm050_set_datarate(i32 0)
store i8 %7, i8* %3
%8 = call signext i8 @bmm050_set_repetitions_XY(i32 1)
%9 = sext i8 %8 to i32
%10 = load i8, i8* %3
%11 = sext i8 %10 to i32
%12 = or i32 %11, %9
%13 = trunc i32 %12 to i8
store i8 %13, i8* %3
%14 = call signext i8 @bmm050_set_repetitions_Z(i32 2)
%15 = sext i8 %14 to i32
%16 = load i8, i8* %3
%17 = sext i8 %16 to i32
%18 = or i32 %17, %15
%19 = trunc i32 %18 to i8
store i8 %19, i8* %3
br label %63
20: ; preds = %1
%21 = call signext i8 @bmm050_set_datarate(i32 0)
store i8 %21, i8* %3
%22 = call signext i8 @bmm050_set_repetitions_XY(i32 4)
%23 = sext i8 %22 to i32
%24 = load i8, i8* %3
%25 = sext i8 %24 to i32
%26 = or i32 %25, %23
%27 = trunc i32 %26 to i8
store i8 %27, i8* %3
%28 = call signext i8 @bmm050_set_repetitions_Z(i32 14)
%29 = sext i8 %28 to i32
%30 = load i8, i8* %3
%31 = sext i8 %30 to i32
%32 = or i32 %31, %29
%33 = trunc i32 %32 to i8
store i8 %33, i8* %3
br label %63
34: ; preds = %1
%35 = call signext i8 @bmm050_set_datarate(i32 5)
store i8 %35, i8* %3
%36 = call signext i8 @bmm050_set_repetitions_XY(i32 23)
%37 = sext i8 %36 to i32
%38 = load i8, i8* %3
%39 = sext i8 %38 to i32
%40 = or i32 %39, %37
%41 = trunc i32 %40 to i8
store i8 %41, i8* %3
%42 = call signext i8 @bmm050_set_repetitions_Z(i32 82)
%43 = sext i8 %42 to i32
%44 = load i8, i8* %3
%45 = sext i8 %44 to i32
%46 = or i32 %45, %43
%47 = trunc i32 %46 to i8
store i8 %47, i8* %3
br label %63
48: ; preds = %1
%49 = call signext i8 @bmm050_set_datarate(i32 0)
store i8 %49, i8* %3
%50 = call signext i8 @bmm050_set_repetitions_XY(i32 7)
%51 = sext i8 %50 to i32
%52 = load i8, i8* %3
%53 = sext i8 %52 to i32
%54 = or i32 %53, %51
%55 = trunc i32 %54 to i8
store i8 %55, i8* %3
%56 = call signext i8 @bmm050_set_repetitions_Z(i32 26)
%57 = sext i8 %56 to i32
%58 = load i8, i8* %3
%59 = sext i8 %58 to i32
%60 = or i32 %59, %57
%61 = trunc i32 %60 to i8
store i8 %61, i8* %3
br label %63
62: ; preds = %1
store i8 -2, i8* %3
br label %63
63: ; preds = %62, %48, %34, %20, %6
%64 = load i8, i8* %3
ret i8 %64
}

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 14, i32 82, i32 26]
define signext i8 @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 signext i8 @bmm050_set_datarate(i32 %7)
%15 = tail call signext i8 @bmm050_set_repetitions_XY(i32 %10)
%16 = or i8 %15, %14
%17 = tail call signext i8 @bmm050_set_repetitions_Z(i32 %13)
%18 = or i8 %16, %17
br label %19
19: ; preds = %1, %4
%20 = phi i8 [ -2, %1 ], [ %18, %4 ]
ret i8 %20
}