#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ flash_block_read(int, int *, size_t);
int /*<<< orphan*/ flash_init();
int /*<<< orphan*/ memcmp(int *, int *, size_t);
int /*<<< orphan*/ memcpy(int *, int *, size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stdout;
void dump_flash(size_t size) {
  int i, j;
  size_t len;
  uint8_t buf[256], last[256];
  int skipping = 0;
  flash_init();
  for (i = 0; i < size; i += 16) {
    len = size - i <= 16 ? size - i : 16;
    flash_block_read(i, buf, len);
    if (i && !memcmp(last, buf, len)) {
      printf("%04x: *%c", i, skipping ? '\r' : '\n');
      fflush(stdout);
      skipping = 1;
      continue;
    }
    skipping = 0;
    memcpy(last, buf, len);
    printf("%04x:", i);
    for (j = 0; j != len; j++)
      printf(" %02x", buf[j]);
    printf("  ");
    for (j = 0; j != len; j++)
      printf("%c", buf[j] >= ' ' && buf[j] <= '~' ? buf[j] : '.');
    putchar('\n');
    fflush(stdout);
  }
}


x86 assembly (clang, -O0):
<dump_flash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x824(%rbp)
mov    $0x0,%al
call   1050 <flash_init@plt>
movl   $0x0,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    1391 <dump_flash+0x221>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
sub    %rcx,%rax
cmp    $0x10,%rax
ja     11d1 <dump_flash+0x61>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x830(%rbp)
jmp    11e2 <dump_flash+0x72>
mov    $0x10,%eax
mov    %rax,-0x830(%rbp)
jmp    11e2 <dump_flash+0x72>
mov    -0x830(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <flash_block_read@plt>
cmpl   $0x0,-0xc(%rbp)
je     126e <dump_flash+0xfe>
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <memcmp@plt>
cmp    $0x0,%eax
jne    126e <dump_flash+0xfe>
mov    -0xc(%rbp),%esi
mov    -0x824(%rbp),%ecx
mov    $0xa,%edx
mov    $0xd,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
movl   $0x1,-0x824(%rbp)
jmp    1383 <dump_flash+0x213>
movl   $0x0,-0x824(%rbp)
lea    -0x820(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0xc(%rbp),%esi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     12dc <dump_flash+0x16c>
movslq -0x10(%rbp),%rax
mov    -0x420(%rbp,%rax,4),%esi
lea    0xd49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12a7 <dump_flash+0x137>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     136b <dump_flash+0x1fb>
movslq -0x10(%rbp),%rax
cmpl   $0x20,-0x420(%rbp,%rax,4)
20
jl     1339 <dump_flash+0x1c9>
movslq -0x10(%rbp),%rax
cmpl   $0x7e,-0x420(%rbp,%rax,4)
7e
jg     1339 <dump_flash+0x1c9>
movslq -0x10(%rbp),%rax
mov    -0x420(%rbp,%rax,4),%eax
mov    %eax,-0x834(%rbp)
jmp    1349 <dump_flash+0x1d9>
mov    $0x2e,%eax
mov    %eax,-0x834(%rbp)
jmp    1349 <dump_flash+0x1d9>
mov    -0x834(%rbp),%esi
lea    0xcb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    12f1 <dump_flash+0x181>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0xc(%rbp)
jmp    1197 <dump_flash+0x27>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dump_flash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rdi,%rbx
xor    %eax,%eax
call   1050 <flash_init@plt>
test   %rbx,%rbx
je     130c <dump_flash+0x19c>
lea    0x10(%rsp),%r15
lea    0xe70(%rip),%rbp
mov    %rbx,%r13
xor    %r12d,%r12d
xor    %r14d,%r14d
mov    %rbx,0x8(%rsp)
jmp    11fb <dump_flash+0x8b>
lea    0xe5f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %r14d,%r14d
lea    0xe3e(%rip),%rbp
mov    0x8(%rsp),%rbx
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1080 <fflush@plt>
add    $0x10,%r12
add    $0xfffffffffffffff0,%r13
cmp    %rbx,%r12
lea    0x10(%rsp),%r15
jae    130c <dump_flash+0x19c>
mov    %r14d,0x4(%rsp)
cmp    $0x10,%r13
mov    $0x10,%r14d
cmovb  %r13,%r14
sub    %r12,%rbx
cmp    $0x10,%rbx
mov    $0x10,%eax
cmovae %rax,%rbx
mov    %r12d,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <flash_block_read@plt>
test   %r12,%r12
je     124c <dump_flash+0xdc>
lea    0x410(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <bcmp@plt>
test   %eax,%eax
je     12e0 <dump_flash+0x170>
lea    0x410(%rsp),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1070 <memcpy@plt>
lea    0xda4(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbx,%rbx
je     11b0 <dump_flash+0x40>
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    0x10(%rsp,%r15,4),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%r15
cmp    %r15,%r14
jne    1280 <dump_flash+0x110>
lea    0xd77(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %rbx,%rbx
mov    $0x2e,%ebp
je     11be <dump_flash+0x4e>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%edi
lea    -0x20(%rdi),%eax
cmp    $0x5f,%eax
cmovae %ebp,%edi
call   1030 <putchar@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    12c0 <dump_flash+0x150>
jmp    11be <dump_flash+0x4e>
xor    %eax,%eax
cmpl   $0x0,0x4(%rsp)
setne  %al
lea    (%rax,%rax,2),%edx
add    $0xa,%edx
lea    0xd09(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%r14d
jmp    11d2 <dump_flash+0x62>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"%04x: *%c\00"
@stdout = global i32 0
@.str.1 = [6 x i8] c"%04x:\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [3 x i8] c" \00"
@.str.4 = [3 x i8] c"%c\00"
define void @dump_flash(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
%6 = alloca [256 x i32]
%7 = alloca [256 x i32]
%8 = alloca i32
store i64 %0, i64* %2
store i32 0, i32* %8
%9 = call i32 (...) @flash_init()
store i32 0, i32* %3
br label %10
10: ; preds = %106, %1
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = load i64, i64* %2
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %109
15: ; preds = %10
%16 = load i64, i64* %2
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = sub i64 %16, %18
%20 = icmp ule i64 %19, 16
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i64, i64* %2
%23 = load i32, i32* %3
%24 = sext i32 %23 to i64
%25 = sub i64 %22, %24
br label %27
26: ; preds = %15
br label %27
27: ; preds = %26, %21
%28 = phi i64 [ %25, %21 ], [ 16, %26 ]
store i64 %28, i64* %5
%29 = load i32, i32* %3
%30 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 0
%31 = load i64, i64* %5
%32 = call i32 @flash_block_read(i32 %29, i32* %30, i64 %31)
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %50
35: ; preds = %27
%36 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 0
%37 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 0
%38 = load i64, i64* %5
%39 = call i32 @memcmp(i32* %36, i32* %37, i64 %38)
%40 = icmp ne i32 %39, 0
br i1 %40, label %50, label %41
41: ; preds = %35
%42 = load i32, i32* %3
%43 = load i32, i32* %8
%44 = icmp ne i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 13, i32 10
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %42, i32 %46)
%48 = load i32, i32* @stdout
%49 = call i32 @fflush(i32 %48)
store i32 1, i32* %8
br label %106
50: ; preds = %35, %27
store i32 0, i32* %8
%51 = getelementptr inbounds [256 x i32], [256 x i32]* %7, i64 0, i64 0
%52 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 0
%53 = load i64, i64* %5
%54 = call i32 @memcpy(i32* %51, i32* %52, i64 %53)
%55 = load i32, i32* %3
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %55)
store i32 0, i32* %4
br label %57
57: ; preds = %68, %50
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = load i64, i64* %5
%61 = icmp ne i64 %59, %60
br i1 %61, label %62, label %71
62: ; preds = %57
%63 = load i32, i32* %4
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %64
%66 = load i32, i32* %65
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %66)
br label %68
68: ; preds = %62
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %57
71: ; preds = %57
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %4
br label %73
73: ; preds = %99, %71
%74 = load i32, i32* %4
%75 = sext i32 %74 to i64
%76 = load i64, i64* %5
%77 = icmp ne i64 %75, %76
br i1 %77, label %78, label %102
78: ; preds = %73
%79 = load i32, i32* %4
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %80
%82 = load i32, i32* %81
%83 = icmp sge i32 %82, 32
br i1 %83, label %84, label %95
84: ; preds = %78
%85 = load i32, i32* %4
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %86
%88 = load i32, i32* %87
%89 = icmp sle i32 %88, 126
br i1 %89, label %90, label %95
90: ; preds = %84
%91 = load i32, i32* %4
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [256 x i32], [256 x i32]* %6, i64 0, i64 %92
%94 = load i32, i32* %93
br label %96
95: ; preds = %84, %78
br label %96
96: ; preds = %95, %90
%97 = phi i32 [ %94, %90 ], [ 46, %95 ]
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %97)
br label %99
99: ; preds = %96
%100 = load i32, i32* %4
%101 = add nsw i32 %100, 1
store i32 %101, i32* %4
br label %73
102: ; preds = %73
%103 = call i32 @putchar(i8 signext 10)
%104 = load i32, i32* @stdout
%105 = call i32 @fflush(i32 %104)
br label %106
106: ; preds = %102, %41
%107 = load i32, i32* %3
%108 = add nsw i32 %107, 16
store i32 %108, i32* %3
br label %10
109: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"%04x: *%c\00"
@stdout = global i32 0
@.str.1 = [6 x i8] c"%04x:\00"
@.str.2 = [6 x i8] c" %02x\00"
@.str.3 = [3 x i8] c" \00"
define void @dump_flash(i64 %0) {
%2 = alloca [256 x i32]
%3 = alloca [256 x i32]
%4 = bitcast [256 x i32]* %2 to i8*
%5 = bitcast [256 x i32]* %3 to i8*
%6 = tail call i32 (...) @flash_init()
%7 = icmp eq i64 %0, 0
br i1 %7, label %60, label %8
8: ; preds = %1
%9 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%10 = getelementptr inbounds [256 x i32], [256 x i32]* %3, i64 0, i64 0
br label %11
11: ; preds = %8, %54
%12 = phi i64 [ 0, %8 ], [ %58, %54 ]
%13 = phi i32 [ 0, %8 ], [ %55, %54 ]
%14 = sub i64 %0, %12
%15 = icmp ult i64 %14, 16
%16 = select i1 %15, i64 %14, i64 16
%17 = trunc i64 %12 to i32
%18 = call i32 @flash_block_read(i32 %17, i32* %9, i64 %16)
%19 = icmp eq i64 %12, 0
br i1 %19, label %27, label %20
20: ; preds = %11
%21 = call i32 @bcmp(i8* %5, i8* %4, i64 %16)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = icmp eq i32 %13, 0
%25 = select i1 %24, i32 10, i32 13
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %25)
br label %54
27: ; preds = %20, %11
%28 = call i32 @memcpy(i32* %10, i32* %9, i64 %16)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%30 = icmp eq i64 %16, 0
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %52
33: ; preds = %27, %33
%34 = phi i64 [ %38, %33 ], [ 0, %27 ]
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %36)
%38 = add nuw nsw i64 %34, 1
%39 = icmp eq i64 %16, %38
br i1 %39, label %40, label %33
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br i1 %30, label %52, label %42
42: ; preds = %40, %42
%43 = phi i64 [ %50, %42 ], [ 0, %40 ]
%44 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = add i32 %45, -32
%47 = icmp ult i32 %46, 95
%48 = select i1 %47, i32 %45, i32 46
%49 = call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 %48)
%50 = add nuw nsw i64 %43, 1
%51 = icmp eq i64 %16, %50
br i1 %51, label %52, label %42
52: ; preds = %42, %31, %40
%53 = call i32 @putchar(i8 signext 10)
br label %54
54: ; preds = %52, %23
%55 = phi i32 [ 0, %52 ], [ 1, %23 ]
%56 = load i32, i32* @stdout
%57 = call i32 @fflush(i32 %56)
%58 = add nuw i64 %12, 16
%59 = icmp ult i64 %58, %0
br i1 %59, label %11, label %60
60: ; preds = %54, %1
ret void
}