#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);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, char, char,
                          char, char);
void print_mem(unsigned long address, unsigned long value) {
  char *c = (char *)&value;
  printf("%lx: %lx [%c%c%c%c]\n", address, value,
         (isprint(c[0]) ? (c[0]) : '.'), (isprint(c[1]) ? (c[1]) : '.'),
         (isprint(c[2]) ? (c[2]) : '.'), (isprint(c[3]) ? (c[3]) : '.'));
}


x86 assembly (clang, -O0):
<print_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     116d <print_mem+0x4d>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    117a <print_mem+0x5a>
mov    $0x2e,%eax
mov    %eax,-0x2c(%rbp)
jmp    117a <print_mem+0x5a>
mov    -0x2c(%rbp),%eax
mov    %al,-0x2d(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11a7 <print_mem+0x87>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
mov    %eax,-0x34(%rbp)
jmp    11b4 <print_mem+0x94>
mov    $0x2e,%eax
mov    %eax,-0x34(%rbp)
jmp    11b4 <print_mem+0x94>
mov    -0x34(%rbp),%eax
mov    %al,-0x35(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11e1 <print_mem+0xc1>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    11ee <print_mem+0xce>
mov    $0x2e,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ee <print_mem+0xce>
mov    -0x3c(%rbp),%eax
mov    %al,-0x3d(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x3(%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     121b <print_mem+0xfb>
mov    -0x18(%rbp),%rax
movsbl 0x3(%rax),%eax
mov    %eax,-0x44(%rbp)
jmp    1228 <print_mem+0x108>
mov    $0x2e,%eax
mov    %eax,-0x44(%rbp)
jmp    1228 <print_mem+0x108>
mov    -0x3d(%rbp),%r9b
mov    -0x35(%rbp),%r8b
mov    -0x2d(%rbp),%cl
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rsi
mov    -0x44(%rbp),%eax
lea    0xdbb(%rip),%rdi
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl %r9b,%r9d
movsbl %al,%eax
mov    %eax,(%rsp)
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %rdi,0x10(%rsp)
mov    %rsi,%r12
shr    $0x8,%r12
mov    %rsi,%r13
shr    $0x10,%r13
mov    %rsi,%rbx
shr    $0x18,%rbx
movsbl %r15b,%edi
call   1040 <isprint@plt>
test   %rax,%rax
mov    $0x2e,%r14d
mov    %r15d,%ebp
cmove  %r14d,%ebp
movsbl %r12b,%edi
call   1040 <isprint@plt>
test   %rax,%rax
cmove  %r14d,%r12d
movsbl %r13b,%edi
call   1040 <isprint@plt>
test   %rax,%rax
cmove  %r14d,%r13d
movsbl %bl,%edi
call   1040 <isprint@plt>
test   %rax,%rax
cmove  %r14d,%ebx
movsbl %bl,%eax
mov    %eax,(%rsp)
movsbl %bpl,%ecx
movsbl %r12b,%r8d
movsbl %r13b,%r9d
lea    0xe54(%rip),%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
call   1030 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"%lx: %lx [%c%c%c%c]\0A\00"
define void @print_mem(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i8*
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = bitcast i64* %4 to i8*
store i8* %6, i8** %5
%7 = load i64, i64* %3
%8 = load i64, i64* %4
%9 = load i8*, i8** %5
%10 = getelementptr inbounds i8, i8* %9, i64 0
%11 = load i8, i8* %10
%12 = call i64 @isprint(i8 signext %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
br label %20
19: ; preds = %2
br label %20
20: ; preds = %19, %14
%21 = phi i32 [ %18, %14 ], [ 46, %19 ]
%22 = trunc i32 %21 to i8
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = call i64 @isprint(i8 signext %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8*, i8** %5
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
br label %34
33: ; preds = %20
br label %34
34: ; preds = %33, %28
%35 = phi i32 [ %32, %28 ], [ 46, %33 ]
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %5
%38 = getelementptr inbounds i8, i8* %37, i64 2
%39 = load i8, i8* %38
%40 = call i64 @isprint(i8 signext %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %34
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 2
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
br label %48
47: ; preds = %34
br label %48
48: ; preds = %47, %42
%49 = phi i32 [ %46, %42 ], [ 46, %47 ]
%50 = trunc i32 %49 to i8
%51 = load i8*, i8** %5
%52 = getelementptr inbounds i8, i8* %51, i64 3
%53 = load i8, i8* %52
%54 = call i64 @isprint(i8 signext %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %48
%57 = load i8*, i8** %5
%58 = getelementptr inbounds i8, i8* %57, i64 3
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
br label %62
61: ; preds = %48
br label %62
62: ; preds = %61, %56
%63 = phi i32 [ %60, %56 ], [ 46, %61 ]
%64 = trunc i32 %63 to i8
%65 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %7, i64 %8, i8 signext %22, i8 signext %36, i8 signext %50, i8 signext %64)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"%lx: %lx [%c%c%c%c]\0A\00"
define void @print_mem(i64 %0, i64 %1) {
%3 = trunc i64 %1 to i8
%4 = lshr i64 %1, 8
%5 = trunc i64 %4 to i8
%6 = lshr i64 %1, 16
%7 = trunc i64 %6 to i8
%8 = lshr i64 %1, 24
%9 = trunc i64 %8 to i8
%10 = tail call i64 @isprint(i8 signext %3)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8 46, i8 %3
%13 = tail call i64 @isprint(i8 signext %5)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i8 46, i8 %5
%16 = tail call i64 @isprint(i8 signext %7)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i8 46, i8 %7
%19 = tail call i64 @isprint(i8 signext %9)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8 46, i8 %9
%22 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %1, i8 signext %12, i8 signext %15, i8 signext %18, i8 signext %21)
ret void
}