#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(char const);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char const *);
void grf_logging_print_hex(const char *msg, const char *hexstr, size_t hexlen) {
  int len;
  int i;
  if (!msg) {
    printf("<0x00>\n");
    return;
  }
  len = strlen(msg);
  for (i = 0; i < len; i++) {
    if (isprint(msg[i]))
      printf("%c", msg[i]);
    else
      printf("<0x%02x>", msg[i]);
  }
  printf(" (");
  for (i = 0; i < hexlen; i++) {
    if (i == 0)
      printf("%02x", hexstr[i]);
    else
      printf(" %02x", hexstr[i]);
  }
  printf(")\n");
}


x86 assembly (clang, -O0):
<grf_logging_print_hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1162 <grf_logging_print_hex+0x32>
lea    0xeaa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126f <grf_logging_print_hex+0x13f>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11e8 <grf_logging_print_hex+0xb8>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11bb <grf_logging_print_hex+0x8b>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d5 <grf_logging_print_hex+0xa5>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11da <grf_logging_print_hex+0xaa>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1175 <grf_logging_print_hex+0x45>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1261 <grf_logging_print_hex+0x131>
cmpl   $0x0,-0x20(%rbp)
jne    1234 <grf_logging_print_hex+0x104>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124e <grf_logging_print_hex+0x11e>
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1253 <grf_logging_print_hex+0x123>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11fd <grf_logging_print_hex+0xcd>
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grf_logging_print_hex>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     121a <grf_logging_print_hex+0xca>
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <strlen@plt>
test   %eax,%eax
jle    11be <grf_logging_print_hex+0x6e>
mov    %eax,%r13d
lea    0xe80(%rip),%r12
xor    %ebp,%ebp
jmp    11a3 <grf_logging_print_hex+0x53>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11be <grf_logging_print_hex+0x6e>
movsbl (%rbx,%rbp,1),%edi
call   1070 <isprint@plt>
movsbl (%rbx,%rbp,1),%esi
test   %rax,%rax
je     1190 <grf_logging_print_hex+0x40>
mov    %esi,%edi
call   1030 <putchar@plt>
jmp    119a <grf_logging_print_hex+0x4a>
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe46(%rip),%r12
test   %r15,%r15
je     1221 <grf_logging_print_hex+0xd1>
movsbl (%r14),%esi
lea    0xe2a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x1,%r15
je     1221 <grf_logging_print_hex+0xd1>
mov    $0x1,%ebp
lea    0xe10(%rip),%rbx
nopl   0x0(%rax)
movsbl (%r14,%rbp,1),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1200 <grf_logging_print_hex+0xb0>
jmp    1221 <grf_logging_print_hex+0xd1>
lea    0xdf1(%rip),%r12
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <puts@plt>

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

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