#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 */
unsigned int AnalogRead_MeanPC2(int);
int /*<<< orphan*/ LED_OFF_All();
int /*<<< orphan*/ LED_ON_Power_Three();
int /*<<< orphan*/ PWM_Change_PB3(unsigned char);
int /*<<< orphan*/ _delay_ms(int);
unsigned char AutoCalibrate_3(unsigned char StartingVoltage,
                              unsigned int MinCalVal) {
  LED_ON_Power_Three();
  PWM_Change_PB3(StartingVoltage);
  _delay_ms(1000);
  unsigned char CurrentVoltage = StartingVoltage;
  unsigned int FrequencyToDCValue = 0;
  FrequencyToDCValue = AnalogRead_MeanPC2(16);
  for (CurrentVoltage = StartingVoltage; CurrentVoltage <= 255;
       CurrentVoltage = CurrentVoltage + 1) {
    PWM_Change_PB3(CurrentVoltage);
    _delay_ms(400);
    FrequencyToDCValue = AnalogRead_MeanPC2(16);
    if (FrequencyToDCValue <= MinCalVal) {
      LED_OFF_All();
      return (CurrentVoltage);
    }
  }
}


x86 assembly (clang, -O0):
<AutoCalibrate_3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dil,%al
mov    %al,-0x2(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <LED_ON_Power_Three@plt>
movzbl -0x2(%rbp),%edi
call   1040 <PWM_Change_PB3@plt>
mov    $0x3e8,%edi
call   1050 <_delay_ms@plt>
mov    -0x2(%rbp),%al
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
mov    $0x10,%edi
call   1060 <AnalogRead_MeanPC2@plt>
mov    %eax,-0x10(%rbp)
mov    -0x2(%rbp),%al
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0xff,%eax
jg     11fc <AutoCalibrate_3+0xac>
movzbl -0x9(%rbp),%edi
call   1040 <PWM_Change_PB3@plt>
mov    $0x190,%edi
call   1050 <_delay_ms@plt>
mov    $0x10,%edi
call   1060 <AnalogRead_MeanPC2@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
ja     11e8 <AutoCalibrate_3+0x98>
mov    $0x0,%al
call   1070 <LED_OFF_All@plt>
mov    -0x9(%rbp),%al
mov    %al,-0x1(%rbp)
jmp    11fc <AutoCalibrate_3+0xac>
jmp    11ed <AutoCalibrate_3+0x9d>
movzbl -0x9(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x9(%rbp)
jmp    119b <AutoCalibrate_3+0x4b>
movzbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AutoCalibrate_3>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <LED_ON_Power_Three@plt>
mov    %ebx,%edi
call   1040 <PWM_Change_PB3@plt>
mov    $0x3e8,%edi
call   1050 <_delay_ms@plt>
mov    $0x10,%edi
call   1060 <AnalogRead_MeanPC2@plt>
nopl   0x0(%rax)
movzbl %bl,%ebx
mov    %ebx,%edi
call   1040 <PWM_Change_PB3@plt>
mov    $0x190,%edi
call   1050 <_delay_ms@plt>
mov    $0x10,%edi
call   1060 <AnalogRead_MeanPC2@plt>
add    $0x1,%bl
cmp    %ebp,%eax
ja     1180 <AutoCalibrate_3+0x30>
xor    %eax,%eax
call   1070 <LED_OFF_All@plt>
add    $0xff,%bl
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @AutoCalibrate_3(i8 zeroext %0, i32 %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
store i8 %0, i8* %4
store i32 %1, i32* %5
%8 = call i32 (...) @LED_ON_Power_Three()
%9 = load i8, i8* %4
%10 = call i32 @PWM_Change_PB3(i8 zeroext %9)
%11 = call i32 @_delay_ms(i32 1000)
%12 = load i8, i8* %4
store i8 %12, i8* %6
store i32 0, i32* %7
%13 = call i32 @AnalogRead_MeanPC2(i32 16)
store i32 %13, i32* %7
%14 = load i8, i8* %4
store i8 %14, i8* %6
br label %15
15: ; preds = %31, %2
%16 = load i8, i8* %6
%17 = zext i8 %16 to i32
%18 = icmp sle i32 %17, 255
br i1 %18, label %19, label %36
19: ; preds = %15
%20 = load i8, i8* %6
%21 = call i32 @PWM_Change_PB3(i8 zeroext %20)
%22 = call i32 @_delay_ms(i32 400)
%23 = call i32 @AnalogRead_MeanPC2(i32 16)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = load i32, i32* %5
%26 = icmp ule i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = call i32 (...) @LED_OFF_All()
%29 = load i8, i8* %6
store i8 %29, i8* %3
br label %36
30: ; preds = %19
br label %31
31: ; preds = %30
%32 = load i8, i8* %6
%33 = zext i8 %32 to i32
%34 = add nsw i32 %33, 1
%35 = trunc i32 %34 to i8
store i8 %35, i8* %6
br label %15
36: ; preds = %27, %15
%37 = load i8, i8* %3
ret i8 %37
}

LLVM IR (-O2):
define zeroext i8 @AutoCalibrate_3(i8 zeroext %0, i32 %1) {
%3 = tail call i32 (...) @LED_ON_Power_Three()
%4 = tail call i32 @PWM_Change_PB3(i8 zeroext %0)
%5 = tail call i32 @_delay_ms(i32 1000)
%6 = tail call i32 @AnalogRead_MeanPC2(i32 16)
br label %7
7: ; preds = %7, %2
%8 = phi i8 [ %0, %2 ], [ %13, %7 ]
%9 = tail call i32 @PWM_Change_PB3(i8 zeroext %8)
%10 = tail call i32 @_delay_ms(i32 400)
%11 = tail call i32 @AnalogRead_MeanPC2(i32 16)
%12 = icmp ugt i32 %11, %1
%13 = add i8 %8, 1
br i1 %12, label %7, label %14
14: ; preds = %7
%15 = tail call i32 (...) @LED_OFF_All()
ret i8 %8
}