unsigned int readMCP3008Channel(int channel) {
  unsigned int result = 0;
  unsigned int rbufsr = 0;
  unsigned int rbuf = 0;
  const unsigned short query = (0x18 | channel) << 11;
  (((volatile unsigned int *)(0x48000200 + 0x080)))[31] = query;
  while ((*((volatile unsigned int *const)(0x48000200 + 0x038))) & 0x80)
    ;
  (((volatile unsigned int *)(0x48000200 + 0x080)))[31] =
      (unsigned short)0x0000;
  while ((*((volatile unsigned int *const)(0x48000200 + 0x038))) & 0x80)
    ;
  rbufsr = (*((volatile unsigned int *const)(0x48000200 + 0x050)));
  if (rbufsr & ((1 << 13) | (1 << 14))) {
    while (rbufsr & ((1 << 13) | (1 << 14))) {
      (*((volatile unsigned int *const)(0x48000200 + 0x048))) = 0;
      rbuf = (*((volatile unsigned int *const)(0x48000200 + 0x054)));
      result = (result << 16) | rbuf;
      rbufsr = (*((volatile unsigned int *const)(0x48000200 + 0x050)));
    }
  }
  return result;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
or     $0x18,%eax
shl    $0xb,%eax
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%ecx
mov    $0x48000280,%eax
mov    %ecx,0x7c(%rax)
mov    $0x48000238,%eax
mov    (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     114f <readMCP3008Channel+0x4f>
jmp    1135 <readMCP3008Channel+0x35>
mov    $0x48000280,%eax
movl   $0x0,0x7c(%rax)
mov    $0x48000238,%eax
mov    (%rax),%eax
and    $0x80,%eax
cmp    $0x0,%eax
je     1175 <readMCP3008Channel+0x75>
jmp    115b <readMCP3008Channel+0x5b>
mov    $0x48000250,%eax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
and    $0x6000,%eax
cmp    $0x0,%eax
je     11db <readMCP3008Channel+0xdb>
jmp    1195 <readMCP3008Channel+0x95>
mov    -0xc(%rbp),%eax
and    $0x6000,%eax
cmp    $0x0,%eax
je     11d6 <readMCP3008Channel+0xd6>
mov    $0x48000248,%eax
movl   $0x0,(%rax)
mov    $0x48000254,%eax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x10,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x48000250,%eax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    1195 <readMCP3008Channel+0x95>
jmp    11db <readMCP3008Channel+0xdb>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
or     $0x18,%edi
shl    $0xb,%edi
movzwl %di,%eax
mov    %eax,0x480002fc
testl  $0x80,0x48000238
jne    1110 <readMCP3008Channel+0x10>
movl   $0x0,0x480002fc
nopl   0x0(%rax,%rax,1)
testl  $0x80,0x48000238
jne    1130 <readMCP3008Channel+0x30>
testl  $0x6000,0x48000250
je     1173 <readMCP3008Channel+0x73>
xor    %eax,%eax
nopl   0x0(%rax)
movl   $0x0,0x48000248
shl    $0x10,%eax
or     0x48000254,%eax
testl  $0x6000,0x48000250
jne    1150 <readMCP3008Channel+0x50>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @readMCP3008Channel(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i16
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%7 = load i32, i32* %2
%8 = or i32 24, %7
%9 = shl i32 %8, 11
%10 = trunc i32 %9 to i16
store i16 %10, i16* %6
%11 = load i16, i16* %6
%12 = zext i16 %11 to i32
store volatile i32 %12, i32* getelementptr inbounds (i32, i32* inttoptr (i64 1207960192 to i32*), i64 31)
br label %13
13: ; preds = %17, %1
%14 = load volatile i32, i32* inttoptr (i64 1207960120 to i32*)
%15 = and i32 %14, 128
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
store volatile i32 0, i32* getelementptr inbounds (i32, i32* inttoptr (i64 1207960192 to i32*), i64 31)
br label %19
19: ; preds = %23, %18
%20 = load volatile i32, i32* inttoptr (i64 1207960120 to i32*)
%21 = and i32 %20, 128
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %19
br label %19
24: ; preds = %19
%25 = load volatile i32, i32* inttoptr (i64 1207960144 to i32*)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = and i32 %26, 24576
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %24
br label %30
30: ; preds = %34, %29
%31 = load i32, i32* %4
%32 = and i32 %31, 24576
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %30
store volatile i32 0, i32* inttoptr (i64 1207960136 to i32*)
%35 = load volatile i32, i32* inttoptr (i64 1207960148 to i32*)
store i32 %35, i32* %5
%36 = load i32, i32* %3
%37 = shl i32 %36, 16
%38 = load i32, i32* %5
%39 = or i32 %37, %38
store i32 %39, i32* %3
%40 = load volatile i32, i32* inttoptr (i64 1207960144 to i32*)
store i32 %40, i32* %4
br label %30
41: ; preds = %30
br label %42
42: ; preds = %41, %24
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @readMCP3008Channel(i32 %0) {
%2 = shl i32 %0, 11
%3 = and i32 %2, 14336
%4 = or i32 %3, 49152
store volatile i32 %4, i32* inttoptr (i64 1207960316 to i32*)
br label %5
5: ; preds = %5, %1
%6 = load volatile i32, i32* inttoptr (i64 1207960120 to i32*)
%7 = and i32 %6, 128
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %5
9: ; preds = %5
store volatile i32 0, i32* inttoptr (i64 1207960316 to i32*)
br label %10
10: ; preds = %10, %9
%11 = load volatile i32, i32* inttoptr (i64 1207960120 to i32*)
%12 = and i32 %11, 128
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %10
14: ; preds = %10
%15 = load volatile i32, i32* inttoptr (i64 1207960144 to i32*)
%16 = and i32 %15, 24576
%17 = icmp eq i32 %16, 0
br i1 %17, label %26, label %18
18: ; preds = %14, %18
%19 = phi i32 [ %22, %18 ], [ 0, %14 ]
store volatile i32 0, i32* inttoptr (i64 1207960136 to i32*)
%20 = load volatile i32, i32* inttoptr (i64 1207960148 to i32*)
%21 = shl i32 %19, 16
%22 = or i32 %20, %21
%23 = load volatile i32, i32* inttoptr (i64 1207960144 to i32*)
%24 = and i32 %23, 24576
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %18
26: ; preds = %18, %14
%27 = phi i32 [ 0, %14 ], [ %22, %18 ]
ret i32 %27
}