#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 /*<<< orphan*/ adc_set_chan(int);
int /*<<< orphan*/ delay_ms(int);
int /*<<< orphan*/ gpio_a_analog(int);
int /*<<< orphan*/ printf(char *, int, ...);
int read_avg(int);
void adc_test2(void) {
  int i;
  int val;
  int val2;
  int save;
  gpio_a_analog(1);
  printf(" ADC channel %d\n", 1);
  adc_set_chan(1);
  for (i = 0; i < 5; i++) {
    val = read_avg(40);
    printf("LM385 voltage: %d\n", val);
    delay_ms(10);
  }
  save = read_avg(100);
  for (i = 0; i < 5; i++) {
    val = read_avg(40);
    val2 = val * 1227;
    val2 /= save;
    printf("LM385 voltage: %d %d\n", val, val2);
    delay_ms(10);
  }
}


x86 assembly (clang, -O0):
<adc_test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x1,%edi
call   1030 <gpio_a_analog@plt>
lea    0xe97(%rip),%rdi
mov    $0x1,%esi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1050 <adc_set_chan@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jge    11c6 <adc_test2+0x76>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1186 <adc_test2+0x36>
mov    $0x64,%edi
call   1040 <read_avg@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jge    1233 <adc_test2+0xe3>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,-0x8(%rbp)
imul   $0x4cb,-0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0xc(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11da <adc_test2+0x8a>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adc_test2>:
push   %r14
push   %rbx
push   %rax
mov    $0x1,%edi
call   1030 <gpio_a_analog@plt>
lea    0xe9b(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   1050 <adc_set_chan@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
lea    0xe85(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x64,%edi
call   1040 <read_avg@plt>
mov    %eax,%ebx
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,%esi
imul   $0x4cb,%eax,%eax
cltd
idiv   %ebx
lea    0xdda(%rip),%r14
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,%esi
imul   $0x4cb,%eax,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,%esi
imul   $0x4cb,%eax,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,%esi
imul   $0x4cb,%eax,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1070 <delay_ms@plt>
mov    $0x28,%edi
call   1040 <read_avg@plt>
mov    %eax,%esi
imul   $0x4cb,%eax,%eax
cltd
idiv   %ebx
mov    %r14,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <delay_ms@plt>

LLVM IR (-O0):
@.str = [17 x i8] c" ADC channel %d\0A\00"
@.str.1 = [19 x i8] c"LM385 voltage: %d\0A\00"
@.str.2 = [22 x i8] c"LM385 voltage: %d %d\0A\00"
define void @adc_test2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 @gpio_a_analog(i32 1)
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = call i32 @adc_set_chan(i32 1)
store i32 0, i32* %1
br label %8
8: ; preds = %16, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 5
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = call i32 @read_avg(i32 40)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = call i32 @delay_ms(i32 10)
br label %16
16: ; preds = %11
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
br label %8
19: ; preds = %8
%20 = call i32 @read_avg(i32 100)
store i32 %20, i32* %4
store i32 0, i32* %1
br label %21
21: ; preds = %35, %19
%22 = load i32, i32* %1
%23 = icmp slt i32 %22, 5
br i1 %23, label %24, label %38
24: ; preds = %21
%25 = call i32 @read_avg(i32 40)
store i32 %25, i32* %2
%26 = load i32, i32* %2
%27 = mul nsw i32 %26, 1227
store i32 %27, i32* %3
%28 = load i32, i32* %4
%29 = load i32, i32* %3
%30 = sdiv i32 %29, %28
store i32 %30, i32* %3
%31 = load i32, i32* %2
%32 = load i32, i32* %3
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %31, i32 %32)
%34 = call i32 @delay_ms(i32 10)
br label %35
35: ; preds = %24
%36 = load i32, i32* %1
%37 = add nsw i32 %36, 1
store i32 %37, i32* %1
br label %21
38: ; preds = %21
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c" ADC channel %d\0A\00"
@.str.1 = [19 x i8] c"LM385 voltage: %d\0A\00"
@.str.2 = [22 x i8] c"LM385 voltage: %d %d\0A\00"
define void @adc_test2() {
%1 = tail call i32 @gpio_a_analog(i32 1)
%2 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 1)
%3 = tail call i32 @adc_set_chan(i32 1)
%4 = tail call i32 @read_avg(i32 40)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 @delay_ms(i32 10)
%7 = tail call i32 @read_avg(i32 40)
%8 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = tail call i32 @delay_ms(i32 10)
%10 = tail call i32 @read_avg(i32 40)
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = tail call i32 @delay_ms(i32 10)
%13 = tail call i32 @read_avg(i32 40)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = tail call i32 @delay_ms(i32 10)
%16 = tail call i32 @read_avg(i32 40)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = tail call i32 @delay_ms(i32 10)
%19 = tail call i32 @read_avg(i32 100)
%20 = tail call i32 @read_avg(i32 40)
%21 = mul nsw i32 %20, 1227
%22 = sdiv i32 %21, %19
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %22)
%24 = tail call i32 @delay_ms(i32 10)
%25 = tail call i32 @read_avg(i32 40)
%26 = mul nsw i32 %25, 1227
%27 = sdiv i32 %26, %19
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %25, i32 %27)
%29 = tail call i32 @delay_ms(i32 10)
%30 = tail call i32 @read_avg(i32 40)
%31 = mul nsw i32 %30, 1227
%32 = sdiv i32 %31, %19
%33 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
%34 = tail call i32 @delay_ms(i32 10)
%35 = tail call i32 @read_avg(i32 40)
%36 = mul nsw i32 %35, 1227
%37 = sdiv i32 %36, %19
%38 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %35, i32 %37)
%39 = tail call i32 @delay_ms(i32 10)
%40 = tail call i32 @read_avg(i32 40)
%41 = mul nsw i32 %40, 1227
%42 = sdiv i32 %41, %19
%43 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %40, i32 %42)
%44 = tail call i32 @delay_ms(i32 10)
ret void
}