#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 /*<<< orphan*/ buf;

/* Variables and functions */
int FS460_image_get_begin_field(int);
int FS460_image_get_finish_read(char *, int);
int FS460_image_get_start_read(int);
int FS460_image_is_transfer_completed(int *);
int /*<<< orphan*/ FS460_image_request_freeze(int, int, int /*<<< orphan*/);
int FS460_image_set_begin_field(int);
int FS460_image_set_start_write(char *, int);
int /*<<< orphan*/ OS_mdelay(int);
int FS460_SDRAM_test(int percent_to_test) {
  char buf[0x8000];
  int i, j, field;
  int err, completed;
  int reps;
  int bytes_checked;
  bytes_checked = 0;
  FS460_image_request_freeze(0x0002 | 0x0001, 0x0002 | 0x0001, 0);
  OS_mdelay(40);
  reps = (((512 / 32) * percent_to_test) + 99) / 100;
  for (i = 0; i < sizeof(buf); i++) {
    buf[i] = (char)(i ^ 0xD4);
  }
  err = 0;
  for (field = 0; (field < 2) && !err; field++) {
    err = FS460_image_set_begin_field(field);
    if (!err) {
      for (j = 0; (j < reps) && !err; j++) {
        err = FS460_image_set_start_write(buf, sizeof(buf));
        if (!err) {
          completed = 0;
          while (!completed && !err)
            err = FS460_image_is_transfer_completed(&completed);
        }
      }
    }
    if (!err) {
      err = FS460_image_get_begin_field(field);
      if (!err) {
        for (j = 0; (j < reps) && !err; j++) {
          err = FS460_image_get_start_read(sizeof(buf));
          if (!err) {
            completed = 0;
            while (!completed && !err)
              err = FS460_image_is_transfer_completed(&completed);
            if (!err) {
              err = FS460_image_get_finish_read(buf, sizeof(buf));
              if (!err) {
                for (i = 0; (i < sizeof(buf)) && !err; i++) {
                  if (buf[i] != (char)(i ^ 0xD4)) {
                    err = 0x1006;
                  }
                  bytes_checked++;
                }
              }
            }
          }
        }
      }
    }
  }
  FS460_image_request_freeze(0, 0x0002 | 0x0001, 0);
  return err;
}


