#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_get_datarate(unsigned char *);
scalar_t__ bmm050_get_repetitions_XY(unsigned char *);
scalar_t__ bmm050_get_repetitions_Z(unsigned char *);
int bmm050_get_presetmode(unsigned char *mode) {
  int 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)
movl   $0x0,-0xc(%rbp)
movb   $0x0,-0xd(%rbp)
movb   $0x0,-0xe(%rbp)
movb   $0x0,-0xf(%rbp)
lea    -0xd(%rbp),%rdi
call   1050 <bmm050_get_datarate@plt>
mov    %eax,-0xc(%rbp)
lea    -0xe(%rbp),%rdi
call   1040 <bmm050_get_repetitions_XY@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
lea    -0xf(%rbp),%rdi
call   1030 <bmm050_get_repetitions_Z@plt>
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
movzbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jne    11ba <bmm050_get_presetmode+0x8a>
movzbl -0xe(%rbp),%eax
cmp    $0x1,%eax
jne    11ba <bmm050_get_presetmode+0x8a>
movzbl -0xf(%rbp),%eax
cmp    $0x2,%eax
jne    11ba <bmm050_get_presetmode+0x8a>
mov    -0x8(%rbp),%rax
movb   $0x1,(%rax)
jmp    1269 <bmm050_get_presetmode+0x139>
movzbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jne    11ed <bmm050_get_presetmode+0xbd>
movzbl -0xe(%rbp),%eax
cmp    $0x4,%eax
jne    11ed <bmm050_get_presetmode+0xbd>
movzbl -0xf(%rbp),%eax
cmp    $0xf,%eax
jne    11ed <bmm050_get_presetmode+0xbd>
mov    -0x8(%rbp),%rax
movb   $0x2,(%rax)
jmp    1264 <bmm050_get_presetmode+0x134>
movzbl -0xd(%rbp),%eax
cmp    $0x5,%eax
jne    1220 <bmm050_get_presetmode+0xf0>
movzbl -0xe(%rbp),%eax
cmp    $0x17,%eax
jne    1220 <bmm050_get_presetmode+0xf0>
movzbl -0xf(%rbp),%eax
cmp    $0x52,%eax
jne    1220 <bmm050_get_presetmode+0xf0>
mov    -0x8(%rbp),%rax
movb   $0x3,(%rax)
jmp    125f <bmm050_get_presetmode+0x12f>
movzbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jne    1253 <bmm050_get_presetmode+0x123>
movzbl -0xe(%rbp),%eax
cmp    $0x7,%eax
jne    1253 <bmm050_get_presetmode+0x123>
movzbl -0xf(%rbp),%eax
cmp    $0x1a,%eax
jne    1253 <bmm050_get_presetmode+0x123>
mov    -0x8(%rbp),%rax
movb   $0x4,(%rax)
jmp    125a <bmm050_get_presetmode+0x12a>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    125f <bmm050_get_presetmode+0x12f>
jmp    1264 <bmm050_get_presetmode+0x134>
jmp    1269 <bmm050_get_presetmode+0x139>
mov    -0xc(%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),%bl
mov    0x5(%rsp),%sil
test   %cl,%cl
jne    118a <bmm050_get_presetmode+0x5a>
cmp    $0x1,%bl
jne    118a <bmm050_get_presetmode+0x5a>
mov    $0x1,%dl
cmp    $0x2,%sil
je     11bf <bmm050_get_presetmode+0x8f>
test   %cl,%cl
jne    119b <bmm050_get_presetmode+0x6b>
cmp    $0x4,%bl
jne    119b <bmm050_get_presetmode+0x6b>
mov    $0x2,%dl
cmp    $0xf,%sil
je     11bf <bmm050_get_presetmode+0x8f>
cmp    $0x5,%cl
jne    11ad <bmm050_get_presetmode+0x7d>
cmp    $0x17,%bl
jne    11ad <bmm050_get_presetmode+0x7d>
mov    $0x3,%dl
cmp    $0x52,%sil
je     11bf <bmm050_get_presetmode+0x8f>
xor    $0x7,%bl
or     %bl,%cl
xor    $0x1a,%sil
or     %cl,%sil
sete   %dl
shl    $0x2,%dl
mov    %dl,(%r14)
add    %r15d,%ebp
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bmm050_get_presetmode(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %2
store i32 0, i32* %3
store i8 0, i8* %4
store i8 0, i8* %5
store i8 0, i8* %6
%7 = call i32 @bmm050_get_datarate(i8* %4)
store i32 %7, i32* %3
%8 = call i64 @bmm050_get_repetitions_XY(i8* %5)
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = add nsw i64 %10, %8
%12 = trunc i64 %11 to i32
store i32 %12, i32* %3
%13 = call i64 @bmm050_get_repetitions_Z(i8* %6)
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = add nsw i64 %15, %13
%17 = trunc i64 %16 to i32
store i32 %17, i32* %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 i32, i32* %3
ret i32 %79
}

LLVM IR (-O2):
define i32 @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 i32 @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 i32
%36 = add i32 %5, %35
%37 = trunc i64 %7 to i32
%38 = add i32 %36, %37
ret i32 %38
}