#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 /*<<< orphan*/ byteToHex(char, char *);
int /*<<< orphan*/ printf(char *, ...);
void dumpMemoryAsHex(char *data, char *dataEnd, int count) {
  static char hexbuff[3] = {0, 0, 0};
  int i = 0;
  while (i < count) {
    if (&data[i] >= dataEnd)
      break;
    byteToHex(data[i++], hexbuff);
    printf("%s ", hexbuff);
  }
  for (; i < count; i++) {
    printf(".. ");
  }
}


x86 assembly (clang, -O0):
<dumpMemoryAsHex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    119c <dumpMemoryAsHex+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
add    %rcx,%rax
cmp    -0x10(%rbp),%rax
jb     1160 <dumpMemoryAsHex+0x40>
jmp    119c <dumpMemoryAsHex+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x18(%rbp)
movslq %ecx,%rcx
lea    0x2eb8(%rip),%rsi
movsbl (%rax,%rcx,1),%edi
call   1040 <byteToHex@plt>
lea    0xe77(%rip),%rdi
lea    0x2ea1(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    113a <dumpMemoryAsHex+0x1a>
jmp    11a1 <dumpMemoryAsHex+0x81>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c9 <dumpMemoryAsHex+0xa9>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <dumpMemoryAsHex+0x81>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dumpMemoryAsHex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
test   %edx,%edx
jle    1184 <dumpMemoryAsHex+0x64>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %ebx,%r13d
lea    0x2ef0(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%r15,%rbp,1),%rax
cmp    %r14,%rax
jae    117e <dumpMemoryAsHex+0x5e>
add    $0x1,%rbp
movsbl (%rax),%edi
mov    %r12,%rsi
call   1040 <byteToHex@plt>
lea    0xe91(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %rbp,%r13
jne    1150 <dumpMemoryAsHex+0x30>
cmp    %ebx,%ebp
jl     118a <dumpMemoryAsHex+0x6a>
jmp    11af <dumpMemoryAsHex+0x8f>
xor    %ebp,%ebp
cmp    %ebx,%ebp
jge    11af <dumpMemoryAsHex+0x8f>
sub    %ebp,%ebx
lea    0xe71(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0xffffffff,%ebx
jne    11a0 <dumpMemoryAsHex+0x80>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@dumpMemoryAsHex.hexbuff = internal global [3 x i8] zeroinitializer
@.str = [4 x i8] c"%s \00"
@.str.1 = [4 x i8] c".. \00"
define void @dumpMemoryAsHex(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %20, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8*, i8** %5
%18 = icmp uge i8* %16, %17
br i1 %18, label %19, label %20
19: ; preds = %12
br label %29
20: ; preds = %12
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @byteToHex(i8 signext %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @dumpMemoryAsHex.hexbuff, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @dumpMemoryAsHex.hexbuff, i64 0, i64 0))
br label %8
29: ; preds = %19, %8
br label %30
30: ; preds = %36, %29
%31 = load i32, i32* %7
%32 = load i32, i32* %6
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %36
36: ; preds = %34
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %30
39: ; preds = %30
ret void
}

LLVM IR (-O2):
@dumpMemoryAsHex.hexbuff = internal global [3 x i8] zeroinitializer
@.str = [4 x i8] c"%s \00"
@.str.1 = [4 x i8] c".. \00"
define void @dumpMemoryAsHex(i8* %0, i8* readnone %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %20
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %11
%8 = phi i64 [ 0, %5 ], [ %12, %11 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = icmp ult i8* %9, %1
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = add nuw nsw i64 %8, 1
%13 = load i8, i8* %9
%14 = tail call i32 @byteToHex(i8 signext %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @dumpMemoryAsHex.hexbuff, i64 0, i64 0))
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @dumpMemoryAsHex.hexbuff, i64 0, i64 0))
%16 = icmp eq i64 %12, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %11
%18 = phi i64 [ %12, %11 ], [ %8, %7 ]
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %17, %3
%21 = phi i32 [ 0, %3 ], [ %19, %17 ]
%22 = icmp slt i32 %21, %2
br i1 %22, label %23, label %28
23: ; preds = %20, %23
%24 = phi i32 [ %26, %23 ], [ %21, %20 ]
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%26 = add nuw i32 %24, 1
%27 = icmp eq i32 %26, %2
br i1 %27, label %28, label %23
28: ; preds = %23, %20
ret void
}