#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*/ print(int, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned int, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void print_memdump(int level, char *info, unsigned start_addr, unsigned count,
                   unsigned char *data) {
  char buff[1000], buff1[100];
  unsigned i;
  int buff_empty;
  buff[0] = 0;
  if (info)
    strcat(buff, info);
  sprintf(buff1, "start=0x%04x, data[0..%2u]=", start_addr, count - 1);
  strcat(buff, buff1);
  buff_empty = 0;
  for (i = 0; i < count; i++) {
    if (i && (i % 16 == 0)) {
      print(level, "%s\n", buff);
      strcpy(buff, "        ");
      buff_empty = 1;
    }
    if (i % 16 == 8)
      strcat(buff, " ");
    sprintf(buff1, "%02x ", (unsigned)data[i]);
    strcat(buff, buff1);
    buff_empty = 0;
  }
  if (!buff_empty)
    print(level, "%s\n", buff);
}


x86 assembly (clang, -O0):
<print_memdump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movb   $0x0,-0x410(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     117e <print_memdump+0x3e>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x480(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x480(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x488(%rbp)
movl   $0x0,-0x484(%rbp)
mov    -0x484(%rbp),%eax
cmp    -0x18(%rbp),%eax
jae    129d <print_memdump+0x15d>
cmpl   $0x0,-0x484(%rbp)
je     1224 <print_memdump+0xe4>
mov    -0x484(%rbp),%eax
and    $0xf,%eax
cmp    $0x0,%eax
jne    1224 <print_memdump+0xe4>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    0xe1a(%rip),%rsi
call   1040 <print@plt>
lea    -0x410(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x488(%rbp)
mov    -0x484(%rbp),%eax
and    $0xf,%eax
cmp    $0x8,%eax
jne    1249 <print_memdump+0x109>
lea    -0x410(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x480(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x484(%rbp),%ecx
movzbl (%rax,%rcx,1),%edx
lea    0xdc4(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x480(%rbp),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x488(%rbp)
mov    -0x484(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x484(%rbp)
jmp    11c3 <print_memdump+0x83>
cmpl   $0x0,-0x488(%rbp)
jne    12c0 <print_memdump+0x180>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rdx
lea    0xd61(%rip),%rsi
call   1040 <print@plt>
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_memdump>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
mov    %r8,%rbx
mov    %ecx,%ebp
mov    %edx,%r14d
mov    %edi,0xc(%rsp)
movb   $0x0,0x80(%rsp)
test   %rsi,%rsi
je     1177 <print_memdump+0x37>
lea    0x80(%rsp),%rdi
call   1050 <strcat@plt>
lea    -0x1(%rbp),%ecx
lea    0xe7f(%rip),%rsi
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
lea    0x80(%rsp),%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
cmp    $0x1,%ebp
jae    11d2 <print_memdump+0x92>
lea    0xe6d(%rip),%rsi
lea    0x80(%rsp),%rdx
mov    0xc(%rsp),%edi
call   1040 <print@plt>
add    $0x468,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%r12d
lea    0x80(%rsp),%rbp
lea    0xe45(%rip),%r13
lea    0x10(%rsp),%r14
xor    %r15d,%r15d
jmp    123c <print_memdump+0xfc>
xchg   %ax,%ax
mov    0xc(%rsp),%edi
lea    0xe21(%rip),%rsi
mov    %rbp,%rdx
call   1040 <print@plt>
mov    %rbp,%rdi
lea    0xe13(%rip),%rsi
call   1030 <strcpy@plt>
movzbl (%rbx,%r15,1),%edx
mov    %r14,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1050 <strcat@plt>
add    $0x1,%r15
cmp    %r15,%r12
je     11a8 <print_memdump+0x68>
mov    %r15d,%eax
and    $0xf,%eax
test   %r15,%r15
je     124b <print_memdump+0x10b>
test   %eax,%eax
je     11f0 <print_memdump+0xb0>
cmp    $0x8,%eax
jne    1212 <print_memdump+0xd2>
mov    %rbp,%rdi
lea    0xdcd(%rip),%rsi
call   1050 <strcat@plt>
jmp    1212 <print_memdump+0xd2>

LLVM IR (-O0):
@.str = [28 x i8] c"start=0x%04x, data[0..%2u]=\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [9 x i8] c" \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [6 x i8] c"%02x \00"
define void @print_memdump(i32 %0, i8* %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca [1000 x i8]
%12 = alloca [100 x i8]
%13 = alloca i32
%14 = alloca i32
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
store i8 0, i8* %15
%16 = load i8*, i8** %7
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%20 = load i8*, i8** %7
%21 = call i32 @strcat(i8* %19, i8* %20)
br label %22
22: ; preds = %18, %5
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%24 = load i32, i32* %8
%25 = load i32, i32* %9
%26 = sub i32 %25, 1
%27 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %23, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %24, i32 %26)
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%30 = call i32 @strcat(i8* %28, i8* %29)
store i32 0, i32* %14
store i32 0, i32* %13
br label %31
31: ; preds = %67, %22
%32 = load i32, i32* %13
%33 = load i32, i32* %9
%34 = icmp ult i32 %32, %33
br i1 %34, label %35, label %70
35: ; preds = %31
%36 = load i32, i32* %13
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i32, i32* %13
%40 = urem i32 %39, 16
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %48
42: ; preds = %38
%43 = load i32, i32* %6
%44 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%45 = call i32 @print(i32 %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %44)
%46 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %14
br label %48
48: ; preds = %42, %38, %35
%49 = load i32, i32* %13
%50 = urem i32 %49, 16
%51 = icmp eq i32 %50, 8
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %55
55: ; preds = %52, %48
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%57 = load i8*, i8** %10
%58 = load i32, i32* %13
%59 = zext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = zext i8 %61 to i32
%63 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %62)
%64 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%65 = getelementptr inbounds [100 x i8], [100 x i8]* %12, i64 0, i64 0
%66 = call i32 @strcat(i8* %64, i8* %65)
store i32 0, i32* %14
br label %67
67: ; preds = %55
%68 = load i32, i32* %13
%69 = add i32 %68, 1
store i32 %69, i32* %13
br label %31
70: ; preds = %31
%71 = load i32, i32* %14
%72 = icmp ne i32 %71, 0
br i1 %72, label %77, label %73
73: ; preds = %70
%74 = load i32, i32* %6
%75 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%76 = call i32 @print(i32 %74, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %75)
br label %77
77: ; preds = %73, %70
ret void
}

LLVM IR (-O2):
@.str = [28 x i8] c"start=0x%04x, data[0..%2u]=\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [9 x i8] c" \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [6 x i8] c"%02x \00"
define void @print_memdump(i32 %0, i8* %1, i32 %2, i32 %3, i8* nocapture %4) {
%6 = alloca [1000 x i8]
%7 = alloca [100 x i8]
%8 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
store i8 0, i8* %8
%10 = icmp eq i8* %1, null
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = call i32 @strcat(i8* %8, i8* %1)
br label %13
13: ; preds = %11, %5
%14 = add i32 %3, -1
%15 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %14)
%16 = call i32 @strcat(i8* %8, i8* %9)
%17 = icmp eq i32 %3, 0
br i1 %17, label %42, label %18
18: ; preds = %13
%19 = zext i32 %3 to i64
br label %20
20: ; preds = %18, %34
%21 = phi i64 [ 0, %18 ], [ %40, %34 ]
%22 = icmp ne i64 %21, 0
%23 = trunc i64 %21 to i32
%24 = and i32 %23, 15
%25 = icmp eq i32 %24, 0
%26 = and i1 %22, %25
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 @print(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%29 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
br label %34
30: ; preds = %20
%31 = icmp eq i32 %24, 8
br i1 %31, label %32, label %34
32: ; preds = %30
%33 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %34
34: ; preds = %27, %32, %30
%35 = getelementptr inbounds i8, i8* %4, i64 %21
%36 = load i8, i8* %35
%37 = zext i8 %36 to i32
%38 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = call i32 @strcat(i8* %8, i8* %9)
%40 = add nuw nsw i64 %21, 1
%41 = icmp eq i64 %40, %19
br i1 %41, label %42, label %20
42: ; preds = %34, %13
%43 = call i32 @print(i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %8)
ret void
}