#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 AnalogRead_PC2();
int /*<<< orphan*/ _delay_ms(int);
int AnalogRead_MeanPC2(unsigned char NumOfSamplesToAverage) {
  int TotalValue = 0;
  int MeanValue = 0;
  int i = 0;
  for (i = 1; i <= NumOfSamplesToAverage; i++) {
    TotalValue = TotalValue + AnalogRead_PC2();
    _delay_ms(10);
  }
  MeanValue = TotalValue / NumOfSamplesToAverage;
  return MeanValue;
}


x86 assembly (clang, -O0):
<AnalogRead_MeanPC2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cmp    %ecx,%eax
jg     1188 <AnalogRead_MeanPC2+0x68>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <AnalogRead_PC2@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    $0xa,%edi
call   1040 <_delay_ms@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114a <AnalogRead_MeanPC2+0x2a>
mov    -0x8(%rbp),%eax
movzbl -0x1(%rbp),%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AnalogRead_MeanPC2>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%r14d
test   %edi,%edi
je     114a <AnalogRead_MeanPC2+0x2a>
mov    %r14d,%ebx
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <AnalogRead_PC2@plt>
add    %eax,%ebp
mov    $0xa,%edi
call   1040 <_delay_ms@plt>
add    $0xffffffff,%ebx
jne    1130 <AnalogRead_MeanPC2+0x10>
jmp    114c <AnalogRead_MeanPC2+0x2c>
xor    %ebp,%ebp
mov    %ebp,%eax
cltd
idiv   %r14d
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @AnalogRead_MeanPC2(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i8 %0, i8* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
store i32 1, i32* %5
br label %6
6: ; preds = %16, %1
%7 = load i32, i32* %5
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = icmp sle i32 %7, %9
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i32, i32* %3
%13 = call i32 (...) @AnalogRead_PC2()
%14 = add nsw i32 %12, %13
store i32 %14, i32* %3
%15 = call i32 @_delay_ms(i32 10)
br label %16
16: ; preds = %11
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %6
19: ; preds = %6
%20 = load i32, i32* %3
%21 = load i8, i8* %2
%22 = zext i8 %21 to i32
%23 = sdiv i32 %20, %22
store i32 %23, i32* %4
%24 = load i32, i32* %4
ret i32 %24
}

LLVM IR (-O2):
define i32 @AnalogRead_MeanPC2(i8 zeroext %0) {
%2 = zext i8 %0 to i32
%3 = icmp eq i8 %0, 0
br i1 %3, label %12, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %10, %4 ], [ 1, %1 ]
%6 = phi i32 [ %8, %4 ], [ 0, %1 ]
%7 = tail call i32 (...) @AnalogRead_PC2()
%8 = add nsw i32 %7, %6
%9 = tail call i32 @_delay_ms(i32 10)
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %5, %2
br i1 %11, label %12, label %4
12: ; preds = %4, %1
%13 = phi i32 [ 0, %1 ], [ %8, %4 ]
%14 = sdiv i32 %13, %2
ret i32 %14
}