#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ bootloader_gpio_write(int, int);
int /*<<< orphan*/ bootloader_spi_transac8(int /*<<< orphan*/, int, void *,
                                           int *);
__attribute__((section(".boot.text"))) void
bootloader_spiflash_waitcomplete(uint32_t spidev) {
  uint8_t cmd[1];
  cmd[0] = 0x05;
  bootloader_gpio_write(
      (0 << 4) | (9 << 0) | (1 << 12) | (0 << 18) | (2 << 16) | (1 << 19), 0);
  bootloader_spi_transac8(spidev, 1, cmd, ((void *)0));
  do {
    bootloader_spi_transac8(spidev, 1, ((void *)0), cmd);
  } while (cmd[0] & 0x01);
  bootloader_gpio_write(
      (0 << 4) | (9 << 0) | (1 << 12) | (0 << 18) | (2 << 16) | (1 << 19), 1);
}


x86 assembly (clang, -O0):
<bootloader_spiflash_waitcomplete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x5,-0x8(%rbp)
mov    $0xa1009,%edi
xor    %esi,%esi
call   1040 <bootloader_gpio_write@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rdx
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <bootloader_spi_transac8@plt>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rcx
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <bootloader_spi_transac8@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1153 <bootloader_spiflash_waitcomplete+0x33>
mov    $0xa1009,%edi
mov    $0x1,%esi
call   1040 <bootloader_gpio_write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bootloader_spiflash_waitcomplete>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x5,0x4(%rsp)
mov    $0xa1009,%edi
xor    %esi,%esi
call   1040 <bootloader_gpio_write@plt>
lea    0x4(%rsp),%r14
mov    %ebx,%edi
mov    $0x1,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1030 <bootloader_spi_transac8@plt>
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
mov    %r14,%rcx
call   1030 <bootloader_spi_transac8@plt>
testb  $0x1,0x4(%rsp)
jne    1150 <bootloader_spiflash_waitcomplete+0x30>
mov    $0xa1009,%edi
mov    $0x1,%esi
call   1040 <bootloader_gpio_write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @bootloader_spiflash_waitcomplete(i32 %0) section ".boot.text" {
%2 = alloca i32
%3 = alloca [1 x i32]
store i32 %0, i32* %2
%4 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 5, i32* %4
%5 = call i32 @bootloader_gpio_write(i32 659465, i32 0)
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%8 = bitcast i32* %7 to i8*
%9 = call i32 @bootloader_spi_transac8(i32 %6, i32 1, i8* %8, i32* null)
br label %10
10: ; preds = %14, %1
%11 = load i32, i32* %2
%12 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%13 = call i32 @bootloader_spi_transac8(i32 %11, i32 1, i8* null, i32* %12)
br label %14
14: ; preds = %10
%15 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %15
%17 = and i32 %16, 1
%18 = icmp ne i32 %17, 0
br i1 %18, label %10, label %19
19: ; preds = %14
%20 = call i32 @bootloader_gpio_write(i32 659465, i32 1)
ret void
}

LLVM IR (-O2):
define void @bootloader_spiflash_waitcomplete(i32 %0) section ".boot.text" {
%2 = alloca [1 x i32]
%3 = bitcast [1 x i32]* %2 to i8*
%4 = getelementptr inbounds [1 x i32], [1 x i32]* %2, i64 0, i64 0
store i32 5, i32* %4
%5 = tail call i32 @bootloader_gpio_write(i32 659465, i32 0)
%6 = call i32 @bootloader_spi_transac8(i32 %0, i32 1, i8* %3, i32* null)
br label %7
7: ; preds = %7, %1
%8 = call i32 @bootloader_spi_transac8(i32 %0, i32 1, i8* null, i32* %4)
%9 = load i32, i32* %4
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %7
12: ; preds = %7
%13 = call i32 @bootloader_gpio_write(i32 659465, i32 1)
ret void
}