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


x86 assembly (clang, -O0):
<wait_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x14,-0x8(%rbp)
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     1187 <wait_init+0x67>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    117b <wait_init+0x5b>
mov    $0xffffffd4,%eax
movl   $0xff,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    118e <wait_init+0x6e>
mov    $0x0,%al
call   1030 <spi_spin@plt>
jmp    113a <wait_init+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_init>:
push   %r14
push   %rbx
push   %rax
mov    $0xffffffd4,%r14d
movl   $0xff,(%r14)
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <spi_spin@plt>
mov    $0xff0041,%edi
xor    %esi,%esi
call   1040 <cmd_write@plt>
test   %eax,%eax
je     131e <wait_init+0x1fe>
xor    %eax,%eax
call   1030 <spi_spin@plt>
jmp    132a <wait_init+0x20a>
movl   $0xff,(%r14)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i32 @wait_init() {
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
%1 = tail call i32 @cmd_write(i32 16711745, i32 0)
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %4
3: ; preds = %72, %68, %64, %60, %56, %52, %48, %44, %40, %36, %32, %28, %24, %20, %16, %12, %8, %4, %0
store volatile i32 255, i32* inttoptr (i64 4294967252 to i32*)
br label %78
4: ; preds = %0
%5 = tail call i32 (...) @spi_spin()
%6 = tail call i32 @cmd_write(i32 16711745, i32 0)
%7 = icmp eq i32 %6, 0
br i1 %7, label %3, label %8
8: ; preds = %4
%9 = tail call i32 (...) @spi_spin()
%10 = tail call i32 @cmd_write(i32 16711745, i32 0)
%11 = icmp eq i32 %10, 0
br i1 %11, label %3, label %12
12: ; preds = %8
%13 = tail call i32 (...) @spi_spin()
%14 = tail call i32 @cmd_write(i32 16711745, i32 0)
%15 = icmp eq i32 %14, 0
br i1 %15, label %3, label %16
16: ; preds = %12
%17 = tail call i32 (...) @spi_spin()
%18 = tail call i32 @cmd_write(i32 16711745, i32 0)
%19 = icmp eq i32 %18, 0
br i1 %19, label %3, label %20
20: ; preds = %16
%21 = tail call i32 (...) @spi_spin()
%22 = tail call i32 @cmd_write(i32 16711745, i32 0)
%23 = icmp eq i32 %22, 0
br i1 %23, label %3, label %24
24: ; preds = %20
%25 = tail call i32 (...) @spi_spin()
%26 = tail call i32 @cmd_write(i32 16711745, i32 0)
%27 = icmp eq i32 %26, 0
br i1 %27, label %3, label %28
28: ; preds = %24
%29 = tail call i32 (...) @spi_spin()
%30 = tail call i32 @cmd_write(i32 16711745, i32 0)
%31 = icmp eq i32 %30, 0
br i1 %31, label %3, label %32
32: ; preds = %28
%33 = tail call i32 (...) @spi_spin()
%34 = tail call i32 @cmd_write(i32 16711745, i32 0)
%35 = icmp eq i32 %34, 0
br i1 %35, label %3, label %36
36: ; preds = %32
%37 = tail call i32 (...) @spi_spin()
%38 = tail call i32 @cmd_write(i32 16711745, i32 0)
%39 = icmp eq i32 %38, 0
br i1 %39, label %3, label %40
40: ; preds = %36
%41 = tail call i32 (...) @spi_spin()
%42 = tail call i32 @cmd_write(i32 16711745, i32 0)
%43 = icmp eq i32 %42, 0
br i1 %43, label %3, label %44
44: ; preds = %40
%45 = tail call i32 (...) @spi_spin()
%46 = tail call i32 @cmd_write(i32 16711745, i32 0)
%47 = icmp eq i32 %46, 0
br i1 %47, label %3, label %48
48: ; preds = %44
%49 = tail call i32 (...) @spi_spin()
%50 = tail call i32 @cmd_write(i32 16711745, i32 0)
%51 = icmp eq i32 %50, 0
br i1 %51, label %3, label %52
52: ; preds = %48
%53 = tail call i32 (...) @spi_spin()
%54 = tail call i32 @cmd_write(i32 16711745, i32 0)
%55 = icmp eq i32 %54, 0
br i1 %55, label %3, label %56
56: ; preds = %52
%57 = tail call i32 (...) @spi_spin()
%58 = tail call i32 @cmd_write(i32 16711745, i32 0)
%59 = icmp eq i32 %58, 0
br i1 %59, label %3, label %60
60: ; preds = %56
%61 = tail call i32 (...) @spi_spin()
%62 = tail call i32 @cmd_write(i32 16711745, i32 0)
%63 = icmp eq i32 %62, 0
br i1 %63, label %3, label %64
64: ; preds = %60
%65 = tail call i32 (...) @spi_spin()
%66 = tail call i32 @cmd_write(i32 16711745, i32 0)
%67 = icmp eq i32 %66, 0
br i1 %67, label %3, label %68
68: ; preds = %64
%69 = tail call i32 (...) @spi_spin()
%70 = tail call i32 @cmd_write(i32 16711745, i32 0)
%71 = icmp eq i32 %70, 0
br i1 %71, label %3, label %72
72: ; preds = %68
%73 = tail call i32 (...) @spi_spin()
%74 = tail call i32 @cmd_write(i32 16711745, i32 0)
%75 = icmp eq i32 %74, 0
br i1 %75, label %3, label %76
76: ; preds = %72
%77 = tail call i32 (...) @spi_spin()
br label %78
78: ; preds = %76, %3
%79 = phi i32 [ 1, %3 ], [ 0, %76 ]
ret i32 %79
}