#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_printf(char *, char const *, char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char);
void log_printf_hexa(const char *spaces, const char *string) {
  int msg_pos, hexa_pos, ascii_pos;
  char hexa[(16 * 3) + 1], ascii[(16 * 2) + 1];
  msg_pos = 0;
  hexa_pos = 0;
  ascii_pos = 0;
  while (string[msg_pos]) {
    snprintf(hexa + hexa_pos, 4, "%02X ", (unsigned char)(string[msg_pos]));
    hexa_pos += 3;
    snprintf(ascii + ascii_pos, 3, "%c ",
             ((((unsigned char)string[msg_pos]) < 32) ||
              (((unsigned char)string[msg_pos]) > 127))
                 ? '.'
                 : (unsigned char)(string[msg_pos]));
    ascii_pos += 2;
    if (ascii_pos == 32) {
      log_printf("%s%-48s  %s", spaces, hexa, ascii);
      hexa_pos = 0;
      ascii_pos = 0;
    }
    msg_pos++;
  }
  if (ascii_pos > 0)
    log_printf("%s%-48s  %s", spaces, hexa, ascii);
}


x86 assembly (clang, -O0):
<log_printf_hexa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1251 <log_printf_hexa+0x131>
lea    -0x50(%rbp),%rdi
movslq -0x18(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    $0x4,%esi
lea    0xe87(%rip),%rdx
movsbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x18(%rbp)
lea    -0x80(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11c7 <log_printf_hexa+0xa7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x7f,%eax
jle    11d7 <log_printf_hexa+0xb7>
mov    $0x2e,%eax
mov    %eax,-0x8c(%rbp)
jmp    11e9 <log_printf_hexa+0xc9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x88(%rbp),%rdi
mov    -0x8c(%rbp),%eax
mov    $0x3,%esi
lea    0xe04(%rip),%rdx
movsbl %al,%ecx
call   1030 <snprintf@plt>
mov    -0x1c(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jne    1243 <log_printf_hexa+0x123>
mov    -0x8(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    0xdda(%rip),%rdi
call   1040 <log_printf@plt>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1148 <log_printf_hexa+0x28>
cmpl   $0x0,-0x1c(%rbp)
jle    1273 <log_printf_hexa+0x153>
mov    -0x8(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x80(%rbp),%rcx
lea    0xd9c(%rip),%rdi
call   1040 <log_printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_printf_hexa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdi,0x8(%rsp)
mov    (%rsi),%al
test   %al,%al
je     11fb <log_printf_hexa+0xdb>
mov    %rsi,%rbx
add    $0x1,%rbx
xor    %r13d,%r13d
lea    0xeb2(%rip),%r15
mov    $0x2e,%ebp
lea    0xeac(%rip),%r12
xor    %r14d,%r14d
jmp    116f <log_printf_hexa+0x4f>
nop
add    $0x3,%r14d
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
je     11db <log_printf_hexa+0xbb>
movslq %r14d,%rcx
lea    (%rsp,%rcx,1),%rdi
add    $0x40,%rdi
movsbl %al,%ecx
mov    $0x4,%esi
mov    %r15,%rdx
call   1030 <snprintf@plt>
movslq %r13d,%r13
lea    (%rsp,%r13,1),%rdi
add    $0x10,%rdi
movzbl -0x1(%rbx),%eax
cmp    $0x20,%al
cmovl  %ebp,%eax
movsbl %al,%ecx
mov    $0x3,%esi
mov    %r12,%rdx
call   1030 <snprintf@plt>
add    $0x2,%r13d
cmp    $0x20,%r13d
jne    1160 <log_printf_hexa+0x40>
lea    0xe4b(%rip),%rdi
mov    0x8(%rsp),%rsi
lea    0x40(%rsp),%rdx
lea    0x10(%rsp),%rcx
call   1040 <log_printf@plt>
xor    %r14d,%r14d
xor    %r13d,%r13d
jmp    1164 <log_printf_hexa+0x44>
test   %r13d,%r13d
jle    11fb <log_printf_hexa+0xdb>
lea    0xe23(%rip),%rdi
lea    0x40(%rsp),%rdx
lea    0x10(%rsp),%rcx
mov    0x8(%rsp),%rsi
call   1040 <log_printf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%02X \00"
@.str.1 = [4 x i8] c"%c \00"
@.str.2 = [12 x i8] c"%s%-48s %s\00"
define void @log_printf_hexa(i8* %0, i8* nocapture %1) {
%3 = alloca [49 x i8]
%4 = alloca [33 x i8]
%5 = getelementptr inbounds [49 x i8], [49 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 0
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %40, label %9
9: ; preds = %2, %29
%10 = phi i64 [ %32, %29 ], [ 0, %2 ]
%11 = phi i8 [ %34, %29 ], [ %7, %2 ]
%12 = phi i8* [ %33, %29 ], [ %1, %2 ]
%13 = phi i32 [ %31, %29 ], [ 0, %2 ]
%14 = phi i32 [ %30, %29 ], [ 0, %2 ]
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [49 x i8], [49 x i8]* %3, i64 0, i64 %15
%17 = call i32 @snprintf(i8* %16, i32 4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8 signext %11)
%18 = add nsw i32 %14, 3
%19 = sext i32 %13 to i64
%20 = getelementptr inbounds [33 x i8], [33 x i8]* %4, i64 0, i64 %19
%21 = load i8, i8* %12
%22 = icmp slt i8 %21, 32
%23 = select i1 %22, i8 46, i8 %21
%24 = call i32 @snprintf(i8* %20, i32 3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8 signext %23)
%25 = add nsw i32 %13, 2
%26 = icmp eq i32 %25, 32
br i1 %26, label %27, label %29
27: ; preds = %9
%28 = call i32 @log_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %5, i8* %6)
br label %29
29: ; preds = %27, %9
%30 = phi i32 [ 0, %27 ], [ %18, %9 ]
%31 = phi i32 [ 0, %27 ], [ %25, %9 ]
%32 = add nuw i64 %10, 1
%33 = getelementptr inbounds i8, i8* %1, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %9
36: ; preds = %29
%37 = icmp sgt i32 %31, 0
br i1 %37, label %38, label %40
38: ; preds = %36
%39 = call i32 @log_printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %5, i8* %6)
br label %40
40: ; preds = %2, %38, %36
ret void
}