#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 *);
char bmm050_get_repetitions_XY(unsigned char *);
char 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>
movsbl %al,%ecx
movsbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <bmm050_get_repetitions_Z@plt>
movsbl %al,%ecx
movsbl -0x9(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x9(%rbp)
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11b5 <bmm050_get_presetmode+0x85>
movzbl -0xb(%rbp),%eax
cmp    $0x1,%eax
jne    11b5 <bmm050_get_presetmode+0x85>
movzbl -0xc(%rbp),%eax
cmp    $0x2,%eax
jne    11b5 <bmm050_get_presetmode+0x85>
mov    -0x8(%rbp),%rax
movb   $0x1,(%rax)
jmp    1264 <bmm050_get_presetmode+0x134>
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    11e8 <bmm050_get_presetmode+0xb8>
movzbl -0xb(%rbp),%eax
cmp    $0x4,%eax
jne    11e8 <bmm050_get_presetmode+0xb8>
movzbl -0xc(%rbp),%eax
cmp    $0xf,%eax
jne    11e8 <bmm050_get_presetmode+0xb8>
mov    -0x8(%rbp),%rax
movb   $0x2,(%rax)
jmp    125f <bmm050_get_presetmode+0x12f>
movzbl -0xa(%rbp),%eax
cmp    $0x5,%eax
jne    121b <bmm050_get_presetmode+0xeb>
movzbl -0xb(%rbp),%eax
cmp    $0x17,%eax
jne    121b <bmm050_get_presetmode+0xeb>
movzbl -0xc(%rbp),%eax
cmp    $0x52,%eax
jne    121b <bmm050_get_presetmode+0xeb>
mov    -0x8(%rbp),%rax
movb   $0x3,(%rax)
jmp    125a <bmm050_get_presetmode+0x12a>
movzbl -0xa(%rbp),%eax
cmp    $0x0,%eax
jne    124e <bmm050_get_presetmode+0x11e>
movzbl -0xb(%rbp),%eax
cmp    $0x7,%eax
jne    124e <bmm050_get_presetmode+0x11e>
movzbl -0xc(%rbp),%eax
cmp    $0x1a,%eax
jne    124e <bmm050_get_presetmode+0x11e>
mov    -0x8(%rbp),%rax
movb   $0x4,(%rax)
jmp    1255 <bmm050_get_presetmode+0x125>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    125a <bmm050_get_presetmode+0x12a>
jmp    125f <bmm050_get_presetmode+0x12f>
jmp    1264 <bmm050_get_presetmode+0x134>
movsbl -0x9(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmm050_get_presetmode>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movb   $0x0,0xf(%rsp)
movb   $0x0,0xe(%rsp)
movb   $0x0,0xd(%rsp)
lea    0xf(%rsp),%rdi
call   1050 <bmm050_get_datarate@plt>
mov    %eax,%ebp
lea    0xe(%rsp),%rdi
call   1040 <bmm050_get_repetitions_XY@plt>
mov    %eax,%ebx
lea    0xd(%rsp),%rdi
call   1030 <bmm050_get_repetitions_Z@plt>
mov    0xf(%rsp),%dil
mov    0xe(%rsp),%dl
mov    0xd(%rsp),%sil
test   %dil,%dil
jne    118c <bmm050_get_presetmode+0x5c>
cmp    $0x1,%dl
jne    118c <bmm050_get_presetmode+0x5c>
mov    $0x1,%cl
cmp    $0x2,%sil
je     11c4 <bmm050_get_presetmode+0x94>
test   %dil,%dil
jne    119e <bmm050_get_presetmode+0x6e>
cmp    $0x4,%dl
jne    119e <bmm050_get_presetmode+0x6e>
mov    $0x2,%cl
cmp    $0xf,%sil
je     11c4 <bmm050_get_presetmode+0x94>
cmp    $0x5,%dil
jne    11b1 <bmm050_get_presetmode+0x81>
cmp    $0x17,%dl
jne    11b1 <bmm050_get_presetmode+0x81>
mov    $0x3,%cl
cmp    $0x52,%sil
je     11c4 <bmm050_get_presetmode+0x94>
xor    $0x7,%dl
or     %dl,%dil
xor    $0x1a,%sil
or     %dil,%sil
sete   %cl
shl    $0x2,%cl
mov    %cl,(%r14)
or     %bpl,%bl
or     %al,%bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
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 signext i8 @bmm050_get_repetitions_XY(i8* %5)
%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_get_repetitions_Z(i8* %6)
%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
%20 = load i8, i8* %4
%21 = zext i8 %20 to i32
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %1
%24 = load i8, i8* %5
%25 = zext i8 %24 to i32
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %33
27: ; preds = %23
%28 = load i8, i8* %6
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = load i8*, i8** %2
store i8 1, i8* %32
br label %80
33: ; preds = %27, %23, %1
%34 = load i8, i8* %4
%35 = zext i8 %34 to i32
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %33
%38 = load i8, i8* %5
%39 = zext i8 %38 to i32
%40 = icmp eq i32 %39, 4
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = load i8, i8* %6
%43 = zext i8 %42 to i32
%44 = icmp eq i32 %43, 15
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = load i8*, i8** %2
store i8 2, i8* %46
br label %79
47: ; preds = %41, %37, %33
%48 = load i8, i8* %4
%49 = zext i8 %48 to i32
%50 = icmp eq i32 %49, 5
br i1 %50, label %51, label %61
51: ; preds = %47
%52 = load i8, i8* %5
%53 = zext i8 %52 to i32
%54 = icmp eq i32 %53, 23
br i1 %54, label %55, label %61
55: ; preds = %51
%56 = load i8, i8* %6
%57 = zext i8 %56 to i32
%58 = icmp eq i32 %57, 82
br i1 %58, label %59, label %61
59: ; preds = %55
%60 = load i8*, i8** %2
store i8 3, i8* %60
br label %78
61: ; preds = %55, %51, %47
%62 = load i8, i8* %4
%63 = zext i8 %62 to i32
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %75
65: ; preds = %61
%66 = load i8, i8* %5
%67 = zext i8 %66 to i32
%68 = icmp eq i32 %67, 7
br i1 %68, label %69, label %75
69: ; preds = %65
%70 = load i8, i8* %6
%71 = zext i8 %70 to i32
%72 = icmp eq i32 %71, 26
br i1 %72, label %73, label %75
73: ; preds = %69
%74 = load i8*, i8** %2
store i8 4, i8* %74
br label %77
75: ; preds = %69, %65, %61
%76 = load i8*, i8** %2
store i8 0, i8* %76
br label %77
77: ; preds = %75, %73
br label %78
78: ; preds = %77, %59
br label %79
79: ; preds = %78, %45
br label %80
80: ; preds = %79, %31
%81 = load i8, i8* %3
ret i8 %81
}

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 signext i8 @bmm050_get_repetitions_XY(i8* %3)
%7 = call signext i8 @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 = or i8 %6, %5
%36 = or i8 %35, %7
ret i8 %36
}