#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 read_1wire_sensor(int, int *);
int read_dht_sensor(int, int *);
int read_sht_sensor(int, int *);
int read_register_handler(int addr, int *reg_val_p) {
  int rc;
  int retry = 4;
  if ((addr >= (int)1) && (addr <= (int)((int)1 + (int)20 - 1))) {
    do {
      rc = read_1wire_sensor(addr, reg_val_p);
    } while ((rc == -4) && retry--);
  } else if ((addr >= (int)((int)((int)1 + (int)20 - 1) + 1)) &&
             (addr <= (int)((int)((int)((int)1 + (int)20 - 1) + 1) +
                            (2 * (int)2) - 1))) {
    rc = read_dht_sensor(addr, reg_val_p);
  } else if ((addr >= (int)((int)((int)((int)((int)1 + (int)20 - 1) + 1) +
                                  (2 * (int)2) - 1) +
                            1)) &&
             (addr <= (int)((int)((int)((int)((int)((int)1 + (int)20 - 1) + 1) +
                                        (2 * (int)2) - 1) +
                                  1) +
                            (2 * (int)2) - 1))) {
    rc = read_sht_sensor(addr, reg_val_p);
  } else {
    rc = -1;
  }
  return rc;
}


x86 assembly (clang, -O0):
<read_register_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x18(%rbp)
cmpl   $0x1,-0x4(%rbp)
jl     11a1 <read_register_handler+0x71>
cmpl   $0x14,-0x4(%rbp)
jg     11a1 <read_register_handler+0x71>
jmp    115f <read_register_handler+0x2f>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <read_1wire_sensor@plt>
mov    %eax,-0x14(%rbp)
xor    %eax,%eax
cmpl   $0xfffffffc,-0x14(%rbp)
mov    %al,-0x19(%rbp)
jne    1191 <read_register_handler+0x61>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    115f <read_register_handler+0x2f>
jmp    1202 <read_register_handler+0xd2>
cmpl   $0x15,-0x4(%rbp)
jl     11c9 <read_register_handler+0x99>
cmpl   $0x18,-0x4(%rbp)
jg     11c9 <read_register_handler+0x99>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <read_dht_sensor@plt>
mov    %eax,-0x14(%rbp)
jmp    11fd <read_register_handler+0xcd>
cmpl   $0x19,-0x4(%rbp)
jl     11f1 <read_register_handler+0xc1>
cmpl   $0x1c,-0x4(%rbp)
jg     11f1 <read_register_handler+0xc1>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <read_sht_sensor@plt>
mov    %eax,-0x14(%rbp)
jmp    11f8 <read_register_handler+0xc8>
movl   $0xffffffff,-0x14(%rbp)
jmp    11fd <read_register_handler+0xcd>
jmp    1202 <read_register_handler+0xd2>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_register_handler>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
lea    -0x1(%rbx),%eax
cmp    $0x13,%eax
ja     118e <read_register_handler+0x5e>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <read_1wire_sensor@plt>
cmp    $0xfffffffc,%eax
jne    11c5 <read_register_handler+0x95>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <read_1wire_sensor@plt>
cmp    $0xfffffffc,%eax
jne    11c5 <read_register_handler+0x95>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <read_1wire_sensor@plt>
cmp    $0xfffffffc,%eax
jne    11c5 <read_register_handler+0x95>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <read_1wire_sensor@plt>
cmp    $0xfffffffc,%eax
jne    11c5 <read_register_handler+0x95>
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <read_1wire_sensor@plt>
lea    -0x15(%rbx),%eax
cmp    $0x3,%eax
ja     11a7 <read_register_handler+0x77>
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <read_dht_sensor@plt>
lea    -0x19(%rbx),%ecx
mov    $0xffffffff,%eax
cmp    $0x3,%ecx
ja     11c5 <read_register_handler+0x95>
mov    %ebx,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <read_sht_sensor@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @read_register_handler(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32* %1, i32** %4
store i32 4, i32* %6
%7 = load i32, i32* %3
%8 = icmp sge i32 %7, 1
br i1 %8, label %9, label %27
9: ; preds = %2
%10 = load i32, i32* %3
%11 = icmp sle i32 %10, 20
br i1 %11, label %12, label %27
12: ; preds = %9
br label %13
13: ; preds = %24, %12
%14 = load i32, i32* %3
%15 = load i32*, i32** %4
%16 = call i32 @read_1wire_sensor(i32 %14, i32* %15)
store i32 %16, i32* %5
br label %17
17: ; preds = %13
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, -4
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32, i32* %6
%22 = add nsw i32 %21, -1
store i32 %22, i32* %6
%23 = icmp ne i32 %21, 0
br label %24
24: ; preds = %20, %17
%25 = phi i1 [ false, %17 ], [ %23, %20 ]
br i1 %25, label %13, label %26
26: ; preds = %24
br label %50
27: ; preds = %9, %2
%28 = load i32, i32* %3
%29 = icmp sge i32 %28, 21
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %3
%32 = icmp sle i32 %31, 24
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* %3
%35 = load i32*, i32** %4
%36 = call i32 @read_dht_sensor(i32 %34, i32* %35)
store i32 %36, i32* %5
br label %49
37: ; preds = %30, %27
%38 = load i32, i32* %3
%39 = icmp sge i32 %38, 25
br i1 %39, label %40, label %47
40: ; preds = %37
%41 = load i32, i32* %3
%42 = icmp sle i32 %41, 28
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* %3
%45 = load i32*, i32** %4
%46 = call i32 @read_sht_sensor(i32 %44, i32* %45)
store i32 %46, i32* %5
br label %48
47: ; preds = %40, %37
store i32 -1, i32* %5
br label %48
48: ; preds = %47, %43
br label %49
49: ; preds = %48, %33
br label %50
50: ; preds = %49, %26
%51 = load i32, i32* %5
ret i32 %51
}

LLVM IR (-O2):
define i32 @read_register_handler(i32 %0, i32* %1) {
%3 = add i32 %0, -1
%4 = icmp ult i32 %3, 20
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = tail call i32 @read_1wire_sensor(i32 %0, i32* %1)
%7 = icmp eq i32 %6, -4
br i1 %7, label %8, label %29
8: ; preds = %5
%9 = tail call i32 @read_1wire_sensor(i32 %0, i32* %1)
%10 = icmp eq i32 %9, -4
br i1 %10, label %11, label %29
11: ; preds = %8
%12 = tail call i32 @read_1wire_sensor(i32 %0, i32* %1)
%13 = icmp eq i32 %12, -4
br i1 %13, label %14, label %29
14: ; preds = %11
%15 = tail call i32 @read_1wire_sensor(i32 %0, i32* %1)
%16 = icmp eq i32 %15, -4
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = tail call i32 @read_1wire_sensor(i32 %0, i32* %1)
br label %29
19: ; preds = %2
%20 = add i32 %0, -21
%21 = icmp ult i32 %20, 4
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @read_dht_sensor(i32 %0, i32* %1)
br label %29
24: ; preds = %19
%25 = add i32 %0, -25
%26 = icmp ult i32 %25, 4
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @read_sht_sensor(i32 %0, i32* %1)
br label %29
29: ; preds = %17, %5, %8, %11, %14, %24, %22, %27
%30 = phi i32 [ %23, %22 ], [ %28, %27 ], [ -1, %24 ], [ %6, %5 ], [ %9, %8 ], [ %12, %11 ], [ %15, %14 ], [ %18, %17 ]
ret i32 %30
}