#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, int *,
                                           void *);
__attribute__((section(".boot.text"))) void
bootloader_spiflash_reset(uint32_t spidev) {
  uint8_t cmd[1];
  volatile int i;
  cmd[0] = 0x66;
  bootloader_gpio_write(
      (0 << 4) | (9 << 0) | (1 << 12) | (0 << 18) | (2 << 16) | (1 << 19), 0);
  bootloader_spi_transac8(spidev, 1, cmd, ((void *)0));
  bootloader_gpio_write(
      (0 << 4) | (9 << 0) | (1 << 12) | (0 << 18) | (2 << 16) | (1 << 19), 1);
  for (i = 0; i < 1000; i++) {
  }
  cmd[0] = 0x99;
  bootloader_gpio_write(
      (0 << 4) | (9 << 0) | (1 << 12) | (0 << 18) | (2 << 16) | (1 << 19), 0);
  bootloader_spi_transac8(spidev, 1, cmd, ((void *)0));
  bootloader_gpio_write(
      (0 << 4) | (9 << 0) | (1 << 12) | (0 << 18) | (2 << 16) | (1 << 19), 1);
}


x86 assembly (clang, -O0):
<bootloader_spiflash_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x66,-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    $0xa1009,%edi
mov    $0x1,%esi
call   1040 <bootloader_gpio_write@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    $0x3e8,%eax
jge    118a <bootloader_spiflash_reset+0x6a>
jmp    117c <bootloader_spiflash_reset+0x5c>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <bootloader_spiflash_reset+0x49>
movl   $0x99,-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    $0xa1009,%edi
mov    $0x1,%esi
call   1040 <bootloader_gpio_write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bootloader_spiflash_reset>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movl   $0x66,0xc(%rsp)
mov    $0xa1009,%edi
xor    %esi,%esi
call   1040 <bootloader_gpio_write@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   1030 <bootloader_spi_transac8@plt>
mov    $0xa1009,%edi
mov    $0x1,%esi
call   1040 <bootloader_gpio_write@plt>
movl   $0x0,0x8(%rsp)
mov    0x8(%rsp),%eax
cmp    $0x3e7,%eax
jg     1180 <bootloader_spiflash_reset+0x60>
addl   $0x1,0x8(%rsp)
mov    0x8(%rsp),%eax
cmp    $0x3e8,%eax
jl     1170 <bootloader_spiflash_reset+0x50>
movl   $0x99,0xc(%rsp)
mov    $0xa1009,%edi
xor    %esi,%esi
call   1040 <bootloader_gpio_write@plt>
lea    0xc(%rsp),%rdx
mov    %ebx,%edi
mov    $0x1,%esi
xor    %ecx,%ecx
call   1030 <bootloader_spi_transac8@plt>
mov    $0xa1009,%edi
mov    $0x1,%esi
call   1040 <bootloader_gpio_write@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @bootloader_spiflash_reset(i32 %0) section ".boot.text" {
%2 = alloca i32
%3 = alloca [1 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 102, i32* %5
%6 = call i32 @bootloader_gpio_write(i32 659465, i32 0)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%9 = call i32 @bootloader_spi_transac8(i32 %7, i32 1, i32* %8, i8* null)
%10 = call i32 @bootloader_gpio_write(i32 659465, i32 1)
store volatile i32 0, i32* %4
br label %11
11: ; preds = %15, %1
%12 = load volatile i32, i32* %4
%13 = icmp slt i32 %12, 1000
br i1 %13, label %14, label %18
14: ; preds = %11
br label %15
15: ; preds = %14
%16 = load volatile i32, i32* %4
%17 = add nsw i32 %16, 1
store volatile i32 %17, i32* %4
br label %11
18: ; preds = %11
%19 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
store i32 153, i32* %19
%20 = call i32 @bootloader_gpio_write(i32 659465, i32 0)
%21 = load i32, i32* %2
%22 = getelementptr inbounds [1 x i32], [1 x i32]* %3, i64 0, i64 0
%23 = call i32 @bootloader_spi_transac8(i32 %21, i32 1, i32* %22, i8* null)
%24 = call i32 @bootloader_gpio_write(i32 659465, i32 1)
ret void
}

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