#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*/ clean_RnB();
int /*<<< orphan*/ delselect_ship();
int /*<<< orphan*/ nand_addr(int);
int /*<<< orphan*/ nand_cmd(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ select_ship();
int /*<<< orphan*/ wait_RnB();
int nand_readid(void) {
  int id;
  select_ship();
  clean_RnB();
  nand_cmd(0x90);
  nand_addr(0x00);
  nand_addr(0x00);
  wait_RnB();
  id = (*((volatile unsigned char *)0x70200010));
  printf("first bytes = 0x%02x\n", id);
  id = (*((volatile unsigned char *)0x70200010));
  printf("second bytes = 0x%02x\n", id);
  id = (*((volatile unsigned char *)0x70200010));
  printf("three bytes = 0x%02x\n", id);
  id = (*((volatile unsigned char *)0x70200010));
  printf("four bytes = 0x%02x\n", id);
  id = (*((volatile unsigned char *)0x70200010));
  printf("five bytes = 0x%02x\n", id);
  delselect_ship();
  return 0;
}


x86 assembly (clang, -O0):
<nand_readid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <select_ship@plt>
mov    $0x0,%al
call   1030 <clean_RnB@plt>
mov    $0x90,%edi
call   1080 <nand_cmd@plt>
xor    %edi,%edi
call   1070 <nand_addr@plt>
xor    %edi,%edi
call   1070 <nand_addr@plt>
mov    $0x0,%al
call   1090 <wait_RnB@plt>
mov    $0x70200010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe44(%rip),%rdi
call   1050 <printf@plt>
mov    $0x70200010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
mov    $0x70200010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe39(%rip),%rdi
call   1050 <printf@plt>
mov    $0x70200010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe33(%rip),%rdi
call   1050 <printf@plt>
mov    $0x70200010,%eax
mov    (%rax),%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1060 <delselect_ship@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nand_readid>:
push   %rax
xor    %eax,%eax
call   1040 <select_ship@plt>
xor    %eax,%eax
call   1030 <clean_RnB@plt>
mov    $0x90,%edi
call   1080 <nand_cmd@plt>
xor    %edi,%edi
call   1070 <nand_addr@plt>
xor    %edi,%edi
call   1070 <nand_addr@plt>
xor    %eax,%eax
call   1090 <wait_RnB@plt>
movzbl 0x70200010,%esi
70
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
movzbl 0x70200010,%esi
70
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
movzbl 0x70200010,%esi
70
lea    0xe58(%rip),%rdi
call   1050 <printf@plt>
movzbl 0x70200010,%esi
70
lea    0xe5a(%rip),%rdi
call   1050 <printf@plt>
movzbl 0x70200010,%esi
70
lea    0xe5b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <delselect_ship@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [22 x i8] c"first bytes = 0x%02x\0A\00"
@.str.1 = [23 x i8] c"second bytes = 0x%02x\0A\00"
@.str.2 = [22 x i8] c"three bytes = 0x%02x\0A\00"
@.str.3 = [21 x i8] c"four bytes = 0x%02x\0A\00"
@.str.4 = [21 x i8] c"five bytes = 0x%02x\0A\00"
define i32 @nand_readid() {
%1 = alloca i32
%2 = call i32 (...) @select_ship()
%3 = call i32 (...) @clean_RnB()
%4 = call i32 @nand_cmd(i32 144)
%5 = call i32 @nand_addr(i32 0)
%6 = call i32 @nand_addr(i32 0)
%7 = call i32 (...) @wait_RnB()
%8 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%9 = zext i8 %8 to i32
store i32 %9, i32* %1
%10 = load i32, i32* %1
%11 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%13 = zext i8 %12 to i32
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%17 = zext i8 %16 to i32
store i32 %17, i32* %1
%18 = load i32, i32* %1
%19 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%21 = zext i8 %20 to i32
store i32 %21, i32* %1
%22 = load i32, i32* %1
%23 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %22)
%24 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%25 = zext i8 %24 to i32
store i32 %25, i32* %1
%26 = load i32, i32* %1
%27 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %26)
%28 = call i32 (...) @delselect_ship()
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"first bytes = 0x%02x\0A\00"
@.str.1 = [23 x i8] c"second bytes = 0x%02x\0A\00"
@.str.2 = [22 x i8] c"three bytes = 0x%02x\0A\00"
@.str.3 = [21 x i8] c"four bytes = 0x%02x\0A\00"
@.str.4 = [21 x i8] c"five bytes = 0x%02x\0A\00"
define i32 @nand_readid() {
%1 = tail call i32 (...) @select_ship()
%2 = tail call i32 (...) @clean_RnB()
%3 = tail call i32 @nand_cmd(i32 144)
%4 = tail call i32 @nand_addr(i32 0)
%5 = tail call i32 @nand_addr(i32 0)
%6 = tail call i32 (...) @wait_RnB()
%7 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%8 = zext i8 %7 to i32
%9 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%11 = zext i8 %10 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%14 = zext i8 %13 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%17 = zext i8 %16 to i32
%18 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = load volatile i8, i8* inttoptr (i64 1881145360 to i8*)
%20 = zext i8 %19 to i32
%21 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %20)
%22 = tail call i32 (...) @delselect_ship()
ret i32 0
}