#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 */
double const resistance_from_adc(unsigned int, unsigned int const);
unsigned int find_minimum_adc(const double resistance_min,
                              const unsigned int reference_resistance) {
  unsigned int adc = 0;
  while (adc < 32768 &&
         (resistance_from_adc(adc, reference_resistance) < resistance_min)) {
    ++adc;
  }
  if (adc > 0) {
    --adc;
  }
  return adc;
}


x86 assembly (clang, -O0):
<find_minimum_adc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %edi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x8000,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jae    1156 <find_minimum_adc+0x46>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%esi
call   1030 <resistance_from_adc@plt>
movaps %xmm0,%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
seta   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1166 <find_minimum_adc+0x56>
jmp    1174 <find_minimum_adc+0x64>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1127 <find_minimum_adc+0x17>
cmpl   $0x0,-0x10(%rbp)
jbe    1187 <find_minimum_adc+0x77>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_minimum_adc>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %ebp,%esi
call   1030 <resistance_from_adc@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    1146 <find_minimum_adc+0x36>
add    $0x1,%ebx
cmp    $0x8000,%ebx
jne    1120 <find_minimum_adc+0x10>
mov    $0x7fff,%ebx
jmp    114e <find_minimum_adc+0x3e>
xor    %eax,%eax
sub    $0x1,%ebx
cmovb  %eax,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @find_minimum_adc(double %0, i32 %1) {
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
store double %0, double* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %17, %2
%7 = load i32, i32* %5
%8 = icmp ult i32 %7, 32768
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = call double @resistance_from_adc(i32 %10, i32 %11)
%13 = load double, double* %3
%14 = fcmp olt double %12, %13
br label %15
15: ; preds = %9, %6
%16 = phi i1 [ false, %6 ], [ %14, %9 ]
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* %5
%19 = add i32 %18, 1
store i32 %19, i32* %5
br label %6
20: ; preds = %15
%21 = load i32, i32* %5
%22 = icmp ugt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i32, i32* %5
%25 = add i32 %24, -1
store i32 %25, i32* %5
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
define i32 @find_minimum_adc(double %0, i32 %1) {
br label %3
3: ; preds = %2, %7
%4 = phi i32 [ 0, %2 ], [ %8, %7 ]
%5 = tail call double @resistance_from_adc(i32 %4, i32 %1)
%6 = fcmp olt double %5, %0
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = add nuw nsw i32 %4, 1
%9 = icmp eq i32 %8, 32768
br i1 %9, label %14, label %3
10: ; preds = %3
%11 = icmp eq i32 %4, 0
%12 = add nsw i32 %4, -1
%13 = select i1 %11, i32 0, i32 %12
br label %14
14: ; preds = %7, %10
%15 = phi i32 [ %13, %10 ], [ 32767, %7 ]
ret i32 %15
}