#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*/ hprintf(int, char *, unsigned char);
int /*<<< orphan*/ hputc(char, int);
int /*<<< orphan*/ hputs(char *, int);
void memdumpbfd(int fh, void *p, int len) {
  int i, mask;
  unsigned char *s;
  if (len == 0)
    return;
  s = (unsigned char *)p;
  for (; len > 0; len -= 4) {
    hputs("\t", fh);
    int size = len > 4 ? 4 : len;
    for (i = 0; i < size; ++i) {
      hprintf(fh, "0x%02x: ", s[i]);
      for (mask = 128; mask != 0; mask >>= 1)
        hputc(s[i] & mask ? '1' : '0', fh);
      hputs("   ", fh);
    }
    hputs("\n", fh);
  }
}


x86 assembly (clang, -O0):
<memdumpbfd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1151 <memdumpbfd+0x21>
jmp    1246 <memdumpbfd+0x116>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1246 <memdumpbfd+0x116>
mov    -0x4(%rbp),%esi
lea    0xe93(%rip),%rdi
call   1050 <hputs@plt>
cmpl   $0x4,-0x14(%rbp)
jle    1189 <memdumpbfd+0x59>
mov    $0x4,%eax
mov    %eax,-0x30(%rbp)
jmp    118f <memdumpbfd+0x5f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1229 <memdumpbfd+0xf9>
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe48(%rip),%rsi
movzbl (%rax,%rcx,1),%edx
call   1040 <hprintf@plt>
movl   $0x80,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     120c <memdumpbfd+0xdc>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
and    -0x1c(%rbp),%edx
mov    $0x30,%eax
mov    $0x31,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    -0x4(%rbp),%esi
movsbl %al,%edi
call   1030 <hputc@plt>
mov    -0x1c(%rbp),%eax
sar    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ca <memdumpbfd+0x9a>
mov    -0x4(%rbp),%esi
lea    0xdf5(%rip),%rdi
call   1050 <hputs@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119c <memdumpbfd+0x6c>
mov    -0x4(%rbp),%esi
lea    0xddc(%rip),%rdi
call   1050 <hputs@plt>
mov    -0x14(%rbp),%eax
sub    $0x4,%eax
mov    %eax,-0x14(%rbp)
jmp    1159 <memdumpbfd+0x29>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<memdumpbfd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
jle    128e <memdumpbfd+0x15e>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xeb0(%rip),%r12
lea    0xeb2(%rip),%r13
mov    %edx,%r15d
nopl   0x0(%rax)
lea    0xe99(%rip),%rdi
mov    %ebp,%esi
call   1050 <hputs@plt>
sub    $0x4,%r15d
mov    %r15d,(%rsp)
mov    $0x4,%r15d
mov    %r14d,0x4(%rsp)
cmovb  %r14d,%r15d
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%r14,1),%edx
mov    %ebp,%edi
mov    %r12,%rsi
call   1040 <hprintf@plt>
xor    %edi,%edi
cmpb   $0x0,(%rbx,%r14,1)
setns  %dil
xor    $0x31,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x40,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x20,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x10,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x8,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x4,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x2,%al
cmp    $0x1,%al
mov    $0x31,%edi
sbb    $0x0,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
movzbl (%rbx,%r14,1),%eax
and    $0x1,%al
or     $0x30,%al
movzbl %al,%edi
mov    %ebp,%esi
call   1030 <hputc@plt>
mov    %r13,%rdi
mov    %ebp,%esi
call   1050 <hputs@plt>
add    $0x1,%r14
cmp    %r15,%r14
jb     1190 <memdumpbfd+0x60>
lea    0xd9a(%rip),%rdi
mov    %ebp,%esi
call   1050 <hputs@plt>
cmpl   $0x4,0x4(%rsp)
mov    (%rsp),%r15d
mov    %r15d,%r14d
jg     1160 <memdumpbfd+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\09\00"
@.str.1 = [9 x i8] c"0x%02x: \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @memdumpbfd(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
br label %74
14: ; preds = %3
%15 = load i8*, i8** %5
store i8* %15, i8** %9
br label %16
16: ; preds = %71, %14
%17 = load i32, i32* %6
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %74
19: ; preds = %16
%20 = load i32, i32* %4
%21 = call i32 @hputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %6
%23 = icmp sgt i32 %22, 4
br i1 %23, label %24, label %25
24: ; preds = %19
br label %27
25: ; preds = %19
%26 = load i32, i32* %6
br label %27
27: ; preds = %25, %24
%28 = phi i32 [ 4, %24 ], [ %26, %25 ]
store i32 %28, i32* %10
store i32 0, i32* %7
br label %29
29: ; preds = %65, %27
%30 = load i32, i32* %7
%31 = load i32, i32* %10
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %68
33: ; preds = %29
%34 = load i32, i32* %4
%35 = load i8*, i8** %9
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call i32 @hprintf(i32 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %39)
store i32 128, i32* %8
br label %41
41: ; preds = %59, %33
%42 = load i32, i32* %8
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %62
44: ; preds = %41
%45 = load i8*, i8** %9
%46 = load i32, i32* %7
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %45, i64 %47
%49 = load i8, i8* %48
%50 = zext i8 %49 to i32
%51 = load i32, i32* %8
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
%54 = zext i1 %53 to i64
%55 = select i1 %53, i32 49, i32 48
%56 = trunc i32 %55 to i8
%57 = load i32, i32* %4
%58 = call i32 @hputc(i8 signext %56, i32 %57)
br label %59
59: ; preds = %44
%60 = load i32, i32* %8
%61 = ashr i32 %60, 1
store i32 %61, i32* %8
br label %41
62: ; preds = %41
%63 = load i32, i32* %4
%64 = call i32 @hputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %65
65: ; preds = %62
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %29
68: ; preds = %29
%69 = load i32, i32* %4
%70 = call i32 @hputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %69)
br label %71
71: ; preds = %68
%72 = load i32, i32* %6
%73 = sub nsw i32 %72, 4
store i32 %73, i32* %6
br label %16
74: ; preds = %13, %16
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\09\00"
@.str.1 = [9 x i8] c"0x%02x: \00"
@.str.2 = [4 x i8] c" \00"
@.str.3 = [2 x i8] c"\0A\00"
define void @memdumpbfd(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %61
5: ; preds = %3, %57
%6 = phi i32 [ %59, %57 ], [ %2, %3 ]
%7 = tail call i32 @hputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %0)
%8 = icmp ult i32 %6, 4
%9 = select i1 %8, i32 %6, i32 4
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %5, %11
%12 = phi i64 [ 0, %5 ], [ %55, %11 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = tail call i32 @hprintf(i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %14)
%16 = load i8, i8* %13
%17 = icmp sgt i8 %16, -1
%18 = select i1 %17, i8 48, i8 49
%19 = tail call i32 @hputc(i8 signext %18, i32 %0)
%20 = load i8, i8* %13
%21 = and i8 %20, 64
%22 = icmp eq i8 %21, 0
%23 = select i1 %22, i8 48, i8 49
%24 = tail call i32 @hputc(i8 signext %23, i32 %0)
%25 = load i8, i8* %13
%26 = and i8 %25, 32
%27 = icmp eq i8 %26, 0
%28 = select i1 %27, i8 48, i8 49
%29 = tail call i32 @hputc(i8 signext %28, i32 %0)
%30 = load i8, i8* %13
%31 = and i8 %30, 16
%32 = icmp eq i8 %31, 0
%33 = select i1 %32, i8 48, i8 49
%34 = tail call i32 @hputc(i8 signext %33, i32 %0)
%35 = load i8, i8* %13
%36 = and i8 %35, 8
%37 = icmp eq i8 %36, 0
%38 = select i1 %37, i8 48, i8 49
%39 = tail call i32 @hputc(i8 signext %38, i32 %0)
%40 = load i8, i8* %13
%41 = and i8 %40, 4
%42 = icmp eq i8 %41, 0
%43 = select i1 %42, i8 48, i8 49
%44 = tail call i32 @hputc(i8 signext %43, i32 %0)
%45 = load i8, i8* %13
%46 = and i8 %45, 2
%47 = icmp eq i8 %46, 0
%48 = select i1 %47, i8 48, i8 49
%49 = tail call i32 @hputc(i8 signext %48, i32 %0)
%50 = load i8, i8* %13
%51 = and i8 %50, 1
%52 = or i8 %51, 48
%53 = tail call i32 @hputc(i8 signext %52, i32 %0)
%54 = tail call i32 @hputs(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%55 = add nuw nsw i64 %12, 1
%56 = icmp ult i64 %55, %10
br i1 %56, label %11, label %57
57: ; preds = %11
%58 = tail call i32 @hputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i32 %0)
%59 = add nsw i32 %6, -4
%60 = icmp sgt i32 %6, 4
br i1 %60, label %5, label %61
61: ; preds = %57, %3
ret void
}