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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void print_str(FILE *f, const char *str) {
  const char *s;
  int c;
  s = str;
  while (*s != '\0') {
    if (*s <= ' ' || *s > '~')
      goto use_quote;
    s++;
  }
  fprintf(f, "%s", str);
  return;
use_quote:
  s = str;
  fputc('"', f);
  while (*s != '\0') {
    c = *(uint8_t *)s;
    if (c < ' ' || c == 127) {
      fprintf(f, "\\x%02x", c);
    } else if (c == '\\' || c == '\"') {
      fprintf(f, "\\%c", c);
    } else {
      fputc(c, f);
    }
    s++;
  }
  fputc('"', f);
}


x86 assembly (clang, -O0):
<print_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     117e <print_str+0x5e>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jle    1168 <print_str+0x48>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jle    116d <print_str+0x4d>
jmp    1199 <print_str+0x79>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1138 <print_str+0x18>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1257 <print_str+0x137>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1030 <fputc@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1249 <print_str+0x129>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jl     11dc <print_str+0xbc>
cmpl   $0x7f,-0x1c(%rbp)
jne    11f6 <print_str+0xd6>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1238 <print_str+0x118>
cmpl   $0x5c,-0x1c(%rbp)
je     120a <print_str+0xea>
cmpl   $0x22,-0x1c(%rbp)
jne    1224 <print_str+0x104>
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%edx
lea    0xdf2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1233 <print_str+0x113>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1030 <fputc@plt>
jmp    1238 <print_str+0x118>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11af <print_str+0x8f>
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1030 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    (%rsi),%al
test   %al,%al
je     1161 <print_str+0x31>
lea    0x1(%rbx),%rcx
nopl   0x0(%rax,%rax,1)
add    $0x81,%al
cmp    $0xa2,%al
jb     1177 <print_str+0x47>
movzbl (%rcx),%eax
add    $0x1,%rcx
test   %al,%al
jne    1150 <print_str+0x20>
mov    %rbx,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <fputs@plt>
mov    $0x22,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
cmpb   $0x0,(%rbx)
je     11e2 <print_str+0xb2>
add    $0x1,%rbx
lea    0xe6c(%rip),%r15
lea    0xe6c(%rip),%r12
jmp    11b6 <print_str+0x86>
nopl   (%rax)
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
je     11e2 <print_str+0xb2>
mov    -0x1(%rbx),%edx
cmp    $0x20,%edx
jl     11a0 <print_str+0x70>
cmp    $0x7f,%edx
je     11a0 <print_str+0x70>
cmp    $0x5c,%edx
je     11cd <print_str+0x9d>
cmp    $0x22,%edx
jne    11d5 <print_str+0xa5>
mov    %r14,%rdi
mov    %r12,%rsi
jmp    11a6 <print_str+0x76>
movsbl %dl,%edi
mov    %r14,%rsi
call   1040 <fputc@plt>
jmp    11ad <print_str+0x7d>
mov    $0x22,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"\\x%02x\00"
@.str.2 = [4 x i8] c"\\%c\00"
define void @print_str(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
store i8* %7, i8** %5
br label %8
8: ; preds = %24, %2
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp sle i32 %16, 32
br i1 %17, label %23, label %18
18: ; preds = %13
%19 = load i8*, i8** %5
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp sgt i32 %21, 126
br i1 %22, label %23, label %24
23: ; preds = %18, %13
br label %31
24: ; preds = %18
%25 = load i8*, i8** %5
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %5
br label %8
27: ; preds = %8
%28 = load i32*, i32** %3
%29 = load i8*, i8** %4
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %75
31: ; preds = %23
%32 = load i8*, i8** %4
store i8* %32, i8** %5
%33 = load i32*, i32** %3
%34 = call i32 @fputc(i8 signext 34, i32* %33)
br label %35
35: ; preds = %69, %31
%36 = load i8*, i8** %5
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %72
40: ; preds = %35
%41 = load i8*, i8** %5
%42 = bitcast i8* %41 to i32*
%43 = load i32, i32* %42
store i32 %43, i32* %6
%44 = load i32, i32* %6
%45 = icmp slt i32 %44, 32
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = load i32, i32* %6
%48 = icmp eq i32 %47, 127
br i1 %48, label %49, label %53
49: ; preds = %46, %40
%50 = load i32*, i32** %3
%51 = load i32, i32* %6
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %50, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %51)
br label %69
53: ; preds = %46
%54 = load i32, i32* %6
%55 = icmp eq i32 %54, 92
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load i32, i32* %6
%58 = icmp eq i32 %57, 34
br i1 %58, label %59, label %63
59: ; preds = %56, %53
%60 = load i32*, i32** %3
%61 = load i32, i32* %6
%62 = call i32 (i32*, i8*, ...) @fprintf(i32* %60, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %61)
br label %68
63: ; preds = %56
%64 = load i32, i32* %6
%65 = trunc i32 %64 to i8
%66 = load i32*, i32** %3
%67 = call i32 @fputc(i8 signext %65, i32* %66)
br label %68
68: ; preds = %63, %59
br label %69
69: ; preds = %68, %49
%70 = load i8*, i8** %5
%71 = getelementptr inbounds i8, i8* %70, i32 1
store i8* %71, i8** %5
br label %35
72: ; preds = %35
%73 = load i32*, i32** %3
%74 = call i32 @fputc(i8 signext 34, i32* %73)
br label %75
75: ; preds = %72, %27
ret void
}

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