#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*/ uint8_t;
typedef int uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
void DumpRange(FILE *fp, uint8_t *image, int imageOffset, int endOffset) {
  uint32_t *imagePtr = (uint32_t *)(image + imageOffset);
  int needComma = 0;
  int cnt = 0;
  while (imageOffset < endOffset) {
    uint32_t value = *imagePtr++;
    if (needComma) {
      fprintf(fp, ",");
      needComma = 0;
    }
    if ((cnt % 16) == 0)
      fprintf(fp, "\n/* %04x */ ", imageOffset);
    fprintf(fp, "0x%02X,0x%02X,0x%02X,0x%02X", (value & 0xff),
            ((value >> 8) & 0xff), ((value >> 16) & 0xff),
            ((value >> 24) & 0xff));
    imageOffset += sizeof(uint32_t);
    needComma = 1;
    cnt += 4;
  }
}


x86 assembly (clang, -O0):
<DumpRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1218 <DumpRange+0x108>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     118a <DumpRange+0x7a>
mov    -0x8(%rbp),%rdi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x10,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11b3 <DumpRange+0xa3>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%edx
and    $0xff,%edx
mov    -0x2c(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0x2c(%rbp),%r8d
sar    $0x10,%r8d
and    $0xff,%r8d
mov    -0x2c(%rbp),%r9d
sar    $0x18,%r9d
and    $0xff,%r9d
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movslq -0x14(%rbp),%rax
add    $0x4,%rax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x28(%rbp)
jmp    1147 <DumpRange+0x37>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DumpRange>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %ecx,%edx
jge    11f1 <DumpRange+0xd1>
mov    %ecx,%r13d
mov    %edx,%r14d
mov    %rdi,%r15
movslq %edx,%rax
lea    (%rsi,%rax,4),%r12
mov    (%r12),%ebx
lea    0xeb2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
movzbl %bl,%edx
movzbl %bh,%ecx
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%r8d
shr    $0x18,%ebx
lea    0xe9f(%rip),%rsi
mov    %r15,%rdi
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0x4(%r14),%eax
cmp    %r13d,%eax
jge    11f1 <DumpRange+0xd1>
mov    %r14d,%ebp
mov    $0x4,%r14d
jmp    11c3 <DumpRange+0xa3>
nop
movzbl %bl,%edx
movzbl %bh,%ecx
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%r8d
shr    $0x18,%ebx
mov    %r15,%rdi
lea    0xe61(%rip),%rsi
mov    %ebx,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x4,%r14
lea    (%r14,%rbp,1),%eax
cmp    %r13d,%eax
jge    11f1 <DumpRange+0xd1>
mov    (%r12,%r14,1),%ebx
mov    $0x2c,%edi
mov    %r15,%rsi
call   1030 <fputc@plt>
test   $0xc,%r14b
jne    1190 <DumpRange+0x70>
lea    (%r14,%rbp,1),%rdx
mov    %r15,%rdi
lea    0xe18(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1190 <DumpRange+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
@.str.1 = [13 x i8] c"\0A/* %04x */ \00"
@.str.2 = [28 x i8] c"0x%02X,0x%02X,0x%02X,0x%02X\00"
define void @DumpRange(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32*, i32** %6
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
store i32* %16, i32** %9
store i32 0, i32* %10
store i32 0, i32* %11
br label %17
17: ; preds = %38, %4
%18 = load i32, i32* %7
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %58
21: ; preds = %17
%22 = load i32*, i32** %9
%23 = getelementptr inbounds i32, i32* %22, i32 1
store i32* %23, i32** %9
%24 = load i32, i32* %22
store i32 %24, i32* %12
%25 = load i32, i32* %10
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32*, i32** %5
%29 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %10
br label %30
30: ; preds = %27, %21
%31 = load i32, i32* %11
%32 = srem i32 %31, 16
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i32*, i32** %5
%36 = load i32, i32* %7
%37 = call i32 (i32*, i8*, ...) @fprintf(i32* %35, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %30
%39 = load i32*, i32** %5
%40 = load i32, i32* %12
%41 = and i32 %40, 255
%42 = load i32, i32* %12
%43 = ashr i32 %42, 8
%44 = and i32 %43, 255
%45 = load i32, i32* %12
%46 = ashr i32 %45, 16
%47 = and i32 %46, 255
%48 = load i32, i32* %12
%49 = ashr i32 %48, 24
%50 = and i32 %49, 255
%51 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %41, i32 %44, i32 %47, i32 %50)
%52 = load i32, i32* %7
%53 = sext i32 %52 to i64
%54 = add i64 %53, 4
%55 = trunc i64 %54 to i32
store i32 %55, i32* %7
store i32 1, i32* %10
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 4
store i32 %57, i32* %11
br label %17
58: ; preds = %17
ret void
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"\0A/* %04x */ \00"
@.str.2 = [28 x i8] c"0x%02X,0x%02X,0x%02X,0x%02X\00"
define void @DumpRange(i32* nocapture %0, i32* nocapture %1, i32 %2, i32 %3) {
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds i32, i32* %1, i64 %5
%7 = icmp slt i32 %2, %3
br i1 %7, label %8, label %42
8: ; preds = %4
%9 = load i32, i32* %6
%10 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%11 = and i32 %9, 255
%12 = lshr i32 %9, 8
%13 = and i32 %12, 255
%14 = lshr i32 %9, 16
%15 = and i32 %14, 255
%16 = lshr i32 %9, 24
%17 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %11, i32 %13, i32 %15, i32 %16)
%18 = add i32 %2, 4
%19 = icmp slt i32 %18, %3
br i1 %19, label %20, label %42
20: ; preds = %8, %31
%21 = phi i32 [ %39, %31 ], [ %18, %8 ]
%22 = phi i32 [ %40, %31 ], [ 4, %8 ]
%23 = phi i32* [ %24, %31 ], [ %6, %8 ]
%24 = getelementptr inbounds i32, i32* %23, i64 1
%25 = load i32, i32* %24
%26 = tail call i32 @fputc(i32 44, i32* %0)
%27 = and i32 %22, 12
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %20
%30 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %21)
br label %31
31: ; preds = %29, %20
%32 = and i32 %25, 255
%33 = lshr i32 %25, 8
%34 = and i32 %33, 255
%35 = lshr i32 %25, 16
%36 = and i32 %35, 255
%37 = lshr i32 %25, 24
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %32, i32 %34, i32 %36, i32 %37)
%39 = add i32 %21, 4
%40 = add nuw nsw i32 %22, 4
%41 = icmp slt i32 %39, %3
br i1 %41, label %20, label %42
42: ; preds = %31, %8, %4
ret void
}