#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_get_datarate(unsigned char *);
scalar_t__ bmm050_get_repetitions_XY(unsigned char *);
scalar_t__ bmm050_get_repetitions_Z(unsigned char *);
char bmm050_get_presetmode(unsigned char *mode) {
  char comres = 0;
  unsigned char data_rate = 0;
  unsigned char repetitionsxy = 0;
  unsigned char repetitionsz = 0;
  comres = bmm050_get_datarate(&data_rate);
  comres += bmm050_get_repetitions_XY(&repetitionsxy);
  comres += bmm050_get_repetitions_Z(&repetitionsz);
  if ((data_rate == 0) && (repetitionsxy == 1) && (repetitionsz == 2)) {
    *mode = 1;
  } else {
    if ((data_rate == 0) && (repetitionsxy == 4) && (repetitionsz == 15)) {
      *mode = 2;
    } else {
      if ((data_rate == 5) && (repetitionsxy == 23) && (repetitionsz == 82)) {
        *mode = 3;
      } else {
        if ((data_rate == 0) && (repetitionsxy == 7) && (repetitionsz == 26)) {
          *mode = 4;
        } else {
          *mode = 0;
        }
      }
    }
  }
  return comres;
}


x86 assembly (clang, -O0):
<bmm050_get_presetmode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
movb   $0x0,-0xa(%rbp)
movb   $0x0,-0xb(%rbp)
movb   $0x0,-0xc(%rbp)
lea    -0xa(%rbp),%rdi
call   1050 <bmm050_get_datarate@plt>
mov    %al,-0x9(%rbp)
lea    -0xb(%rbp),%rdi
call   1040 <bmm050_get_repetitions_XY@plt>
mov    %rax,%rcx
movsbq -0x9(%rbp),%rax
add    %rcx,%rax
mov    %al,-0x9(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <bmm050_get_repetitions_Z@plt>
mov    %rax,%rcx
movsbq -0x9(%rbp),%rax
add    %rcx,%rax
mov    %al,-0x9(%rbp)
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11b9 <bmm050_get_presetmode+0x89>
movzbl -0xb(%rbp),%eax
cmp    $0x1,%eax
jne    11b9 <bmm050_get_presetmode+0x89>
movzbl -0xc(%rbp),%eax
cmp    $0x2,%eax
jne    11b9 <bmm050_get_presetmode+0x89>
mov    -0x8(%rbp),%rax
movb   $0x1,(%rax)
jmp    1268 <bmm050_get_presetmode+0x138>
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11ec <bmm050_get_presetmode+0xbc>
movzbl -0xb(%rbp),%eax
cmp    $0x4,%eax
jne    11ec <bmm050_get_presetmode+0xbc>
movzbl -0xc(%rbp),%eax
cmp    $0xf,%eax
jne    11ec <bmm050_get_presetmode+0xbc>
mov    -0x8(%rbp),%rax
movb   $0x2,(%rax)
jmp    1263 <bmm050_get_presetmode+0x133>
movzbl -0xa(%rbp),%eax
cmp    $0x5,%eax
jne    121f <bmm050_get_presetmode+0xef>
movzbl -0xb(%rbp),%eax
cmp    $0x17,%eax
jne    121f <bmm050_get_presetmode+0xef>
movzbl -0xc(%rbp),%eax
cmp    $0x52,%eax
jne    121f <bmm050_get_presetmode+0xef>
mov    -0x8(%rbp),%rax
movb   $0x3,(%rax)
jmp    125e <bmm050_get_presetmode+0x12e>
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    1252 <bmm050_get_presetmode+0x122>
movzbl -0xb(%rbp),%eax
cmp    $0x7,%eax
jne    1252 <bmm050_get_presetmode+0x122>
movzbl -0xc(%rbp),%eax
cmp    $0x1a,%eax
jne    1252 <bmm050_get_presetmode+0x122>
mov    -0x8(%rbp),%rax
movb   $0x4,(%rax)
jmp    1259 <bmm050_get_presetmode+0x129>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    125e <bmm050_get_presetmode+0x12e>
jmp    1263 <bmm050_get_presetmode+0x133>
jmp    1268 <bmm050_get_presetmode+0x138>
movsbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmm050_get_presetmode>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
movb   $0x0,0x7(%rsp)
movb   $0x0,0x6(%rsp)
movb   $0x0,0x5(%rsp)
lea    0x7(%rsp),%rdi
call   1050 <bmm050_get_datarate@plt>
mov    %eax,%ebp
lea    0x6(%rsp),%rdi
call   1040 <bmm050_get_repetitions_XY@plt>
mov    %rax,%r15
lea    0x5(%rsp),%rdi
call   1030 <bmm050_get_repetitions_Z@plt>
mov    0x7(%rsp),%cl
mov    0x6(%rsp),%dl
mov    0x5(%rsp),%sil
test   %cl,%cl
jne    118a <bmm050_get_presetmode+0x5a>
cmp    $0x1,%dl
jne    118a <bmm050_get_presetmode+0x5a>
mov    $0x1,%bl
cmp    $0x2,%sil
je     11bf <bmm050_get_presetmode+0x8f>
test   %cl,%cl
jne    119b <bmm050_get_presetmode+0x6b>
cmp    $0x4,%dl
jne    119b <bmm050_get_presetmode+0x6b>
mov    $0x2,%bl
cmp    $0xf,%sil
je     11bf <bmm050_get_presetmode+0x8f>
cmp    $0x5,%cl
jne    11ad <bmm050_get_presetmode+0x7d>
cmp    $0x17,%dl
jne    11ad <bmm050_get_presetmode+0x7d>
mov    $0x3,%bl
cmp    $0x52,%sil
je     11bf <bmm050_get_presetmode+0x8f>
xor    $0x7,%dl
or     %dl,%cl
xor    $0x1a,%sil
or     %cl,%sil
sete   %bl
shl    $0x2,%bl
mov    %bl,(%r14)
add    %r15b,%bpl
add    %bpl,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define signext i8 @bmm050_get_presetmode(i8* nocapture writeonly %0) {
%2 = alloca i8
%3 = alloca i8
%4 = alloca i8
store i8 0, i8* %2
store i8 0, i8* %3
store i8 0, i8* %4
%5 = call signext i8 @bmm050_get_datarate(i8* %2)
%6 = call i64 @bmm050_get_repetitions_XY(i8* %3)
%7 = call i64 @bmm050_get_repetitions_Z(i8* %4)
%8 = load i8, i8* %2
%9 = icmp eq i8 %8, 0
%10 = load i8, i8* %3
%11 = icmp eq i8 %10, 1
%12 = select i1 %9, i1 %11, i1 false
%13 = load i8, i8* %4
%14 = icmp eq i8 %13, 2
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %33, label %16
16: ; preds = %1
%17 = icmp eq i8 %10, 4
%18 = select i1 %9, i1 %17, i1 false
%19 = icmp eq i8 %13, 15
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %33, label %21
21: ; preds = %16
%22 = icmp eq i8 %8, 5
%23 = icmp eq i8 %10, 23
%24 = select i1 %22, i1 %23, i1 false
%25 = icmp eq i8 %13, 82
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %33, label %27
27: ; preds = %21
%28 = icmp eq i8 %10, 7
%29 = select i1 %9, i1 %28, i1 false
%30 = icmp eq i8 %13, 26
%31 = select i1 %29, i1 %30, i1 false
%32 = select i1 %31, i8 4, i8 0
br label %33
33: ; preds = %27, %21, %16, %1
%34 = phi i8 [ 1, %1 ], [ 2, %16 ], [ 3, %21 ], [ %32, %27 ]
store i8 %34, i8* %0
%35 = trunc i64 %6 to i8
%36 = add i8 %5, %35
%37 = trunc i64 %7 to i8
%38 = add i8 %36, %37
ret i8 %38
}