unsigned char flash_readcommand(unsigned int flashaddress) {
  unsigned int datatosend;
  unsigned int flashcommand = 0xF0000000;
  unsigned int readbyte = 0;
  datatosend = flashcommand | (flashaddress << 9);
  *(volatile unsigned int *)0xCC006814 = 0x0;
  *(volatile unsigned int *)0xCC006814 = 0x000000C0;
  *(volatile unsigned int *)0xCC006824 = datatosend;
  *(volatile unsigned int *)0xCC006820 = 0x35;
  while ((*(volatile unsigned int *)0xCC006820) & 1)
    ;
  *(volatile unsigned int *)0xCC006814 = 0x000000C0;
  *(volatile unsigned int *)0xCC006820 = 0x39;
  while ((*(volatile unsigned int *)0xCC006820) & 1)
    ;
  readbyte = *(volatile unsigned int *)0xCC006824 << 1;
  *(volatile unsigned int *)0xCC006814 = 0x0;
  return ((readbyte >> 24) & 0xff);
}


x86 assembly (clang, -O0):
<flash_readcommand>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0xf0000000,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x4(%rbp),%ecx
shl    $0x9,%ecx
or     %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    $0xcc006814,%eax
movl   $0x0,(%rax)
mov    $0xcc006814,%eax
movl   $0xc0,(%rax)
mov    -0x8(%rbp),%ecx
mov    $0xcc006824,%eax
mov    %ecx,(%rax)
mov    $0xcc006820,%eax
movl   $0x35,(%rax)
mov    $0xcc006820,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1166 <flash_readcommand+0x66>
jmp    114e <flash_readcommand+0x4e>
mov    $0xcc006814,%eax
movl   $0xc0,(%rax)
mov    $0xcc006820,%eax
movl   $0x39,(%rax)
mov    $0xcc006820,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1194 <flash_readcommand+0x94>
jmp    117c <flash_readcommand+0x7c>
mov    $0xcc006824,%eax
mov    (%rax),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    $0xcc006814,%eax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
movzbl %al,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<flash_readcommand>:
mov    $0xcc006814,%ecx
shl    $0x9,%edi
or     $0xf0000000,%edi
movl   $0x0,(%rcx)
movl   $0xc0,(%rcx)
mov    %edi,0x10(%rcx)
movl   $0x35,0xc(%rcx)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rcx),%eax
test   $0x1,%al
jne    1130 <flash_readcommand+0x30>
movl   $0xc0,(%rcx)
movl   $0x39,0xc(%rcx)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0xc(%rcx),%eax
test   $0x1,%al
jne    1150 <flash_readcommand+0x50>
mov    0x10(%rcx),%eax
movl   $0x0,(%rcx)
shr    $0x17,%eax
ret

LLVM IR (-O0):
define zeroext i8 @flash_readcommand(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 -268435456, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = load i32, i32* %2
%8 = shl i32 %7, 9
%9 = or i32 %6, %8
store i32 %9, i32* %3
store volatile i32 0, i32* inttoptr (i64 3422578708 to i32*)
store volatile i32 192, i32* inttoptr (i64 3422578708 to i32*)
%10 = load i32, i32* %3
store volatile i32 %10, i32* inttoptr (i64 3422578724 to i32*)
store volatile i32 53, i32* inttoptr (i64 3422578720 to i32*)
br label %11
11: ; preds = %15, %1
%12 = load volatile i32, i32* inttoptr (i64 3422578720 to i32*)
%13 = and i32 %12, 1
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %11
16: ; preds = %11
store volatile i32 192, i32* inttoptr (i64 3422578708 to i32*)
store volatile i32 57, i32* inttoptr (i64 3422578720 to i32*)
br label %17
17: ; preds = %21, %16
%18 = load volatile i32, i32* inttoptr (i64 3422578720 to i32*)
%19 = and i32 %18, 1
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %17
22: ; preds = %17
%23 = load volatile i32, i32* inttoptr (i64 3422578724 to i32*)
%24 = shl i32 %23, 1
store i32 %24, i32* %5
store volatile i32 0, i32* inttoptr (i64 3422578708 to i32*)
%25 = load i32, i32* %5
%26 = lshr i32 %25, 24
%27 = and i32 %26, 255
%28 = trunc i32 %27 to i8
ret i8 %28
}

LLVM IR (-O2):
define zeroext i8 @flash_readcommand(i32 %0) {
%2 = shl i32 %0, 9
%3 = or i32 %2, -268435456
store volatile i32 0, i32* inttoptr (i64 3422578708 to i32*)
store volatile i32 192, i32* inttoptr (i64 3422578708 to i32*)
store volatile i32 %3, i32* inttoptr (i64 3422578724 to i32*)
store volatile i32 53, i32* inttoptr (i64 3422578720 to i32*)
br label %4
4: ; preds = %4, %1
%5 = load volatile i32, i32* inttoptr (i64 3422578720 to i32*)
%6 = and i32 %5, 1
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %4
8: ; preds = %4
store volatile i32 192, i32* inttoptr (i64 3422578708 to i32*)
store volatile i32 57, i32* inttoptr (i64 3422578720 to i32*)
br label %9
9: ; preds = %9, %8
%10 = load volatile i32, i32* inttoptr (i64 3422578720 to i32*)
%11 = and i32 %10, 1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %9
13: ; preds = %9
%14 = load volatile i32, i32* inttoptr (i64 3422578724 to i32*)
store volatile i32 0, i32* inttoptr (i64 3422578708 to i32*)
%15 = lshr i32 %14, 23
%16 = trunc i32 %15 to i8
ret i8 %16
}