#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 */
scalar_t__ isprint(unsigned char);
int /*<<< orphan*/ printf(char *, ...);
void writeln(unsigned char *buffer, size_t numBytes, int offset,
             int bytesPerLine) {
  printf("%6X |", offset);
  for (int i = 0; i < bytesPerLine; i++) {
    if (i > 0 && i % 4 == 0) {
      printf(" ");
    }
    if (i < numBytes) {
      printf(" %02X", buffer[i]);
    } else {
      printf("   ");
    }
  }
  printf(" | ");
  for (int i = 0; i < numBytes; i++) {
    printf("%c", isprint(buffer[i]) ? buffer[i] : '.');
  }
  printf("\n");
}


x86 assembly (clang, -O0):
<writeln>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%esi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11d4 <writeln+0xb4>
cmpl   $0x0,-0x1c(%rbp)
jle    1186 <writeln+0x66>
mov    -0x1c(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1186 <writeln+0x66>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x1c(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b3 <writeln+0x93>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c1 <writeln+0xa1>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c6 <writeln+0xa6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114e <writeln+0x2e>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1252 <writeln+0x132>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1226 <writeln+0x106>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
jmp    1233 <writeln+0x113>
mov    $0x2e,%eax
mov    %eax,-0x24(%rbp)
jmp    1233 <writeln+0x113>
mov    -0x24(%rbp),%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e9 <writeln+0xc9>
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeln>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xeb6(%rip),%rdi
mov    %edx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11b1 <writeln+0x81>
mov    %ebp,%r13d
lea    0xea5(%rip),%r15
lea    0xea4(%rip),%r12
xor    %ebp,%ebp
jmp    1183 <writeln+0x53>
nopl   0x0(%rax)
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11b1 <writeln+0x81>
test   %rbp,%rbp
je     119c <writeln+0x6c>
mov    %ebp,%eax
and    $0x3,%eax
test   %rax,%rax
jne    119c <writeln+0x6c>
mov    $0x20,%edi
call   1030 <putchar@plt>
cmp    %r14,%rbp
jae    1170 <writeln+0x40>
movzbl (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    117a <writeln+0x4a>
lea    0xe58(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r14,%r14
je     11f7 <writeln+0xc7>
xor    %ebp,%ebp
jmp    11e2 <writeln+0xb2>
nopl   0x0(%rax,%rax,1)
movzbl (%rbx,%rbp,1),%edi
call   1030 <putchar@plt>
add    $0x1,%rbp
cmp    %rbp,%r14
je     11f7 <writeln+0xc7>
movzbl (%rbx,%rbp,1),%edi
call   1050 <isprint@plt>
test   %rax,%rax
jne    11d0 <writeln+0xa0>
mov    $0x2e,%edi
jmp    11d4 <writeln+0xa4>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

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

LLVM IR (-O2):
@.str = [6 x i8] c"%6X |\00"
@.str.2 = [6 x i8] c" %02X\00"
@.str.3 = [4 x i8] c" \00"
@.str.4 = [4 x i8] c" | \00"
define void @writeln(i8* nocapture %0, i64 %1, i32 %2, i32 %3) {
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %2)
%6 = icmp sgt i32 %3, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = zext i32 %3 to i64
br label %12
9: ; preds = %29, %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp eq i64 %1, 0
br i1 %11, label %32, label %34
12: ; preds = %7, %29
%13 = phi i64 [ 0, %7 ], [ %30, %29 ]
%14 = icmp ne i64 %13, 0
%15 = and i64 %13, 3
%16 = icmp eq i64 %15, 0
%17 = and i1 %14, %16
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = tail call i32 @putchar(i32 32)
br label %20
20: ; preds = %18, %12
%21 = icmp ult i64 %13, %1
br i1 %21, label %22, label %27
22: ; preds = %20
%23 = getelementptr inbounds i8, i8* %0, i64 %13
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %25)
br label %29
27: ; preds = %20
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %22, %27
%30 = add nuw nsw i64 %13, 1
%31 = icmp eq i64 %30, %8
br i1 %31, label %9, label %12
32: ; preds = %43, %9
%33 = tail call i32 @putchar(i32 10)
ret void
34: ; preds = %9, %43
%35 = phi i64 [ %46, %43 ], [ 0, %9 ]
%36 = getelementptr inbounds i8, i8* %0, i64 %35
%37 = load i8, i8* %36
%38 = tail call i64 @isprint(i8 zeroext %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = load i8, i8* %36
%42 = zext i8 %41 to i32
br label %43
43: ; preds = %34, %40
%44 = phi i32 [ %42, %40 ], [ 46, %34 ]
%45 = tail call i32 @putchar(i32 %44)
%46 = add nuw i64 %35, 1
%47 = icmp eq i64 %46, %1
br i1 %47, label %32, label %34
}