#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 cmd_write(int, int);
int /*<<< orphan*/ spi_spin();
int wait_initV2() {
  int i = 2000;
  int r;
  spi_spin();
  while (--i) {
    if ((r = cmd_write(0xff0077, 0)) == 1) {
      *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
      if ((r = cmd_write(0x870069, 0x40000000)) == 0) {
        *(volatile unsigned int *)(0xFFFFFFD0 + 0x04) = (0xff);
        return (1);
      }
      spi_spin();
    }
  }
  return (0);
}


x86 assembly (clang, -O0):
<wait_initV2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x7d0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <spi_spin@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     11a9 <wait_initV2+0x89>
mov    $0xff0077,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x1,%eax
jne    11a4 <wait_initV2+0x84>
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    $0x870069,%edi
mov    $0x40000000,%esi
call   1040 <cmd_write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    119d <wait_initV2+0x7d>
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b0 <wait_initV2+0x90>
mov    $0x0,%al
call   1030 <spi_spin@plt>
jmp    1136 <wait_initV2+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_initV2>:
push   %rbp
push   %rbx
push   %rax
mov    $0xffffffd4,%ebx
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xfffff831,%ebp
jmp    1144 <wait_initV2+0x24>
cs nopw 0x0(%rax,%rax,1)
inc    %ebp
je     1177 <wait_initV2+0x57>
mov    $0xff0077,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
cmp    $0x1,%eax
jne    1140 <wait_initV2+0x20>
movl   $0xff,(%rbx)
mov    $0x870069,%edi
mov    $0x40000000,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     117b <wait_initV2+0x5b>
xor    %eax,%eax
call   1030 <spi_spin@plt>
jmp    1140 <wait_initV2+0x20>
xor    %eax,%eax
jmp    1186 <wait_initV2+0x66>
movl   $0xff,(%rbx)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @wait_initV2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 2000, i32* %2
%4 = call i32 (...) @spi_spin()
br label %5
5: ; preds = %18, %0
%6 = load i32, i32* %2
%7 = add nsw i32 %6, -1
store i32 %7, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %5
%10 = call i32 @cmd_write(i32 16711799, i32 0)
store i32 %10, i32* %3
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %18
12: ; preds = %9
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%13 = call i32 @cmd_write(i32 8847465, i32 1073741824)
store i32 %13, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
store i32 1, i32* %1
br label %20
16: ; preds = %12
%17 = call i32 (...) @spi_spin()
br label %18
18: ; preds = %16, %9
br label %5
19: ; preds = %5
store i32 0, i32* %1
br label %20
20: ; preds = %19, %15
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
define i32 @wait_initV2() {
%1 = tail call i32 (...) @spi_spin()
br label %2
2: ; preds = %0, %12
%3 = phi i32 [ 1999, %0 ], [ %13, %12 ]
%4 = tail call i32 @cmd_write(i32 16711799, i32 0)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %12
6: ; preds = %2
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%7 = tail call i32 @cmd_write(i32 8847465, i32 1073741824)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
br label %15
10: ; preds = %6
%11 = tail call i32 (...) @spi_spin()
br label %12
12: ; preds = %10, %2
%13 = add nsw i32 %3, -1
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %2
15: ; preds = %12, %9
%16 = phi i32 [ 1, %9 ], [ 0, %12 ]
ret i32 %16
}