#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(const char *msg) {
  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("\n");
}


x86 assembly (clang, -O0):
<grf_logging_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115a <grf_logging_print+0x2a>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ee <grf_logging_print+0xbe>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e0 <grf_logging_print+0xb0>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11b3 <grf_logging_print+0x83>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cd <grf_logging_print+0x9d>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d2 <grf_logging_print+0xa2>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116d <grf_logging_print+0x3d>
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grf_logging_print>:
test   %rdi,%rdi
je     11c5 <grf_logging_print+0x75>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r12
call   1050 <strlen@plt>
test   %eax,%eax
jle    11b0 <grf_logging_print+0x60>
mov    %eax,%r15d
lea    0xe8d(%rip),%r14
xor    %ebx,%ebx
jmp    1193 <grf_logging_print+0x43>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
je     11b0 <grf_logging_print+0x60>
movsbl (%r12,%rbx,1),%edi
call   1070 <isprint@plt>
movsbl (%r12,%rbx,1),%esi
test   %rax,%rax
je     1180 <grf_logging_print+0x30>
mov    %esi,%edi
call   1030 <putchar@plt>
jmp    118a <grf_logging_print+0x3a>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
lea    0xe3d(%rip),%rdi
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 = [2 x i8] c"\0A\00"
define void @grf_logging_print(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %46
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %3
store i32 0, i32* %4
br label %12
12: ; preds = %41, %9
%13 = load i32, i32* %4
%14 = load i32, i32* %3
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %44
16: ; preds = %12
%17 = load i8*, i8** %2
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = call i64 @isprint(i8 signext %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = load i8*, i8** %2
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %40
32: ; preds = %16
%33 = load i8*, i8** %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %38)
br label %40
40: ; preds = %32, %24
br label %41
41: ; preds = %40
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %12
44: ; preds = %12
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %46
46: ; preds = %44, %7
ret void
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"<0x%02x>\00"
@str = [7 x i8] c"<0x00>\00"
define void @grf_logging_print(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %27
5: ; preds = %1
%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 @putchar(i32 10)
br label %27
27: ; preds = %25, %3
ret void
}