#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*/ ap_log_hprintf(int, char *, unsigned char, unsigned char);
int /*<<< orphan*/ ap_log_hputc(char, int);
scalar_t__ isprint(unsigned char);
void ap_log_mem_dump_to_fd(int file_handle, void *memory_area, int len) {
  int i;
  int addr;
  int showaddr;
  int linelen;
  unsigned char *s;
  if (len == 0)
    return;
  showaddr = (len > 48);
  addr = 0;
  s = (unsigned char *)memory_area;
  for (; len > 0; len -= 16, addr += 16) {
    if (showaddr)
      ap_log_hprintf(file_handle, "%04x(%4d):  ", addr, addr);
    linelen = len > 16 ? 16 : len;
    for (i = 0; i < linelen; ++i)
      ap_log_hprintf(file_handle, "%02x %c ", s[i], isprint(s[i]) ? s[i] : '.');
    ap_log_hputc('\n', file_handle);
    s += linelen;
  }
}


x86 assembly (clang, -O0):
<ap_log_mem_dump_to_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1151 <ap_log_mem_dump_to_fd+0x21>
jmp    1284 <ap_log_mem_dump_to_fd+0x154>
cmpl   $0x30,-0x14(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1284 <ap_log_mem_dump_to_fd+0x154>
cmpl   $0x0,-0x20(%rbp)
je     11a0 <ap_log_mem_dump_to_fd+0x70>
mov    -0x4(%rbp),%edi
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x1c(%rbp),%eax
lea    0xe6b(%rip),%rsi
movzbl %cl,%edx
movzbl %al,%ecx
call   1050 <ap_log_hprintf@plt>
cmpl   $0x10,-0x14(%rbp)
jle    11b7 <ap_log_mem_dump_to_fd+0x87>
mov    $0x10,%eax
mov    %eax,-0x34(%rbp)
jmp    11bd <ap_log_mem_dump_to_fd+0x8d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    124f <ap_log_mem_dump_to_fd+0x11f>
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x35(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1219 <ap_log_mem_dump_to_fd+0xe9>
mov    -0x30(%rbp),%rax
movslq -0x18(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x40(%rbp)
jmp    1226 <ap_log_mem_dump_to_fd+0xf6>
mov    $0x2e,%eax
mov    %eax,-0x40(%rbp)
jmp    1226 <ap_log_mem_dump_to_fd+0xf6>
mov    -0x35(%rbp),%cl
mov    -0x3c(%rbp),%edi
mov    -0x40(%rbp),%eax
lea    0xdd7(%rip),%rsi
movzbl %cl,%edx
movzbl %al,%ecx
call   1050 <ap_log_hprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ca <ap_log_mem_dump_to_fd+0x9a>
mov    -0x4(%rbp),%esi
mov    $0xa,%edi
call   1030 <ap_log_hputc@plt>
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x10,%eax
mov    %eax,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x1c(%rbp)
jmp    116f <ap_log_mem_dump_to_fd+0x3f>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ap_log_mem_dump_to_fd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,0x4(%rsp)
test   %edx,%edx
je     1217 <ap_log_mem_dump_to_fd+0xe7>
jle    1217 <ap_log_mem_dump_to_fd+0xe7>
mov    %rsi,%rbx
mov    %edi,%r13d
xor    %ebp,%ebp
lea    0xeae(%rip),%r12
mov    0x4(%rsp),%r14d
jmp    1198 <ap_log_mem_dump_to_fd+0x68>
cs nopw 0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %r13d,%esi
call   1030 <ap_log_hputc@plt>
add    %r15,%rbx
mov    0x10(%rsp),%rbp
add    $0x10,%ebp
cmpl   $0x10,0xc(%rsp)
mov    0x8(%rsp),%r14d
jle    1217 <ap_log_mem_dump_to_fd+0xe7>
cmpl   $0x31,0x4(%rsp)
jl     11b4 <ap_log_mem_dump_to_fd+0x84>
movzbl %bpl,%ecx
mov    %r13d,%edi
lea    0xe53(%rip),%rsi
mov    %ecx,%edx
call   1050 <ap_log_hprintf@plt>
mov    %rbp,0x10(%rsp)
mov    %r14d,%eax
sub    $0x10,%eax
mov    %eax,0x8(%rsp)
mov    $0x10,%r15d
mov    %r14d,0xc(%rsp)
cmovb  %r14d,%r15d
xor    %r14d,%r14d
jmp    1202 <ap_log_mem_dump_to_fd+0xd2>
nopw   0x0(%rax,%rax,1)
movzbl (%rbx,%r14,1),%eax
movzbl %al,%ecx
mov    %r13d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <ap_log_hprintf@plt>
add    $0x1,%r14
cmp    %r15,%r14
jae    1170 <ap_log_mem_dump_to_fd+0x40>
movzbl (%rbx,%r14,1),%ebp
mov    %ebp,%edi
call   1040 <isprint@plt>
test   %rax,%rax
jne    11e0 <ap_log_mem_dump_to_fd+0xb0>
mov    $0x2e,%al
jmp    11e5 <ap_log_mem_dump_to_fd+0xb5>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"%04x(%4d): \00"
@.str.1 = [9 x i8] c"%02x %c \00"
define void @ap_log_mem_dump_to_fd(i32 %0, i8* nocapture %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %38, label %5
5: ; preds = %3
%6 = icmp sgt i32 %2, 48
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %38
8: ; preds = %5, %32
%9 = phi i8* [ %34, %32 ], [ %1, %5 ]
%10 = phi i32 [ %35, %32 ], [ %2, %5 ]
%11 = phi i32 [ %36, %32 ], [ 0, %5 ]
br i1 %6, label %12, label %15
12: ; preds = %8
%13 = trunc i32 %11 to i8
%14 = tail call i32 @ap_log_hprintf(i32 %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8 zeroext %13, i8 zeroext %13)
br label %15
15: ; preds = %12, %8
%16 = icmp ult i32 %10, 16
%17 = select i1 %16, i32 %10, i32 16
%18 = zext i32 %17 to i64
br label %19
19: ; preds = %15, %27
%20 = phi i64 [ 0, %15 ], [ %30, %27 ]
%21 = getelementptr inbounds i8, i8* %9, i64 %20
%22 = load i8, i8* %21
%23 = tail call i64 @isprint(i8 zeroext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19
%26 = load i8, i8* %21
br label %27
27: ; preds = %19, %25
%28 = phi i8 [ %26, %25 ], [ 46, %19 ]
%29 = tail call i32 @ap_log_hprintf(i32 %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %22, i8 zeroext %28)
%30 = add nuw nsw i64 %20, 1
%31 = icmp ult i64 %30, %18
br i1 %31, label %19, label %32
32: ; preds = %27
%33 = tail call i32 @ap_log_hputc(i8 signext 10, i32 %0)
%34 = getelementptr inbounds i8, i8* %9, i64 %18
%35 = add nsw i32 %10, -16
%36 = add nuw nsw i32 %11, 16
%37 = icmp sgt i32 %10, 16
br i1 %37, label %8, label %38
38: ; preds = %32, %5, %3
ret void
}