#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 *, ...);
void print_encode(const char *buffer, size_t size) {
  const char *in = buffer, *end = buffer + size;
  while (in != end) {
    if (*in == '%') {
      printf("%%%%");
    } else if (isprint(*in)) {
      printf("%c", *in);
    } else {
      printf("%%%02X", *in);
    }
    ++in;
  }
}


x86 assembly (clang, -O0):
<print_encode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11d0 <print_encode+0xb0>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    1175 <print_encode+0x55>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <print_encode+0x9f>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     11a5 <print_encode+0x85>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ba <print_encode+0x9a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11bf <print_encode+0x9f>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <print_encode+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_encode>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     11a5 <print_encode+0x75>
mov    %rsi,%r14
mov    %rdi,%r13
lea    0xeb5(%rip),%r15
lea    0xeb3(%rip),%r12
xor    %ebx,%ebx
jmp    1173 <print_encode+0x43>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r14
je     11a5 <print_encode+0x75>
movzbl 0x0(%r13,%rbx,1),%eax
cmp    $0x25,%al
je     1160 <print_encode+0x30>
movsbl %al,%edi
call   1050 <isprint@plt>
movsbl 0x0(%r13,%rbx,1),%esi
test   %rax,%rax
je     1199 <print_encode+0x69>
mov    %esi,%edi
call   1030 <putchar@plt>
jmp    116a <print_encode+0x3a>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    116a <print_encode+0x3a>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%%%%\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [7 x i8] c"%%%02X\00"
define void @print_encode(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
%8 = load i8*, i8** %3
%9 = load i64, i64* %4
%10 = getelementptr inbounds i8, i8* %8, i64 %9
store i8* %10, i8** %6
br label %11
11: ; preds = %38, %2
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = icmp ne i8* %12, %13
br i1 %14, label %15, label %41
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 37
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %38
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = load i8, i8* %23
%25 = call i64 @isprint(i8 signext %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i8*, i8** %5
%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 %37
32: ; preds = %22
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %32, %27
br label %38
38: ; preds = %37, %20
%39 = load i8*, i8** %5
%40 = getelementptr inbounds i8, i8* %39, i32 1
store i8* %40, i8** %5
br label %11
41: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%%%%\00"
@.str.2 = [7 x i8] c"%%%02X\00"
define void @print_encode(i8* %0, i64 %1) {
%3 = getelementptr inbounds i8, i8* %0, i64 %1
%4 = icmp eq i64 %1, 0
br i1 %4, label %23, label %5
5: ; preds = %2, %20
%6 = phi i8* [ %21, %20 ], [ %0, %2 ]
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 37
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %20
11: ; preds = %5
%12 = tail call i64 @isprint(i8 signext %7)
%13 = icmp eq i64 %12, 0
%14 = load i8, i8* %6
%15 = sext i8 %14 to i32
br i1 %13, label %18, label %16
16: ; preds = %11
%17 = tail call i32 @putchar(i32 %15)
br label %20
18: ; preds = %11
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %20
20: ; preds = %16, %18, %9
%21 = getelementptr inbounds i8, i8* %6, i64 1
%22 = icmp eq i8* %21, %3
br i1 %22, label %23, label %5
23: ; preds = %20, %2
ret void
}