#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*/ uart_print_hex(unsigned int);
int /*<<< orphan*/ uart_printf(char *);
int /*<<< orphan*/ uart_puts(char *);
void nand_read_ID(void) {
  (*(volatile unsigned int *)(0x70200004)) &= ~2;
  (*(volatile unsigned int *)(0x70200008)) = 0x90;
  (*(volatile unsigned int *)(0x7020000C)) = 0;
  while (1) {
    if ((*(volatile unsigned int *)(0x70200028)) & 1)
      break;
  }
  unsigned int data[3];
  data[0] = (*(volatile unsigned int *)(0x70200010));
  data[1] = (*(volatile unsigned int *)(0x70200010));
  data[2] = (*(volatile unsigned int *)(0x70200010));
  (*(volatile unsigned int *)(0x70200004)) |= 2;
  uart_printf("The ID is: ");
  uart_print_hex(data[2]);
  uart_print_hex(data[1]);
  uart_print_hex(data[0]);
  uart_puts("");
  return;
}


x86 assembly (clang, -O0):
<nand_read_ID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x70200004,%eax
mov    (%rax),%ecx
and    $0xfffffffd,%ecx
mov    $0x70200004,%eax
mov    %ecx,(%rax)
mov    $0x70200008,%eax
movl   $0x90,(%rax)
mov    $0x7020000c,%eax
movl   $0x0,(%rax)
mov    $0x70200028,%eax
mov    (%rax),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1177 <nand_read_ID+0x47>
jmp    117c <nand_read_ID+0x4c>
jmp    115f <nand_read_ID+0x2f>
mov    $0x70200010,%eax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x70200010,%eax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    $0x70200010,%eax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    $0x70200004,%eax
mov    (%rax),%ecx
or     $0x2,%ecx
mov    $0x70200004,%eax
mov    %ecx,(%rax)
lea    0xe4e(%rip),%rdi
call   1030 <uart_printf@plt>
mov    -0x4(%rbp),%edi
call   1040 <uart_print_hex@plt>
mov    -0x8(%rbp),%edi
call   1040 <uart_print_hex@plt>
mov    -0xc(%rbp),%edi
call   1040 <uart_print_hex@plt>
lea    0xe35(%rip),%rdi
call   1050 <uart_puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_read_ID>:
push   %rbp
push   %r14
push   %rbx
andl   $0xfffffffd,0x70200004
fd
movl   $0x90,0x70200008
movl   $0x0,0x7020000c
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
testl  $0x1,0x70200028
je     1160 <nand_read_ID+0x30>
mov    0x70200010,%r14d
70
mov    0x70200010,%ebp
mov    0x70200010,%ebx
orl    $0x2,0x70200004
02
lea    0xe6e(%rip),%rdi
call   1030 <uart_printf@plt>
mov    %ebx,%edi
call   1040 <uart_print_hex@plt>
mov    %ebp,%edi
call   1040 <uart_print_hex@plt>
mov    %r14d,%edi
call   1040 <uart_print_hex@plt>
lea    0xe57(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <uart_puts@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"The ID is: \00"
@.str.1 = [1 x i8] zeroinitializer
define void @nand_read_ID() {
%1 = alloca [3 x i32]
%2 = load volatile i32, i32* inttoptr (i64 1881145348 to i32*)
%3 = and i32 %2, -3
store volatile i32 %3, i32* inttoptr (i64 1881145348 to i32*)
store volatile i32 144, i32* inttoptr (i64 1881145352 to i32*)
store volatile i32 0, i32* inttoptr (i64 1881145356 to i32*)
br label %4
4: ; preds = %0, %9
%5 = load volatile i32, i32* inttoptr (i64 1881145384 to i32*)
%6 = and i32 %5, 1
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
br label %10
9: ; preds = %4
br label %4
10: ; preds = %8
%11 = load volatile i32, i32* inttoptr (i64 1881145360 to i32*)
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
store i32 %11, i32* %12
%13 = load volatile i32, i32* inttoptr (i64 1881145360 to i32*)
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
store i32 %13, i32* %14
%15 = load volatile i32, i32* inttoptr (i64 1881145360 to i32*)
%16 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
store i32 %15, i32* %16
%17 = load volatile i32, i32* inttoptr (i64 1881145348 to i32*)
%18 = or i32 %17, 2
store volatile i32 %18, i32* inttoptr (i64 1881145348 to i32*)
%19 = call i32 @uart_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 2
%21 = load i32, i32* %20
%22 = call i32 @uart_print_hex(i32 %21)
%23 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @uart_print_hex(i32 %24)
%26 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @uart_print_hex(i32 %27)
%29 = call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"The ID is: \00"
@.str.1 = [1 x i8] zeroinitializer
define void @nand_read_ID() {
%1 = load volatile i32, i32* inttoptr (i64 1881145348 to i32*)
%2 = and i32 %1, -3
store volatile i32 %2, i32* inttoptr (i64 1881145348 to i32*)
store volatile i32 144, i32* inttoptr (i64 1881145352 to i32*)
store volatile i32 0, i32* inttoptr (i64 1881145356 to i32*)
br label %3
3: ; preds = %3, %0
%4 = load volatile i32, i32* inttoptr (i64 1881145384 to i32*)
%5 = and i32 %4, 1
%6 = icmp eq i32 %5, 0
br i1 %6, label %3, label %7
7: ; preds = %3
%8 = load volatile i32, i32* inttoptr (i64 1881145360 to i32*)
%9 = load volatile i32, i32* inttoptr (i64 1881145360 to i32*)
%10 = load volatile i32, i32* inttoptr (i64 1881145360 to i32*)
%11 = load volatile i32, i32* inttoptr (i64 1881145348 to i32*)
%12 = or i32 %11, 2
store volatile i32 %12, i32* inttoptr (i64 1881145348 to i32*)
%13 = tail call i32 @uart_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @uart_print_hex(i32 %10)
%15 = tail call i32 @uart_print_hex(i32 %9)
%16 = tail call i32 @uart_print_hex(i32 %8)
%17 = tail call i32 @uart_puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
ret void
}