x86 assembly (clang, -O0):
<FS460_SDRAM_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8040,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x802c(%rbp)
mov    $0x3,%esi
xor    %edx,%edx
mov    %esi,%edi
call   1030 <FS460_image_request_freeze@plt>
mov    $0x28,%edi
call   1080 <OS_mdelay@plt>
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
add    $0x63,%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8028(%rbp)
movl   $0x0,-0x8014(%rbp)
movslq -0x8014(%rbp),%rax
cmp    $0x8000,%rax
jae    1213 <FS460_SDRAM_test+0x93>
mov    -0x8014(%rbp),%eax
xor    $0xd4,%eax
mov    %al,%cl
movslq -0x8014(%rbp),%rax
mov    %cl,-0x8010(%rbp,%rax,1)
mov    -0x8014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8014(%rbp)
jmp    11d1 <FS460_SDRAM_test+0x51>
movl   $0x0,-0x8020(%rbp)
movl   $0x0,-0x801c(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0x801c(%rbp)
mov    %al,-0x802d(%rbp)
jge    124e <FS460_SDRAM_test+0xce>
cmpl   $0x0,-0x8020(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x802d(%rbp)
mov    -0x802d(%rbp),%al
test   $0x1,%al
jne    1261 <FS460_SDRAM_test+0xe1>
jmp    1570 <FS460_SDRAM_test+0x3f0>
mov    -0x801c(%rbp),%edi
call   10a0 <FS460_image_set_begin_field@plt>
mov    %eax,-0x8020(%rbp)
cmpl   $0x0,-0x8020(%rbp)
jne    136a <FS460_SDRAM_test+0x1ea>
movl   $0x0,-0x8018(%rbp)
mov    -0x8018(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8028(%rbp),%ecx
mov    %al,-0x802e(%rbp)
jge    12b5 <FS460_SDRAM_test+0x135>
cmpl   $0x0,-0x8020(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x802e(%rbp)
mov    -0x802e(%rbp),%al
test   $0x1,%al
jne    12c8 <FS460_SDRAM_test+0x148>
jmp    1365 <FS460_SDRAM_test+0x1e5>
lea    -0x8010(%rbp),%rdi
mov    $0x8000,%esi
call   1040 <FS460_image_set_start_write@plt>
mov    %eax,-0x8020(%rbp)
cmpl   $0x0,-0x8020(%rbp)
jne    134c <FS460_SDRAM_test+0x1cc>
movl   $0x0,-0x8024(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8024(%rbp)
mov    %al,-0x802f(%rbp)
jne    131d <FS460_SDRAM_test+0x19d>
cmpl   $0x0,-0x8020(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x802f(%rbp)
mov    -0x802f(%rbp),%al
test   $0x1,%al
jne    1330 <FS460_SDRAM_test+0x1b0>
jmp    1347 <FS460_SDRAM_test+0x1c7>
lea    -0x8024(%rbp),%rdi
call   1070 <FS460_image_is_transfer_completed@plt>
mov    %eax,-0x8020(%rbp)
jmp    12f6 <FS460_SDRAM_test+0x176>
jmp    134c <FS460_SDRAM_test+0x1cc>
jmp    1351 <FS460_SDRAM_test+0x1d1>
mov    -0x8018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8018(%rbp)
jmp    1289 <FS460_SDRAM_test+0x109>
jmp    136a <FS460_SDRAM_test+0x1ea>
cmpl   $0x0,-0x8020(%rbp)
jne    1557 <FS460_SDRAM_test+0x3d7>
mov    -0x801c(%rbp),%edi
call   1090 <FS460_image_get_begin_field@plt>
mov    %eax,-0x8020(%rbp)
cmpl   $0x0,-0x8020(%rbp)
jne    1552 <FS460_SDRAM_test+0x3d2>
movl   $0x0,-0x8018(%rbp)
mov    -0x8018(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8028(%rbp),%ecx
mov    %al,-0x8030(%rbp)
jge    13cb <FS460_SDRAM_test+0x24b>
cmpl   $0x0,-0x8020(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x8030(%rbp)
mov    -0x8030(%rbp),%al
test   $0x1,%al
jne    13de <FS460_SDRAM_test+0x25e>
jmp    154d <FS460_SDRAM_test+0x3cd>
mov    $0x8000,%edi
call   1060 <FS460_image_get_start_read@plt>
mov    %eax,-0x8020(%rbp)
cmpl   $0x0,-0x8020(%rbp)
jne    1534 <FS460_SDRAM_test+0x3b4>
movl   $0x0,-0x8024(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x8024(%rbp)
mov    %al,-0x8031(%rbp)
jne    142c <FS460_SDRAM_test+0x2ac>
cmpl   $0x0,-0x8020(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x8031(%rbp)
mov    -0x8031(%rbp),%al
test   $0x1,%al
jne    143f <FS460_SDRAM_test+0x2bf>
jmp    1456 <FS460_SDRAM_test+0x2d6>
lea    -0x8024(%rbp),%rdi
call   1070 <FS460_image_is_transfer_completed@plt>
mov    %eax,-0x8020(%rbp)
jmp    1405 <FS460_SDRAM_test+0x285>
cmpl   $0x0,-0x8020(%rbp)
jne    152f <FS460_SDRAM_test+0x3af>
lea    -0x8010(%rbp),%rdi
mov    $0x8000,%esi
call   1050 <FS460_image_get_finish_read@plt>
mov    %eax,-0x8020(%rbp)
cmpl   $0x0,-0x8020(%rbp)
jne    152a <FS460_SDRAM_test+0x3aa>
movl   $0x0,-0x8014(%rbp)
movslq -0x8014(%rbp),%rcx
xor    %eax,%eax
cmp    $0x8000,%rcx
mov    %al,-0x8032(%rbp)
jae    14bf <FS460_SDRAM_test+0x33f>
cmpl   $0x0,-0x8020(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x8032(%rbp)
mov    -0x8032(%rbp),%al
test   $0x1,%al
jne    14d2 <FS460_SDRAM_test+0x352>
jmp    1525 <FS460_SDRAM_test+0x3a5>
movslq -0x8014(%rbp),%rax
movsbl -0x8010(%rbp,%rax,1),%eax
ff
mov    -0x8014(%rbp),%ecx
xor    $0xd4,%ecx
movsbl %cl,%ecx
cmp    %ecx,%eax
je     1502 <FS460_SDRAM_test+0x382>
movl   $0x1006,-0x8020(%rbp)
mov    -0x802c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x802c(%rbp)
mov    -0x8014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8014(%rbp)
jmp    1491 <FS460_SDRAM_test+0x311>
jmp    152a <FS460_SDRAM_test+0x3aa>
jmp    152f <FS460_SDRAM_test+0x3af>
jmp    1534 <FS460_SDRAM_test+0x3b4>
jmp    1539 <FS460_SDRAM_test+0x3b9>
mov    -0x8018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8018(%rbp)
jmp    139f <FS460_SDRAM_test+0x21f>
jmp    1552 <FS460_SDRAM_test+0x3d2>
jmp    1557 <FS460_SDRAM_test+0x3d7>
jmp    155c <FS460_SDRAM_test+0x3dc>
mov    -0x801c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x801c(%rbp)
jmp    1227 <FS460_SDRAM_test+0xa7>
xor    %edx,%edx
mov    $0x3,%esi
mov    %edx,%edi
call   1030 <FS460_image_request_freeze@plt>
mov    -0x8020(%rbp),%eax
add    $0x8040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS460_SDRAM_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8018,%rsp
mov    %edi,%r14d
xor    %ebx,%ebx
mov    $0x3,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1030 <FS460_image_request_freeze@plt>
mov    $0x28,%edi
call   1080 <OS_mdelay@plt>
mov    %r14d,%eax
shl    $0x4,%eax
add    $0x63,%eax
movdqa 0xe3e(%rip),%xmm0
movdqa 0xe46(%rip),%xmm1
movdqa 0xe4e(%rip),%xmm2
movdqa 0xe56(%rip),%xmm3
movdqa 0xe5e(%rip),%xmm4
movdqa 0xe66(%rip),%xmm5
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm6
pxor   %xmm1,%xmm6
movdqa %xmm6,0x10(%rsp,%rbx,1)
movdqa %xmm0,%xmm6
paddb  %xmm2,%xmm6
pxor   %xmm1,%xmm6
movdqa %xmm6,0x20(%rsp,%rbx,1)
movdqa %xmm0,%xmm6
paddb  %xmm3,%xmm6
pxor   %xmm1,%xmm6
movdqa %xmm6,0x30(%rsp,%rbx,1)
movdqa %xmm0,%xmm6
paddb  %xmm4,%xmm6
pxor   %xmm1,%xmm6
movdqa %xmm6,0x40(%rsp,%rbx,1)
add    $0x40,%rbx
paddb  %xmm5,%xmm0
cmp    $0x8000,%rbx
jne    11f0 <FS460_SDRAM_test+0x70>
cltq
imul   $0x51eb851f,%rax,%r13
mov    %r13,%rax
shr    $0x3f,%rax
sar    $0x25,%r13
add    %eax,%r13d
mov    $0x1,%al
lea    0x10(%rsp),%r15
lea    0x4(%rsp),%rbp
xor    %r12d,%r12d
mov    %eax,0xc(%rsp)
mov    %r12d,%edi
call   10a0 <FS460_image_set_begin_field@plt>
test   %eax,%eax
jne    13bc <FS460_SDRAM_test+0x23c>
test   %r14d,%r14d
jle    12dc <FS460_SDRAM_test+0x15c>
mov    %r14d,0x8(%rsp)
xor    %r14d,%r14d
nopl   0x0(%rax)
mov    %r15,%rdi
mov    $0x8000,%esi
call   1040 <FS460_image_set_start_write@plt>
test   %eax,%eax
jne    13bc <FS460_SDRAM_test+0x23c>
movl   $0x0,0x4(%rsp)
nopl   (%rax)
mov    %rbp,%rdi
call   1070 <FS460_image_is_transfer_completed@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%eax
or     %ebx,%eax
je     12b0 <FS460_SDRAM_test+0x130>
add    $0x1,%r14d
cmp    %r13d,%r14d
jge    12cf <FS460_SDRAM_test+0x14f>
test   %ebx,%ebx
je     1290 <FS460_SDRAM_test+0x110>
test   %ebx,%ebx
mov    0x8(%rsp),%r14d
jne    13be <FS460_SDRAM_test+0x23e>
mov    %r12d,%edi
call   1090 <FS460_image_get_begin_field@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    13a0 <FS460_SDRAM_test+0x220>
test   %r14d,%r14d
jle    13a0 <FS460_SDRAM_test+0x220>
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    $0x8000,%edi
call   1060 <FS460_image_get_start_read@plt>
test   %eax,%eax
jne    13bc <FS460_SDRAM_test+0x23c>
movl   $0x0,0x4(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1070 <FS460_image_is_transfer_completed@plt>
mov    %eax,%ebx
mov    0x4(%rsp),%eax
or     %ebx,%eax
je     1320 <FS460_SDRAM_test+0x1a0>
test   %ebx,%ebx
jne    13be <FS460_SDRAM_test+0x23e>
mov    %r15,%rdi
mov    $0x8000,%esi
call   1050 <FS460_image_get_finish_read@plt>
test   %eax,%eax
jne    13bc <FS460_SDRAM_test+0x23c>
xor    %edx,%edx
xor    %esi,%esi
nop
movsbl 0x10(%rsp,%rsi,1),%eax
mov    %edx,%ecx
sar    $0x18,%ecx
xor    $0xffffffd4,%ecx
cmp    $0x7ffe,%rsi
ja     1374 <FS460_SDRAM_test+0x1f4>
add    $0x1,%rsi
add    $0x1000000,%edx
cmp    %eax,%ecx
je     1350 <FS460_SDRAM_test+0x1d0>
add    $0x1,%r12d
cmp    %r13d,%r12d
jge    1385 <FS460_SDRAM_test+0x205>
cmp    %eax,%ecx
je     1300 <FS460_SDRAM_test+0x180>
cmp    %eax,%ecx
mov    $0x1006,%ebx
mov    $0x0,%eax
cmove  %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
test   %ebx,%ebx
sete   %al
mov    $0x1,%r12d
test   %al,0xc(%rsp)
mov    $0x0,%eax
jne    126b <FS460_SDRAM_test+0xeb>
jmp    13be <FS460_SDRAM_test+0x23e>
mov    %eax,%ebx
xor    %edi,%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1030 <FS460_image_request_freeze@plt>
mov    %ebx,%eax
add    $0x8018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @FS460_SDRAM_test(i32 %0) {
%2 = alloca i32
%3 = alloca [32768 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %10
%11 = call i32 @FS460_image_request_freeze(i32 3, i32 3, i32 0)
%12 = call i32 @OS_mdelay(i32 40)
%13 = load i32, i32* %2
%14 = mul nsw i32 16, %13
%15 = add nsw i32 %14, 99
%16 = sdiv i32 %15, 100
store i32 %16, i32* %9
store i32 0, i32* %4
br label %17
17: ; preds = %28, %1
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = icmp ult i64 %19, 32768
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %4
%23 = xor i32 %22, 212
%24 = trunc i32 %23 to i8
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 %26
store i8 %24, i8* %27
br label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %17
31: ; preds = %17
store i32 0, i32* %7
store i32 0, i32* %6
br label %32
32: ; preds = %162, %31
%33 = load i32, i32* %6
%34 = icmp slt i32 %33, 2
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br label %39
39: ; preds = %35, %32
%40 = phi i1 [ false, %32 ], [ %38, %35 ]
br i1 %40, label %41, label %165
41: ; preds = %39
%42 = load i32, i32* %6
%43 = call i32 @FS460_image_set_begin_field(i32 %42)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = icmp ne i32 %44, 0
br i1 %45, label %80, label %46
46: ; preds = %41
store i32 0, i32* %5
br label %47
47: ; preds = %76, %46
%48 = load i32, i32* %5
%49 = load i32, i32* %9
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = load i32, i32* %7
%53 = icmp ne i32 %52, 0
%54 = xor i1 %53, true
br label %55
55: ; preds = %51, %47
%56 = phi i1 [ false, %47 ], [ %54, %51 ]
br i1 %56, label %57, label %79
57: ; preds = %55
%58 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%59 = call i32 @FS460_image_set_start_write(i8* %58, i32 32768)
store i32 %59, i32* %7
%60 = load i32, i32* %7
%61 = icmp ne i32 %60, 0
br i1 %61, label %75, label %62
62: ; preds = %57
store i32 0, i32* %8
br label %63
63: ; preds = %72, %62
%64 = load i32, i32* %8
%65 = icmp ne i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %63
%67 = load i32, i32* %7
%68 = icmp ne i32 %67, 0
%69 = xor i1 %68, true
br label %70
70: ; preds = %66, %63
%71 = phi i1 [ false, %63 ], [ %69, %66 ]
br i1 %71, label %72, label %74
72: ; preds = %70
%73 = call i32 @FS460_image_is_transfer_completed(i32* %8)
store i32 %73, i32* %7
br label %63
74: ; preds = %70
br label %75
75: ; preds = %74, %57
br label %76
76: ; preds = %75
%77 = load i32, i32* %5
%78 = add nsw i32 %77, 1
store i32 %78, i32* %5
br label %47
79: ; preds = %55
br label %80
80: ; preds = %79, %41
%81 = load i32, i32* %7
%82 = icmp ne i32 %81, 0
br i1 %82, label %161, label %83
83: ; preds = %80
%84 = load i32, i32* %6
%85 = call i32 @FS460_image_get_begin_field(i32 %84)
store i32 %85, i32* %7
%86 = load i32, i32* %7
%87 = icmp ne i32 %86, 0
br i1 %87, label %160, label %88
88: ; preds = %83
store i32 0, i32* %5
br label %89
89: ; preds = %156, %88
%90 = load i32, i32* %5
%91 = load i32, i32* %9
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %97
93: ; preds = %89
%94 = load i32, i32* %7
%95 = icmp ne i32 %94, 0
%96 = xor i1 %95, true
br label %97
97: ; preds = %93, %89
%98 = phi i1 [ false, %89 ], [ %96, %93 ]
br i1 %98, label %99, label %159
99: ; preds = %97
%100 = call i32 @FS460_image_get_start_read(i32 32768)
store i32 %100, i32* %7
%101 = load i32, i32* %7
%102 = icmp ne i32 %101, 0
br i1 %102, label %155, label %103
103: ; preds = %99
store i32 0, i32* %8
br label %104
104: ; preds = %113, %103
%105 = load i32, i32* %8
%106 = icmp ne i32 %105, 0
br i1 %106, label %111, label %107
107: ; preds = %104
%108 = load i32, i32* %7
%109 = icmp ne i32 %108, 0
%110 = xor i1 %109, true
br label %111
111: ; preds = %107, %104
%112 = phi i1 [ false, %104 ], [ %110, %107 ]
br i1 %112, label %113, label %115
113: ; preds = %111
%114 = call i32 @FS460_image_is_transfer_completed(i32* %8)
store i32 %114, i32* %7
br label %104
115: ; preds = %111
%116 = load i32, i32* %7
%117 = icmp ne i32 %116, 0
br i1 %117, label %154, label %118
118: ; preds = %115
%119 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%120 = call i32 @FS460_image_get_finish_read(i8* %119, i32 32768)
store i32 %120, i32* %7
%121 = load i32, i32* %7
%122 = icmp ne i32 %121, 0
br i1 %122, label %153, label %123
123: ; preds = %118
store i32 0, i32* %4
br label %124
124: ; preds = %149, %123
%125 = load i32, i32* %4
%126 = sext i32 %125 to i64
%127 = icmp ult i64 %126, 32768
br i1 %127, label %128, label %132
128: ; preds = %124
%129 = load i32, i32* %7
%130 = icmp ne i32 %129, 0
%131 = xor i1 %130, true
br label %132
132: ; preds = %128, %124
%133 = phi i1 [ false, %124 ], [ %131, %128 ]
br i1 %133, label %134, label %152
134: ; preds = %132
%135 = load i32, i32* %4
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 %136
%138 = load i8, i8* %137
%139 = sext i8 %138 to i32
%140 = load i32, i32* %4
%141 = xor i32 %140, 212
%142 = trunc i32 %141 to i8
%143 = sext i8 %142 to i32
%144 = icmp ne i32 %139, %143
br i1 %144, label %145, label %146
145: ; preds = %134
store i32 4102, i32* %7
br label %146
146: ; preds = %145, %134
%147 = load i32, i32* %10
%148 = add nsw i32 %147, 1
store i32 %148, i32* %10
br label %149
149: ; preds = %146
%150 = load i32, i32* %4
%151 = add nsw i32 %150, 1
store i32 %151, i32* %4
br label %124
152: ; preds = %132
br label %153
153: ; preds = %152, %118
br label %154
154: ; preds = %153, %115
br label %155
155: ; preds = %154, %99
br label %156
156: ; preds = %155
%157 = load i32, i32* %5
%158 = add nsw i32 %157, 1
store i32 %158, i32* %5
br label %89
159: ; preds = %97
br label %160
160: ; preds = %159, %83
br label %161
161: ; preds = %160, %80
br label %162
162: ; preds = %161
%163 = load i32, i32* %6
%164 = add nsw i32 %163, 1
store i32 %164, i32* %6
br label %32
165: ; preds = %39
%166 = call i32 @FS460_image_request_freeze(i32 0, i32 3, i32 0)
%167 = load i32, i32* %7
ret i32 %167
}

LLVM IR (-O2):
define i32 @FS460_SDRAM_test(i32 %0) {
%2 = alloca [32768 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 0
%5 = bitcast i32* %3 to i8*
%6 = tail call i32 @FS460_image_request_freeze(i32 3, i32 3, i32 0)
%7 = tail call i32 @OS_mdelay(i32 40)
%8 = shl nsw i32 %0, 4
%9 = add nsw i32 %8, 99
br label %10
10: ; preds = %10, %1
%11 = phi i64 [ 0, %1 ], [ %31, %10 ]
%12 = phi <16 x i8> [ <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, %1 ], [ %32, %10 ]
%13 = xor <16 x i8> %12, <i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44>
%14 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %11
%15 = bitcast i8* %14 to <16 x i8>*
store <16 x i8> %13, <16 x i8>* %15
%16 = or i64 %11, 16
%17 = add <16 x i8> %12, <i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16, i8 16>
%18 = xor <16 x i8> %17, <i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44>
%19 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %16
%20 = bitcast i8* %19 to <16 x i8>*
store <16 x i8> %18, <16 x i8>* %20
%21 = or i64 %11, 32
%22 = add <16 x i8> %12, <i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32, i8 32>
%23 = xor <16 x i8> %22, <i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44>
%24 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %21
%25 = bitcast i8* %24 to <16 x i8>*
store <16 x i8> %23, <16 x i8>* %25
%26 = or i64 %11, 48
%27 = add <16 x i8> %12, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%28 = xor <16 x i8> %27, <i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44, i8 -44>
%29 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %26
%30 = bitcast i8* %29 to <16 x i8>*
store <16 x i8> %28, <16 x i8>* %30
%31 = add nuw nsw i64 %11, 64
%32 = add <16 x i8> %12, <i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64, i8 64>
%33 = icmp eq i64 %31, 32768
br i1 %33, label %34, label %10
34: ; preds = %10
%35 = sdiv i32 %9, 100
%36 = icmp sgt i32 %0, 0
%37 = icmp slt i32 %0, 1
br label %38
38: ; preds = %34, %100
%39 = phi i1 [ true, %34 ], [ false, %100 ]
%40 = phi i32 [ 0, %34 ], [ 1, %100 ]
%41 = call i32 @FS460_image_set_begin_field(i32 %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %104
43: ; preds = %38
br i1 %36, label %44, label %62
44: ; preds = %43, %55
%45 = phi i32 [ %56, %55 ], [ 0, %43 ]
%46 = call i32 @FS460_image_set_start_write(i8* %4, i32 32768)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %104
48: ; preds = %44
store i32 0, i32* %3
br label %49
49: ; preds = %48, %49
%50 = call i32 @FS460_image_is_transfer_completed(i32* %3)
%51 = load i32, i32* %3
%52 = icmp eq i32 %51, 0
%53 = icmp eq i32 %50, 0
%54 = select i1 %52, i1 %53, i1 false
br i1 %54, label %49, label %55
55: ; preds = %49
%56 = add nuw nsw i32 %45, 1
%57 = icmp slt i32 %56, %35
%58 = icmp eq i32 %50, 0
%59 = select i1 %57, i1 %58, i1 false
br i1 %59, label %44, label %60
60: ; preds = %55
%61 = icmp eq i32 %50, 0
br i1 %61, label %62, label %104
62: ; preds = %43, %60
%63 = call i32 @FS460_image_get_begin_field(i32 %40)
%64 = icmp ne i32 %63, 0
%65 = or i1 %64, %37
br i1 %65, label %100, label %66
66: ; preds = %62, %94
%67 = phi i32 [ %95, %94 ], [ 0, %62 ]
%68 = call i32 @FS460_image_get_start_read(i32 32768)
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %104
70: ; preds = %66
store i32 0, i32* %3
br label %71
71: ; preds = %70, %71
%72 = call i32 @FS460_image_is_transfer_completed(i32* %3)
%73 = load i32, i32* %3
%74 = icmp eq i32 %73, 0
%75 = icmp eq i32 %72, 0
%76 = select i1 %74, i1 %75, i1 false
br i1 %76, label %71, label %77
77: ; preds = %71
br i1 %75, label %78, label %104
78: ; preds = %77
%79 = call i32 @FS460_image_get_finish_read(i8* %4, i32 32768)
%80 = icmp eq i32 %79, 0
br i1 %80, label %81, label %104
81: ; preds = %78, %81
%82 = phi i64 [ %91, %81 ], [ 0, %78 ]
%83 = getelementptr inbounds [32768 x i8], [32768 x i8]* %2, i64 0, i64 %82
%84 = load i8, i8* %83
%85 = sext i8 %84 to i32
%86 = trunc i64 %82 to i32
%87 = shl i32 %86, 24
%88 = ashr exact i32 %87, 24
%89 = xor i32 %88, -44
%90 = icmp eq i32 %89, %85
%91 = add nuw nsw i64 %82, 1
%92 = icmp ult i64 %82, 32767
%93 = select i1 %92, i1 %90, i1 false
br i1 %93, label %81, label %94
94: ; preds = %81
%95 = add nuw nsw i32 %67, 1
%96 = icmp slt i32 %95, %35
%97 = select i1 %96, i1 %90, i1 false
br i1 %97, label %66, label %98
98: ; preds = %94
%99 = select i1 %90, i32 0, i32 4102
br label %100
100: ; preds = %98, %62
%101 = phi i32 [ %63, %62 ], [ %99, %98 ]
%102 = icmp eq i32 %101, 0
%103 = select i1 %39, i1 %102, i1 false
br i1 %103, label %38, label %104
104: ; preds = %38, %60, %100, %44, %78, %77, %66
%105 = phi i32 [ %68, %66 ], [ %72, %77 ], [ %79, %78 ], [ %46, %44 ], [ %50, %60 ], [ %41, %38 ], [ %101, %100 ]
%106 = call i32 @FS460_image_request_freeze(i32 0, i32 3, i32 0)
ret i32 %105
}