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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, unsigned int);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
scalar_t__ isprint(unsigned int);
void print_string(const void *data, size_t len, FILE *out) {
  uint8_t *str = (uint8_t *)data;
  fputc('"', out);
  while (len-- != 0) {
    unsigned c = *(str++);
    if (isprint(c)) {
      if (c == '"')
        fputs("\\\"", out);
      else
        fputc(c, out);
    } else {
      fprintf(out, "\\x%02x", c);
    }
  }
  fputc('"', out);
}


x86 assembly (clang, -O0):
<print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
mov    $0x22,%edi
call   1040 <fputc@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     11f4 <print_string+0xb4>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1060 <isprint@plt>
cmp    $0x0,%rax
je     11dc <print_string+0x9c>
cmpl   $0x22,-0x24(%rbp)
jne    11c8 <print_string+0x88>
mov    -0x18(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1030 <fputs@plt>
jmp    11d7 <print_string+0x97>
mov    -0x24(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    11ef <print_string+0xaf>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xe19(%rip),%rsi
call   1050 <fprintf@plt>
jmp    116a <print_string+0x2a>
mov    -0x18(%rbp),%rsi
mov    $0x22,%edi
call   1040 <fputc@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
mov    $0x22,%edi
mov    %rdx,%rsi
call   1030 <fputc@plt>
test   %rbx,%rbx
je     11de <print_string+0x9e>
xor    %r13d,%r13d
lea    0xe93(%rip),%r12
jmp    1196 <print_string+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
add    $0x1,%r13
cmp    %r13,%rbx
je     11de <print_string+0x9e>
mov    (%r15,%r13,4),%ebp
mov    %ebp,%edi
call   1050 <isprint@plt>
test   %rax,%rax
je     1180 <print_string+0x40>
cmp    $0x22,%ebp
jne    11d0 <print_string+0x90>
mov    $0x2,%esi
mov    $0x1,%edx
lea    0xe44(%rip),%rdi
mov    %r14,%rcx
call   1060 <fwrite@plt>
jmp    118d <print_string+0x4d>
cs nopw 0x0(%rax,%rax,1)
movsbl %bpl,%edi
mov    %r14,%rsi
call   1030 <fputc@plt>
jmp    118d <print_string+0x4d>
mov    $0x22,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fputc@plt>

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

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