#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*/ log_line(int const, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned char const);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void log_xxd_always(const int priority, const char *msg,
                    const unsigned char *buffer, const int len) {
  char DebugBuffer[len * 3 + strlen(msg) + 1];
  int i;
  char *c;
  strcpy(DebugBuffer, msg);
  c = DebugBuffer + strlen(DebugBuffer);
  for (i = 0; (i < len); ++i) {
    snprintf(c, 4, "%02X ", buffer[i]);
    c += 3;
  }
  log_line(priority, DebugBuffer);
}


x86 assembly (clang, -O0):
<log_xxd_always>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%ecx
mov    %ecx,%eax
lea    (%rax,%rax,2),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edx
mov    -0x4c(%rbp),%eax
mov    %eax,%ecx
mov    %edx,%eax
lea    0x1(%rax,%rcx,1),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    120a <log_xxd_always+0xca>
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    $0x4,%esi
lea    0xe19(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1060 <snprintf@plt>
mov    -0x40(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x40(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11c3 <log_xxd_always+0x83>
mov    -0x48(%rbp),%rsi
mov    -0x4(%rbp),%edi
call   1040 <log_line@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_xxd_always>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%r14
mov    %edi,-0x2c(%rbp)
lea    (%r12,%r12,2),%ebx
mov    %rsi,%rdi
call   1050 <strlen@plt>
add    %ebx,%eax
add    $0x1,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,-0x38(%rbp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %r12d,%r12d
jle    11d3 <log_xxd_always+0x93>
movslq %eax,%rbx
add    -0x38(%rbp),%rbx
mov    %r12d,%r14d
xor    %r15d,%r15d
lea    0xe51(%rip),%r12
nop
movzbl 0x0(%r13,%r15,1),%ecx
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r12,%rdx
call   1060 <snprintf@plt>
add    $0x3,%rbx
add    $0x1,%r15
cmp    %r15,%r14
jne    11b0 <log_xxd_always+0x70>
mov    -0x2c(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1040 <log_line@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
define void @log_xxd_always(i32 %0, i8* %1, i8* nocapture %2, i32 %3) {
%5 = mul nsw i32 %3, 3
%6 = tail call i32 @strlen(i8* %1)
%7 = add i32 %5, 1
%8 = add i32 %7, %6
%9 = zext i32 %8 to i64
%10 = alloca i8, i64 %9
%11 = call i32 @strcpy(i8* %10, i8* %1)
%12 = call i32 @strlen(i8* %10)
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %27
14: ; preds = %4
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %10, i64 %15
%17 = zext i32 %3 to i64
br label %18
18: ; preds = %14, %18
%19 = phi i64 [ 0, %14 ], [ %25, %18 ]
%20 = phi i8* [ %16, %14 ], [ %24, %18 ]
%21 = getelementptr inbounds i8, i8* %2, i64 %19
%22 = load i8, i8* %21
%23 = call i32 @snprintf(i8* %20, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 zeroext %22)
%24 = getelementptr inbounds i8, i8* %20, i64 3
%25 = add nuw nsw i64 %19, 1
%26 = icmp eq i64 %25, %17
br i1 %26, label %27, label %18
27: ; preds = %18, %4
%28 = call i32 @log_line(i32 %0, i8* %10)
ret void
}