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

/* Variables and functions */
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ isprint(char);
void LogContinuousBuffer(const uint8_t *p, unsigned n, FILE *out_file) {
  size_t len = n + 1;
  char *txt = (char *)calloc(len, sizeof(char));
  if (txt != NULL) {
    unsigned odx = 0, idx = 0;
    for (idx = 0; idx < n; idx++) {
      uint8_t byte = p[idx];
      txt[odx++] = isprint(byte) ? byte : '.';
    }
    txt[odx] = '\0';
    fprintf(out_file, "%s\n", txt);
    free(txt);
  }
}


x86 assembly (clang, -O0):
<LogContinuousBuffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1225 <LogContinuousBuffer+0xe5>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    11fd <LogContinuousBuffer+0xbd>
mov    -0x8(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x31(%rbp)
movsbl -0x31(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     11c9 <LogContinuousBuffer+0x89>
movsbl -0x31(%rbp),%eax
mov    %eax,-0x38(%rbp)
jmp    11d6 <LogContinuousBuffer+0x96>
mov    $0x2e,%eax
mov    %eax,-0x38(%rbp)
jmp    11d6 <LogContinuousBuffer+0x96>
mov    -0x38(%rbp),%eax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x2c(%rbp)
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1191 <LogContinuousBuffer+0x51>
mov    -0x28(%rbp),%rax
mov    -0x2c(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<LogContinuousBuffer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r15
lea    0x1(%r12),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     11a7 <LogContinuousBuffer+0x67>
mov    %rax,%r13
test   %r12d,%r12d
je     11b6 <LogContinuousBuffer+0x76>
mov    %rbx,(%rsp)
mov    %r12d,%r12d
xor    %ebx,%ebx
mov    $0x2e,%r14d
nop
movsbl (%r15,%rbx,1),%ebp
mov    %ebp,%edi
call   1060 <isprint@plt>
test   %rax,%rax
cmove  %r14d,%ebp
mov    %bpl,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <LogContinuousBuffer+0x40>
mov    (%rsp),%rbx
jmp    11b9 <LogContinuousBuffer+0x79>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r12d,%r12d
movb   $0x0,0x0(%r13,%r12,1)
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1050 <fprintf@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define void @LogContinuousBuffer(i8* nocapture %0, i32 %1, i32* nocapture %2) {
%4 = add i32 %1, 1
%5 = zext i32 %4 to i64
%6 = tail call i64 @calloc(i64 %5, i32 1)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %30, label %9
9: ; preds = %3
%10 = icmp eq i32 %1, 0
br i1 %10, label %25, label %11
11: ; preds = %9
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %20, %13 ]
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i64 @isprint(i8 signext %16)
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, i8 46, i8 %16
%20 = add nuw nsw i64 %14, 1
%21 = getelementptr inbounds i8, i8* %7, i64 %14
store i8 %19, i8* %21
%22 = icmp eq i64 %20, %12
br i1 %22, label %23, label %13
23: ; preds = %13
%24 = zext i32 %1 to i64
br label %25
25: ; preds = %9, %23
%26 = phi i64 [ %24, %23 ], [ 0, %9 ]
%27 = getelementptr inbounds i8, i8* %7, i64 %26
store i8 0, i8* %27
%28 = tail call i32 @fprintf(i32* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %7)
%29 = tail call i32 @free(i8* %7)
br label %30
30: ; preds = %25, %3
ret void
}