#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 long PEEK32(unsigned long);
int /*<<< orphan*/ POKE32(unsigned long, unsigned short);
scalar_t__ is_ADC_busy(unsigned long);
int read_channel(unsigned long adc_page, unsigned short channel) {
  unsigned long val;
  POKE32(adc_page + 0x0020, 0xAA);
  POKE32(adc_page + 0x0018, channel);
  while (is_ADC_busy(adc_page))
    ;
  val = PEEK32(adc_page + 0x0008);
  val = val & 0xFFFF;
  return val;
}


x86 assembly (clang, -O0):
<read_channel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x20,%rdi
mov    $0xaa,%esi
call   1050 <POKE32@plt>
mov    -0x8(%rbp),%rdi
add    $0x18,%rdi
movzwl -0xa(%rbp),%esi
call   1050 <POKE32@plt>
mov    -0x8(%rbp),%rdi
call   1040 <is_ADC_busy@plt>
cmp    $0x0,%rax
je     117e <read_channel+0x4e>
jmp    1166 <read_channel+0x36>
mov    -0x8(%rbp),%rdi
add    $0x8,%rdi
call   1030 <PEEK32@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
and    $0xffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_channel>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
add    $0x20,%rdi
mov    $0xaa,%esi
call   1050 <POKE32@plt>
lea    0x18(%rbx),%rdi
mov    %ebp,%esi
call   1050 <POKE32@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <is_ADC_busy@plt>
test   %rax,%rax
jne    1160 <read_channel+0x30>
add    $0x8,%rbx
mov    %rbx,%rdi
call   1030 <PEEK32@plt>
movzwl %ax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_channel(i64 %0, i16 zeroext %1) {
%3 = alloca i64
%4 = alloca i16
%5 = alloca i64
store i64 %0, i64* %3
store i16 %1, i16* %4
%6 = load i64, i64* %3
%7 = add i64 %6, 32
%8 = call i32 @POKE32(i64 %7, i16 zeroext 170)
%9 = load i64, i64* %3
%10 = add i64 %9, 24
%11 = load i16, i16* %4
%12 = call i32 @POKE32(i64 %10, i16 zeroext %11)
br label %13
13: ; preds = %17, %2
%14 = load i64, i64* %3
%15 = call i64 @is_ADC_busy(i64 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = load i64, i64* %3
%20 = add i64 %19, 8
%21 = call i64 @PEEK32(i64 %20)
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = and i64 %22, 65535
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = trunc i64 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
define i32 @read_channel(i64 %0, i16 zeroext %1) {
%3 = add i64 %0, 32
%4 = tail call i32 @POKE32(i64 %3, i16 zeroext 170)
%5 = add i64 %0, 24
%6 = tail call i32 @POKE32(i64 %5, i16 zeroext %1)
br label %7
7: ; preds = %7, %2
%8 = tail call i64 @is_ADC_busy(i64 %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %7
10: ; preds = %7
%11 = add i64 %0, 8
%12 = tail call i64 @PEEK32(i64 %11)
%13 = trunc i64 %12 to i32
%14 = and i32 %13, 65535
ret i32 %14
}