#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*/ printf(char *, ...);
void printf_buf_hex_N(unsigned char *buf, int size, char *header, int N) {
  int i;
  if (header)
    printf("%s", header);
  for (i = 0; i < size; i++) {
    if (!(i % N))
      printf("\n");
    if (!(i % 8))
      printf("|");
    printf("%02x ", buf[i]);
  }
  printf("\n");
  return;
}


x86 assembly (clang, -O0):
<printf_buf_hex_N>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1143 <printf_buf_hex_N+0x33>
mov    -0x18(%rbp),%rsi
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11be <printf_buf_hex_N+0xae>
mov    -0x20(%rbp),%eax
cltd
idivl  -0x1c(%rbp)
cmp    $0x0,%edx
jne    1174 <printf_buf_hex_N+0x64>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1196 <printf_buf_hex_N+0x86>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    114a <printf_buf_hex_N+0x3a>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printf_buf_hex_N>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %esi,%ebp
mov    %rdi,%r12
test   %rdx,%rdx
je     1146 <printf_buf_hex_N+0x26>
lea    0xec4(%rip),%rdi
mov    %rdx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11ac <printf_buf_hex_N+0x8c>
mov    %ebp,%ebx
lea    0xeb0(%rip),%r14
xor    %ebp,%ebp
jmp    1178 <printf_buf_hex_N+0x58>
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbp,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11ac <printf_buf_hex_N+0x8c>
mov    %ebp,%eax
cltd
idiv   %r15d
test   %edx,%edx
je     1190 <printf_buf_hex_N+0x70>
test   $0x7,%bpl
jne    1160 <printf_buf_hex_N+0x40>
jmp    11a0 <printf_buf_hex_N+0x80>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
test   $0x7,%bpl
jne    1160 <printf_buf_hex_N+0x40>
mov    $0x7c,%edi
call   1030 <putchar@plt>
jmp    1160 <printf_buf_hex_N+0x40>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c"|\00"
@.str.3 = [6 x i8] c"%02x \00"
define void @printf_buf_hex_N(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i8*, i8** %7
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %4
store i32 0, i32* %9
br label %16
16: ; preds = %41, %15
%17 = load i32, i32* %9
%18 = load i32, i32* %6
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %44
20: ; preds = %16
%21 = load i32, i32* %9
%22 = load i32, i32* %8
%23 = srem i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
%28 = load i32, i32* %9
%29 = srem i32 %28, 8
%30 = icmp ne i32 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %27
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %27
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = zext i8 %38 to i32
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %39)
br label %41
41: ; preds = %33
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %16
44: ; preds = %16
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.3 = [6 x i8] c"%02x \00"
define void @printf_buf_hex_N(i8* nocapture %0, i32 %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %2, null
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %8
8: ; preds = %6, %4
%9 = icmp sgt i32 %1, 0
br i1 %9, label %10, label %31
10: ; preds = %8
%11 = zext i32 %1 to i64
br label %12
12: ; preds = %10, %24
%13 = phi i64 [ 0, %10 ], [ %29, %24 ]
%14 = trunc i64 %13 to i32
%15 = srem i32 %14, %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 @putchar(i32 10)
br label %19
19: ; preds = %17, %12
%20 = and i32 %14, 7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @putchar(i32 124)
br label %24
24: ; preds = %22, %19
%25 = getelementptr inbounds i8, i8* %0, i64 %13
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %27)
%29 = add nuw nsw i64 %13, 1
%30 = icmp eq i64 %29, %11
br i1 %30, label %31, label %12
31: ; preds = %24, %8
%32 = tail call i32 @putchar(i32 10)
ret void
}