unsigned int ADC0Read(unsigned char channelNum) {
  unsigned int regVal, ADC_Data;
  volatile unsigned int timeout = 0;
  if (channelNum >= 8) {
    channelNum = 0;
  }
  (*(volatile unsigned long *)(0xE0034000 + 0x00)) &= 0xFFFFFF00;
  (*(volatile unsigned long *)(0xE0034000 + 0x00)) |=
      (1 << 24) | (1 << channelNum);
  while (timeout++ < 5000) {
    regVal = *(volatile unsigned long *)(0xE0034000 + 0x10 + 4 * channelNum);
    if (regVal & 0x80000000) {
      break;
    }
  }
  (*(volatile unsigned long *)(0xE0034000 + 0x00)) &= 0xF8FFFFFF;
  if (regVal & 0x40000000) {
    return (0);
  }
  ADC_Data = (regVal >> 6) & 0x3FF;
  return (ADC_Data);
}


x86 assembly (clang, -O0):
<ADC0Read>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x5(%rbp)
movl   $0x0,-0x14(%rbp)
movzbl -0x5(%rbp),%eax
cmp    $0x8,%eax
jl     1122 <ADC0Read+0x22>
movb   $0x0,-0x5(%rbp)
mov    $0xe0034000,%eax
mov    (%rax),%rcx
movabs $0xffffff00,%rax
and    %rax,%rcx
mov    $0xe0034000,%eax
mov    %rcx,(%rax)
movzbl -0x5(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
or     $0x1000000,%eax
cltq
mov    $0xe0034000,%ecx
mov    (%rcx),%rcx
or     %rax,%rcx
mov    $0xe0034000,%eax
mov    %rcx,(%rax)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x1388,%eax
jae    11a9 <ADC0Read+0xa9>
movzbl -0x5(%rbp),%eax
shl    $0x2,%eax
add    $0xe0034010,%eax
mov    %eax,%eax
mov    (%rax),%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x80000000,%eax
cmp    $0x0,%eax
je     11a4 <ADC0Read+0xa4>
jmp    11a9 <ADC0Read+0xa9>
jmp    1164 <ADC0Read+0x64>
mov    $0xe0034000,%eax
mov    (%rax),%rcx
movabs $0xf8ffffff,%rax
and    %rax,%rcx
mov    $0xe0034000,%eax
mov    %rcx,(%rax)
mov    -0xc(%rbp),%eax
and    $0x40000000,%eax
cmp    $0x0,%eax
je     11e3 <ADC0Read+0xe3>
movl   $0x0,-0x4(%rbp)
jmp    11f7 <ADC0Read+0xf7>
mov    -0xc(%rbp),%eax
shr    $0x6,%eax
and    $0x3ff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ADC0Read>:
mov    $0xe0034000,%r8d
movl   $0x0,-0x4(%rsp)
xor    %eax,%eax
cmp    $0x8,%dil
cmovae %eax,%edi
mov    $0xffffff00,%edx
and    %rdx,(%r8)
mov    $0x1000000,%edx
bts    %edi,%edx
movslq %edx,%rdx
or     %rdx,(%r8)
mov    -0x4(%rsp),%esi
lea    0x1(%rsi),%edx
mov    %edx,-0x4(%rsp)
cmp    $0x1387,%esi
ja     116f <ADC0Read+0x6f>
mov    $0xe0034010,%r9d
cs nopw 0x0(%rax,%rax,1)
mov    (%r9,%rdi,4),%rdx
test   $0x80000000,%edx
jne    116f <ADC0Read+0x6f>
mov    -0x4(%rsp),%ecx
lea    0x1(%rcx),%esi
mov    %esi,-0x4(%rsp)
cmp    $0x1387,%ecx
jbe    1150 <ADC0Read+0x50>
mov    $0xf8ffffff,%ecx
and    %rcx,(%r8)
mov    %edx,%ecx
shr    $0x6,%ecx
and    $0x3ff,%ecx
test   $0x40000000,%edx
cmove  %ecx,%eax
ret

LLVM IR (-O0):
define i32 @ADC0Read(i8 zeroext %0) {
%2 = alloca i32
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8 %0, i8* %3
store volatile i32 0, i32* %6
%7 = load i8, i8* %3
%8 = zext i8 %7 to i32
%9 = icmp sge i32 %8, 8
br i1 %9, label %10, label %11
10: ; preds = %1
store i8 0, i8* %3
br label %11
11: ; preds = %10, %1
%12 = load volatile i64, i64* inttoptr (i64 3758309376 to i64*)
%13 = and i64 %12, 4294967040
store volatile i64 %13, i64* inttoptr (i64 3758309376 to i64*)
%14 = load i8, i8* %3
%15 = zext i8 %14 to i32
%16 = shl i32 1, %15
%17 = or i32 16777216, %16
%18 = sext i32 %17 to i64
%19 = load volatile i64, i64* inttoptr (i64 3758309376 to i64*)
%20 = or i64 %19, %18
store volatile i64 %20, i64* inttoptr (i64 3758309376 to i64*)
br label %21
21: ; preds = %38, %11
%22 = load volatile i32, i32* %6
%23 = add i32 %22, 1
store volatile i32 %23, i32* %6
%24 = icmp ult i32 %22, 5000
br i1 %24, label %25, label %39
25: ; preds = %21
%26 = load i8, i8* %3
%27 = zext i8 %26 to i32
%28 = mul nsw i32 4, %27
%29 = add i32 -536657904, %28
%30 = zext i32 %29 to i64
%31 = inttoptr i64 %30 to i64*
%32 = load volatile i64, i64* %31
%33 = trunc i64 %32 to i32
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = and i32 %34, -2147483648
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %38
37: ; preds = %25
br label %39
38: ; preds = %25
br label %21
39: ; preds = %37, %21
%40 = load volatile i64, i64* inttoptr (i64 3758309376 to i64*)
%41 = and i64 %40, 4177526783
store volatile i64 %41, i64* inttoptr (i64 3758309376 to i64*)
%42 = load i32, i32* %4
%43 = and i32 %42, 1073741824
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
store i32 0, i32* %2
br label %51
46: ; preds = %39
%47 = load i32, i32* %4
%48 = lshr i32 %47, 6
%49 = and i32 %48, 1023
store i32 %49, i32* %5
%50 = load i32, i32* %5
store i32 %50, i32* %2
br label %51
51: ; preds = %46, %45
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
define i32 @ADC0Read(i8 zeroext %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store volatile i32 0, i32* %2
%4 = icmp ugt i8 %0, 7
%5 = select i1 %4, i8 0, i8 %0
%6 = load volatile i64, i64* inttoptr (i64 3758309376 to i64*)
%7 = and i64 %6, 4294967040
store volatile i64 %7, i64* inttoptr (i64 3758309376 to i64*)
%8 = zext i8 %5 to i32
%9 = shl nuw nsw i32 1, %8
%10 = or i32 %9, 16777216
%11 = sext i32 %10 to i64
%12 = load volatile i64, i64* inttoptr (i64 3758309376 to i64*)
%13 = or i64 %12, %11
store volatile i64 %13, i64* inttoptr (i64 3758309376 to i64*)
%14 = shl nuw nsw i32 %8, 2
%15 = add nuw nsw i32 %14, -536657904
%16 = zext i32 %15 to i64
%17 = inttoptr i64 %16 to i64*
%18 = load volatile i32, i32* %2
%19 = add i32 %18, 1
store volatile i32 %19, i32* %2
%20 = icmp ult i32 %18, 5000
br i1 %20, label %25, label %31
21: ; preds = %25
%22 = load volatile i32, i32* %2
%23 = add i32 %22, 1
store volatile i32 %23, i32* %2
%24 = icmp ult i32 %22, 5000
br i1 %24, label %25, label %29
25: ; preds = %1, %21
%26 = load volatile i64, i64* %17
%27 = and i64 %26, 2147483648
%28 = icmp eq i64 %27, 0
br i1 %28, label %21, label %29
29: ; preds = %25, %21
%30 = trunc i64 %26 to i32
br label %31
31: ; preds = %29, %1
%32 = phi i32 [ undef, %1 ], [ %30, %29 ]
%33 = load volatile i64, i64* inttoptr (i64 3758309376 to i64*)
%34 = and i64 %33, 4177526783
store volatile i64 %34, i64* inttoptr (i64 3758309376 to i64*)
%35 = and i32 %32, 1073741824
%36 = icmp eq i32 %35, 0
%37 = lshr i32 %32, 6
%38 = and i32 %37, 1023
%39 = select i1 %36, i32 %38, i32 0
ret i32 %39
}