#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 */
void hex_convert_memory(const unsigned char *m, size_t n, char *b,
                        size_t width) {
  size_t i;
  for (i = 0; i < n; i++) {
    const unsigned char c = *m++;
    *b++ = "0123456789abcdef"[c >> 4];
    *b++ = "0123456789abcdef"[c & 15];
    if (i % width == width - 1 && i != n - 1)
      *b++ = ' ';
  }
  *b = '\0';
}


x86 assembly (clang, -O0):
<hex_convert_memory>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11e2 <hex_convert_memory+0xe2>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0x29(%rbp)
movzbl -0x29(%rbp),%eax
sar    $0x4,%eax
movslq %eax,%rcx
lea    0xeb1(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movzbl -0x29(%rbp),%eax
and    $0xf,%eax
movslq %eax,%rcx
lea    0xe8c(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    $0x1,%rax
cmp    %rax,%rdx
jne    11cc <hex_convert_memory+0xcc>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
je     11cc <hex_convert_memory+0xcc>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x20,(%rax)
jmp    11d1 <hex_convert_memory+0xd1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    111c <hex_convert_memory+0x1c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_convert_memory>:
push   %rbx
mov    %rdx,%r9
test   %rsi,%rsi
je     1183 <hex_convert_memory+0x83>
lea    -0x1(%rcx),%r10
lea    -0x1(%rsi),%r11
xor    %r8d,%r8d
lea    0xee5(%rip),%rbx
jmp    112c <hex_convert_memory+0x2c>
nopl   (%rax)
add    $0x1,%r8
mov    %rax,%r9
cmp    %r8,%rsi
je     1186 <hex_convert_memory+0x86>
movzbl (%rdi,%r8,1),%eax
mov    %rax,%rdx
shr    $0x4,%rdx
movzbl (%rdx,%rbx,1),%edx
mov    %dl,(%r9)
and    $0xf,%eax
movzbl (%rax,%rbx,1),%eax
mov    %al,0x1(%r9)
mov    %r8,%rax
or     %rcx,%rax
shr    $0x20,%rax
je     1160 <hex_convert_memory+0x60>
mov    %r8,%rax
xor    %edx,%edx
div    %rcx
jmp    1167 <hex_convert_memory+0x67>
mov    %r8d,%eax
xor    %edx,%edx
div    %ecx
lea    0x2(%r9),%rax
cmp    %r8,%r11
je     1120 <hex_convert_memory+0x20>
cmp    %r10,%rdx
jne    1120 <hex_convert_memory+0x20>
movb   $0x20,0x2(%r9)
add    $0x3,%r9
mov    %r9,%rax
jmp    1120 <hex_convert_memory+0x20>
mov    %r9,%rax
movb   $0x0,(%rax)
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @hex_convert_memory(i8* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i64 0, i64* %9
br label %11
11: ; preds = %50, %4
%12 = load i64, i64* %9
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %53
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %5
%18 = load i8, i8* %16
store i8 %18, i8* %10
%19 = load i8, i8* %10
%20 = zext i8 %19 to i32
%21 = ashr i32 %20, 4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = load i8*, i8** %7
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %7
store i8 %24, i8* %25
%27 = load i8, i8* %10
%28 = zext i8 %27 to i32
%29 = and i32 %28, 15
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %30
%32 = load i8, i8* %31
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
store i8 %32, i8* %33
%35 = load i64, i64* %9
%36 = load i64, i64* %8
%37 = urem i64 %35, %36
%38 = load i64, i64* %8
%39 = sub i64 %38, 1
%40 = icmp eq i64 %37, %39
br i1 %40, label %41, label %49
41: ; preds = %15
%42 = load i64, i64* %9
%43 = load i64, i64* %6
%44 = sub i64 %43, 1
%45 = icmp ne i64 %42, %44
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i8*, i8** %7
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %7
store i8 32, i8* %47
br label %49
49: ; preds = %46, %41, %15
br label %50
50: ; preds = %49
%51 = load i64, i64* %9
%52 = add i64 %51, 1
store i64 %52, i64* %9
br label %11
53: ; preds = %11
%54 = load i8*, i8** %7
store i8 0, i8* %54
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
define void @hex_convert_memory(i8* nocapture %0, i64 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = icmp eq i64 %1, 0
br i1 %5, label %36, label %6
6: ; preds = %4
%7 = add i64 %3, -1
%8 = add i64 %1, -1
br label %9
9: ; preds = %6, %32
%10 = phi i8* [ %0, %6 ], [ %13, %32 ]
%11 = phi i64 [ 0, %6 ], [ %34, %32 ]
%12 = phi i8* [ %2, %6 ], [ %33, %32 ]
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = load i8, i8* %10
%15 = zext i8 %14 to i32
%16 = lshr i32 %15, 4
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %19, i8* %12
%21 = and i32 %15, 15
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds [17 x i8], [17 x i8]* @.str, i64 0, i64 %22
%24 = load i8, i8* %23
%25 = getelementptr inbounds i8, i8* %12, i64 2
store i8 %24, i8* %20
%26 = urem i64 %11, %3
%27 = icmp ne i64 %26, %7
%28 = icmp eq i64 %11, %8
%29 = or i1 %28, %27
br i1 %29, label %32, label %30
30: ; preds = %9
%31 = getelementptr inbounds i8, i8* %12, i64 3
store i8 32, i8* %25
br label %32
32: ; preds = %30, %9
%33 = phi i8* [ %31, %30 ], [ %25, %9 ]
%34 = add nuw i64 %11, 1
%35 = icmp eq i64 %34, %1
br i1 %35, label %36, label %9
36: ; preds = %32, %4
%37 = phi i8* [ %2, %4 ], [ %33, %32 ]
store i8 0, i8* %37
ret void
}