#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(unsigned char);
int /*<<< orphan*/ printf(char *, unsigned char);
void print_padded(unsigned char *data, size_t data_len) {
  int i = 0;
  for (i = 0; i < data_len; ++i) {
    if (isprint(data[i])) {
      printf("%c", data[i]);
    } else {
      printf("\\x%02x", data[i]);
    }
  }
}


x86 assembly (clang, -O0):
<print_padded>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11af <print_padded+0x8f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1184 <print_padded+0x64>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe8a(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    119c <print_padded+0x7c>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xe70(%rip),%rdi
movzbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
jmp    11a1 <print_padded+0x81>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113e <print_padded+0x1e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_padded>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     1177 <print_padded+0x57>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xec6(%rip),%r12
lea    0xebc(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%r15,%rbx,1),%edi
call   1040 <isprint@plt>
test   %rax,%rax
movzbl (%r15,%rbx,1),%esi
mov    %r13,%rdi
cmove  %r12,%rdi
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <print_padded+0x30>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
define void @print_padded(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %5
store i32 0, i32* %5
br label %6
6: ; preds = %34, %2
%7 = load i32, i32* %5
%8 = sext i32 %7 to i64
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %37
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = call i64 @isprint(i8 zeroext %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %11
%20 = load i8*, i8** %3
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 zeroext %24)
br label %33
26: ; preds = %11
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %31)
br label %33
33: ; preds = %26, %19
br label %34
34: ; preds = %33
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %6
37: ; preds = %6
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
define void @print_padded(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %15, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %13, %4 ], [ 0, %2 ]
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i64 @isprint(i8 zeroext %7)
%9 = icmp eq i64 %8, 0
%10 = load i8, i8* %6
%11 = select i1 %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%12 = tail call i32 @printf(i8* %11, i8 zeroext %10)
%13 = add nuw i64 %5, 1
%14 = icmp eq i64 %13, %1
br i1 %14, label %15, label %4
15: ; preds = %4, %2
ret void
}