#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;

/* Variables and functions */
int /*<<< orphan*/ do_instruction(int, int *, int *);
int load_page(int spidev, uint8_t *data, unsigned int len) {
  unsigned int i = 0;
  uint8_t tx[4], rx[4];
  tx[1] = 0;
  while (len) {
    tx[0] = 0x40;
    tx[2] = i++;
    tx[3] = *data++;
    if (!do_instruction(spidev, tx, rx))
      return 0;
    tx[0] = 0x48;
    tx[3] = *data++;
    if (!do_instruction(spidev, tx, rx))
      return 0;
    len -= 2;
  }
  return 1;
}


x86 assembly (clang, -O0):
<load_page>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11d6 <load_page+0xc6>
movl   $0x40,-0x30(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <do_instruction@plt>
cmp    $0x0,%eax
jne    1188 <load_page+0x78>
movl   $0x0,-0x4(%rbp)
jmp    11dd <load_page+0xcd>
movl   $0x48,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1030 <do_instruction@plt>
cmp    $0x0,%eax
jne    11c8 <load_page+0xb8>
movl   $0x0,-0x4(%rbp)
jmp    11dd <load_page+0xcd>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
jmp    1130 <load_page+0x20>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_page>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
movl   $0x0,0x4(%rsp)
mov    $0x1,%eax
test   %edx,%edx
je     11ac <load_page+0x9c>
mov    %edx,%ebp
mov    %rsi,%r15
mov    %edi,%ebx
xor    %r14d,%r14d
mov    %rsp,%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0x40,(%rsp)
mov    %r14d,0x8(%rsp)
mov    (%r15,%r14,8),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <do_instruction@plt>
test   %eax,%eax
je     11aa <load_page+0x9a>
lea    (%r14,%r14,1),%rax
movl   $0x48,(%rsp)
mov    0x4(%r15,%rax,4),%eax
mov    %eax,0xc(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1030 <do_instruction@plt>
test   %eax,%eax
je     11aa <load_page+0x9a>
add    $0x1,%r14
add    $0xfffffffe,%ebp
jne    1150 <load_page+0x40>
mov    $0x1,%eax
jmp    11ac <load_page+0x9c>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @load_page(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i32]
%10 = alloca [4 x i32]
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 1
store i32 0, i32* %11
br label %12
12: ; preds = %42, %3
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %45
15: ; preds = %12
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
store i32 64, i32* %16
%17 = load i32, i32* %8
%18 = add i32 %17, 1
store i32 %18, i32* %8
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 2
store i32 %17, i32* %19
%20 = load i32*, i32** %6
%21 = getelementptr inbounds i32, i32* %20, i32 1
store i32* %21, i32** %6
%22 = load i32, i32* %20
%23 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
store i32 %22, i32* %23
%24 = load i32, i32* %5
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%26 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%27 = call i32 @do_instruction(i32 %24, i32* %25, i32* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %15
store i32 0, i32* %4
br label %46
30: ; preds = %15
%31 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
store i32 72, i32* %31
%32 = load i32*, i32** %6
%33 = getelementptr inbounds i32, i32* %32, i32 1
store i32* %33, i32** %6
%34 = load i32, i32* %32
%35 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 3
store i32 %34, i32* %35
%36 = load i32, i32* %5
%37 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %10, i64 0, i64 0
%39 = call i32 @do_instruction(i32 %36, i32* %37, i32* %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %42, label %41
41: ; preds = %30
store i32 0, i32* %4
br label %46
42: ; preds = %30
%43 = load i32, i32* %7
%44 = sub i32 %43, 2
store i32 %44, i32* %7
br label %12
45: ; preds = %12
store i32 1, i32* %4
br label %46
46: ; preds = %45, %41, %29
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
define i32 @load_page(i32 %0, i32* nocapture %1, i32 %2) {
%4 = alloca [4 x i32]
%5 = alloca [4 x i32]
%6 = bitcast [4 x i32]* %4 to i8*
%7 = bitcast [4 x i32]* %5 to i8*
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
store i32 0, i32* %8
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%10 = icmp eq i32 %2, 0
br i1 %10, label %32, label %11
11: ; preds = %3
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 0
br label %15
15: ; preds = %11, %28
%16 = phi i32 [ 0, %11 ], [ %19, %28 ]
%17 = phi i32 [ %2, %11 ], [ %30, %28 ]
%18 = phi i32* [ %1, %11 ], [ %29, %28 ]
store i32 64, i32* %9
%19 = add i32 %16, 1
store i32 %16, i32* %12
%20 = load i32, i32* %18
store i32 %20, i32* %13
%21 = call i32 @do_instruction(i32 %0, i32* %9, i32* %14)
%22 = icmp eq i32 %21, 0
br i1 %22, label %32, label %23
23: ; preds = %15
%24 = getelementptr inbounds i32, i32* %18, i64 1
store i32 72, i32* %9
%25 = load i32, i32* %24
store i32 %25, i32* %13
%26 = call i32 @do_instruction(i32 %0, i32* %9, i32* %14)
%27 = icmp eq i32 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = getelementptr inbounds i32, i32* %18, i64 2
%30 = add i32 %17, -2
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %15
32: ; preds = %15, %23, %28, %3
%33 = phi i32 [ 1, %3 ], [ 1, %28 ], [ 0, %23 ], [ 0, %15 ]
ret i32 %33
}