#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 */
int /*<<< orphan*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void print_str(char *buf, char *str) {
  strcat(buf, " \"");
  for (int i = 0; i < strlen(str); i++) {
    if (str[i] >= 32) {
      int s = strlen(buf);
      buf[s++] = str[i];
      buf[s] = '\0';
    } else {
      char xbuf[16];
      switch (str[i]) {
      case 9:
        strcpy(xbuf, "\\t");
        break;
      case 10:
        strcpy(xbuf, "\\n");
        break;
      case 13:
        strcpy(xbuf, "\\r");
        break;
      default:
        sprintf(xbuf, "\\x%02x", str[i]);
      }
      strcat(buf, xbuf);
    }
  }
  strcat(buf, "\"");
}


x86 assembly (clang, -O0):
<print_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    128f <print_str+0x14f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jl     11d5 <print_str+0x95>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    127c <print_str+0x13c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x38(%rbp)
sub    $0x9,%eax
je     1214 <print_str+0xd4>
jmp    11f2 <print_str+0xb2>
mov    -0x38(%rbp),%eax
sub    $0xa,%eax
je     1229 <print_str+0xe9>
jmp    1203 <print_str+0xc3>
mov    -0x38(%rbp),%eax
sub    $0xd,%eax
je     123e <print_str+0xfe>
jmp    1253 <print_str+0x113>
lea    -0x30(%rbp),%rdi
lea    0xde4(%rip),%rsi
call   1030 <strcpy@plt>
jmp    126f <print_str+0x12f>
lea    -0x30(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1030 <strcpy@plt>
jmp    126f <print_str+0x12f>
lea    -0x30(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   1030 <strcpy@plt>
jmp    126f <print_str+0x12f>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
lea    0xda6(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <strcat@plt>
jmp    1281 <print_str+0x141>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1167 <print_str+0x27>
mov    -0x8(%rbp),%rdi
lea    0xd67(%rip),%rsi
call   1050 <strcat@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_str>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xea5(%rip),%rsi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1211 <print_str+0xd1>
xor    %ebp,%ebp
mov    %rsp,%r12
lea    0xe8a(%rip),%r13
lea    0xe89(%rip),%r15
jmp    11bb <print_str+0x7b>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
call   1040 <strlen@plt>
movzbl (%rbx,%rbp,1),%ecx
cltq
mov    %cl,(%r14,%rax,1)
movb   $0x0,0x1(%r14,%rax,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    1211 <print_str+0xd1>
movsbl (%rbx,%rbp,1),%edx
cmp    $0x20,%edx
jge    1190 <print_str+0x50>
mov    %r12,%rdi
cmp    $0xd,%edx
je     11ee <print_str+0xae>
cmp    $0xa,%edx
je     11e4 <print_str+0xa4>
cmp    $0x9,%edx
jne    11fc <print_str+0xbc>
lea    0xe26(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1204 <print_str+0xc4>
mov    %r13,%rsi
call   1030 <strcpy@plt>
jmp    1204 <print_str+0xc4>
lea    0xe14(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1204 <print_str+0xc4>
mov    %r15,%rsi
call   1060 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
jmp    11a8 <print_str+0x68>
lea    0xde9(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c" \22\00"
@.str.1 = [3 x i8] c"\\t\00"
@.str.2 = [3 x i8] c"\\n\00"
@.str.3 = [3 x i8] c"\\r\00"
@.str.4 = [7 x i8] c"\\x%02x\00"
@.str.5 = [2 x i8] c"\22\00"
define void @print_str(i8* %0, i8* %1) {
%3 = alloca [16 x i8]
%4 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @strlen(i8* %1)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
br label %11
9: ; preds = %36, %2
%10 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
11: ; preds = %7, %36
%12 = phi i64 [ 0, %7 ], [ %37, %36 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = icmp sgt i8 %14, 31
br i1 %15, label %16, label %24
16: ; preds = %11
%17 = call i32 @strlen(i8* %0)
%18 = load i8, i8* %13
%19 = add nsw i32 %17, 1
%20 = sext i32 %17 to i64
%21 = getelementptr inbounds i8, i8* %0, i64 %20
store i8 %18, i8* %21
%22 = sext i32 %19 to i64
%23 = getelementptr inbounds i8, i8* %0, i64 %22
store i8 0, i8* %23
br label %36
24: ; preds = %11
%25 = sext i8 %14 to i32
switch i32 %25, label %32 [
i32 9, label %26
i32 10, label %28
i32 13, label %30
]
26: ; preds = %24
%27 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %34
28: ; preds = %24
%29 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %34
30: ; preds = %24
%31 = call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %34
32: ; preds = %24
%33 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8 signext %14)
br label %34
34: ; preds = %32, %30, %28, %26
%35 = call i32 @strcat(i8* %0, i8* %8)
br label %36
36: ; preds = %16, %34
%37 = add nuw nsw i64 %12, 1
%38 = call i32 @strlen(i8* %1)
%39 = sext i32 %38 to i64
%40 = icmp slt i64 %37, %39
br i1 %40, label %11, label %9
}