#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ isprint(char);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
void printstr(FILE *stream, const char *str) {
  char c;
  while ((c = *str++) != '\0') {
    putc(c, stream);
    if (isprint(c) && c != '"' && c != '\\')
      putc(c, stream);
    else
      fprintf(stream, "\\x%x", (int)c);
  }
}


x86 assembly (clang, -O0):
<printstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
movsbl %al,%eax
cmp    $0x0,%eax
je     11c9 <printstr+0x99>
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
movsbl -0x11(%rbp),%edi
call   1050 <isprint@plt>
cmp    $0x0,%rax
je     11b0 <printstr+0x80>
movsbl -0x11(%rbp),%eax
cmp    $0x22,%eax
je     11b0 <printstr+0x80>
movsbl -0x11(%rbp),%eax
cmp    $0x5c,%eax
je     11b0 <printstr+0x80>
mov    -0x11(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <putc@plt>
jmp    11c4 <printstr+0x94>
mov    -0x8(%rbp),%rdi
movsbl -0x11(%rbp),%edx
lea    0xe41(%rip),%rsi
call   1040 <fprintf@plt>
jmp    1140 <printstr+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printstr>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    (%rsi),%bl
test   %bl,%bl
je     11ad <printstr+0x7d>
mov    %rsi,%rbp
mov    %rdi,%r14
add    $0x1,%rbp
lea    0xeb1(%rip),%r15
jmp    117a <printstr+0x4a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <fprintf@plt>
movzbl 0x0(%rbp),%ebx
add    $0x1,%rbp
test   %bl,%bl
je     11ad <printstr+0x7d>
movsbl %bl,%r12d
mov    %r12d,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
mov    %r12d,%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     1160 <printstr+0x30>
cmp    $0x22,%bl
je     1160 <printstr+0x30>
cmp    $0x5c,%bl
je     1160 <printstr+0x30>
mov    %r12d,%edi
mov    %r14,%rsi
call   1030 <putc@plt>
jmp    116e <printstr+0x3e>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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