#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*/ printf(char *, ...);
void print_mem(char *leader, void *mem, int len, char *format, char sep,
               char *trailer) {
  if (leader != NULL) {
    printf(leader);
  }
  unsigned char *p = (unsigned char *)mem;
  for (int i = 0; i < len; i++) {
    if (i != 0)
      printf("%c", sep);
    printf(format, p[i]);
  }
  if (trailer != NULL) {
    printf(trailer);
  }
}


x86 assembly (clang, -O0):
<print_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %r8b,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %al,-0x21(%rbp)
mov    %r9,-0x30(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1147 <print_mem+0x37>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11a3 <print_mem+0x93>
cmpl   $0x0,-0x3c(%rbp)
je     117e <print_mem+0x6e>
movsbl -0x21(%rbp),%esi
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movzbl (%rax,%rcx,1),%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1156 <print_mem+0x46>
cmpq   $0x0,-0x30(%rbp)
je     11b9 <print_mem+0xa9>
mov    -0x30(%rbp),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,(%rsp)
mov    %r8d,%ebx
mov    %rcx,%r15
mov    %edx,%r13d
mov    %rsi,%r12
test   %rdi,%rdi
je     1147 <print_mem+0x27>
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13d,%r13d
jle    1190 <print_mem+0x70>
movzbl (%r12),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%r13d
je     1190 <print_mem+0x70>
movsbl %bl,%r14d
mov    %r13d,%ebx
mov    $0x1,%ebp
nopl   (%rax)
mov    %r14d,%edi
call   1030 <putchar@plt>
movzbl (%r12,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    1170 <print_mem+0x50>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     11ae <print_mem+0x8e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define void @print_mem(i8* %0, i8* nocapture %1, i32 %2, i8* nocapture %3, i8 signext %4, i8* %5) {
%7 = icmp eq i8* %0, null
br i1 %7, label %10, label %8
8: ; preds = %6
%9 = tail call i32 (i8*, ...) @printf(i8* %0)
br label %10
10: ; preds = %8, %6
%11 = icmp sgt i32 %2, 0
br i1 %11, label %12, label %19
12: ; preds = %10
%13 = sext i8 %4 to i32
%14 = zext i32 %2 to i64
%15 = load i8, i8* %1
%16 = zext i8 %15 to i32
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %3, i32 %16)
%18 = icmp eq i32 %2, 1
br i1 %18, label %19, label %21
19: ; preds = %21, %12, %10
%20 = icmp eq i8* %5, null
br i1 %20, label %32, label %30
21: ; preds = %12, %21
%22 = phi i64 [ %28, %21 ], [ 1, %12 ]
%23 = tail call i32 @putchar(i32 %13)
%24 = getelementptr inbounds i8, i8* %1, i64 %22
%25 = load i8, i8* %24
%26 = zext i8 %25 to i32
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %3, i32 %26)
%28 = add nuw nsw i64 %22, 1
%29 = icmp eq i64 %28, %14
br i1 %29, label %19, label %21
30: ; preds = %19
%31 = tail call i32 (i8*, ...) @printf(i8* %5)
br label %32
32: ; preds = %30, %19
ret void
}