#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 const *, unsigned int);
int /*<<< orphan*/ isprint(char const);
scalar_t__ strlen(char const *);
void print_string(FILE *file, const char *s, int len) {
  const char *end = s + (len < 0 ? (int)strlen(s) : len);
  const char *p;
  for (p = s; p < end; ++p) {
    const char *format;
    switch (*p) {
    case '\a':
      format = "\\a";
      break;
    case '\b':
      format = "\\b";
      break;
    case '\f':
      format = "\\f";
      break;
    case '\n':
      format = "\\n";
      break;
    case '\r':
      format = "\\r";
      break;
    case '\t':
      format = "\\t";
      break;
    case '\v':
      format = "\\v";
      break;
    case '\"':
      format = "\\\"";
      break;
    default:
      format = isprint(*p) ? "%c" : "\\x%02x";
      break;
    }
    fprintf(file, format, ((unsigned)*p) & 0xff);
  }
}


x86 assembly (clang, -O0):
<print_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1166 <print_string+0x36>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
jmp    116c <print_string+0x3c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1292 <print_string+0x162>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
add    $0xfffffff9,%eax
mov    %eax,%ecx
mov    %rcx,-0x48(%rbp)
sub    $0x1b,%eax
ja     1240 <print_string+0x110>
mov    -0x48(%rbp),%rax
lea    0xe49(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea9(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe9c(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe8f(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe82(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe75(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe68(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe5b(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
lea    0xe4e(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1267 <print_string+0x137>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isprint@plt>
mov    %eax,%edx
lea    0xe36(%rip),%rax
lea    0xe2c(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rax
movsbl (%rax),%edx
and    $0xff,%edx
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1185 <print_string+0x55>
add    $0x50,%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    %rsi,%rbx
mov    %rdi,%r14
test   %edx,%edx
js     114e <print_string+0x1e>
test   %edx,%edx
jg     1161 <print_string+0x31>
jmp    121f <print_string+0xef>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rax,%rdx
test   %edx,%edx
jle    121f <print_string+0xef>
movslq %edx,%r15
add    %rbx,%r15
lea    0xf02(%rip),%r12
lea    0xe8b(%rip),%rbp
lea    0xf09(%rip),%r13
jmp    11a4 <print_string+0x74>
movzbl (%rbx),%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl %al,%edx
mov    %r14,%rdi
call   1040 <fprintf@plt>
add    $0x1,%rbx
cmp    %r15,%rbx
jae    121f <print_string+0xef>
movsbl (%rbx),%eax
mov    %eax,%ecx
add    $0xfffffff9,%ecx
cmp    $0x1b,%ecx
ja     11f4 <print_string+0xc4>
movslq 0x0(%rbp,%rcx,4),%rcx
add    %rbp,%rcx
mov    %r12,%rsi
jmp    *%rcx
lea    0xeae(%rip),%rsi
jmp    1190 <print_string+0x60>
lea    0xeb1(%rip),%rsi
jmp    1190 <print_string+0x60>
lea    0xea2(%rip),%rsi
jmp    1190 <print_string+0x60>
lea    0xea2(%rip),%rsi
jmp    1190 <print_string+0x60>
lea    0xe8d(%rip),%rsi
jmp    1190 <print_string+0x60>
lea    0xe8a(%rip),%rsi
jmp    1190 <print_string+0x60>
movsbl %al,%edi
call   1050 <isprint@plt>
lea    0xe88(%rip),%rsi
test   %eax,%eax
je     117e <print_string+0x4e>
lea    0xe76(%rip),%rsi
jmp    117e <print_string+0x4e>
mov    %r13,%rsi
jmp    1190 <print_string+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"\\a\00"
@.str.1 = [3 x i8] c"\\b\00"
@.str.2 = [3 x i8] c"\\f\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\t\00"
@.str.6 = [3 x i8] c"\\v\00"
@.str.7 = [3 x i8] c"\\\22\00"
@.str.8 = [3 x i8] c"%c\00"
@.str.9 = [7 x i8] c"\\x%02x\00"
define void @print_string(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = load i8*, i8** %5
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %3
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
br label %19
17: ; preds = %3
%18 = load i32, i32* %6
br label %19
19: ; preds = %17, %13
%20 = phi i32 [ %16, %13 ], [ %18, %17 ]
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %10, i64 %21
store i8* %22, i8** %7
%23 = load i8*, i8** %5
store i8* %23, i8** %8
br label %24
24: ; preds = %55, %19
%25 = load i8*, i8** %8
%26 = load i8*, i8** %7
%27 = icmp ult i8* %25, %26
br i1 %27, label %28, label %58
28: ; preds = %24
%29 = load i8*, i8** %8
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
switch i32 %31, label %40 [
i32 7, label %32
i32 8, label %33
i32 12, label %34
i32 10, label %35
i32 13, label %36
i32 9, label %37
i32 11, label %38
i32 34, label %39
]
32: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %9
br label %47
33: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %9
br label %47
34: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %9
br label %47
35: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8** %9
br label %47
36: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8** %9
br label %47
37: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8** %9
br label %47
38: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8** %9
br label %47
39: ; preds = %28
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %9
br label %47
40: ; preds = %28
%41 = load i8*, i8** %8
%42 = load i8, i8* %41
%43 = call i32 @isprint(i8 signext %42)
%44 = icmp ne i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0)
store i8* %46, i8** %9
br label %47
47: ; preds = %40, %39, %38, %37, %36, %35, %34, %33, %32
%48 = load i32*, i32** %4
%49 = load i8*, i8** %9
%50 = load i8*, i8** %8
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = and i32 %52, 255
%54 = call i32 @fprintf(i32* %48, i8* %49, i32 %53)
br label %55
55: ; preds = %47
%56 = load i8*, i8** %8
%57 = getelementptr inbounds i8, i8* %56, i32 1
store i8* %57, i8** %8
br label %24
58: ; preds = %24
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\a\00"
@.str.1 = [3 x i8] c"\\b\00"
@.str.2 = [3 x i8] c"\\f\00"
@.str.3 = [3 x i8] c"\\n\00"
@.str.4 = [3 x i8] c"\\r\00"
@.str.5 = [3 x i8] c"\\t\00"
@.str.6 = [3 x i8] c"\\v\00"
@.str.7 = [3 x i8] c"\\\22\00"
@.str.8 = [3 x i8] c"%c\00"
@.str.9 = [7 x i8] c"\\x%02x\00"
define void @print_string(i32* nocapture %0, i8* %1, i32 %2) {
%4 = icmp slt i32 %2, 0
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%7 = trunc i64 %6 to i32
br label %8
8: ; preds = %3, %5
%9 = phi i32 [ %7, %5 ], [ %2, %3 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %1, i64 %10
%12 = icmp sgt i32 %9, 0
br i1 %12, label %13, label %36
13: ; preds = %8, %29
%14 = phi i8* [ %34, %29 ], [ %1, %8 ]
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
switch i32 %16, label %24 [
i32 7, label %29
i32 8, label %17
i32 12, label %18
i32 10, label %19
i32 13, label %20
i32 9, label %21
i32 11, label %22
i32 34, label %23
]
17: ; preds = %13
br label %29
18: ; preds = %13
br label %29
19: ; preds = %13
br label %29
20: ; preds = %13
br label %29
21: ; preds = %13
br label %29
22: ; preds = %13
br label %29
23: ; preds = %13
br label %29
24: ; preds = %13
%25 = tail call i32 @isprint(i8 signext %15)
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0)
%28 = load i8, i8* %14
br label %29
29: ; preds = %13, %24, %23, %22, %21, %20, %19, %18, %17
%30 = phi i8 [ %28, %24 ], [ %15, %23 ], [ %15, %22 ], [ %15, %21 ], [ %15, %20 ], [ %15, %19 ], [ %15, %18 ], [ %15, %17 ], [ %15, %13 ]
%31 = phi i8* [ %27, %24 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), %23 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), %22 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), %21 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), %20 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %19 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), %18 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %17 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %13 ]
%32 = zext i8 %30 to i32
%33 = tail call i32 @fprintf(i32* %0, i8* %31, i32 %32)
%34 = getelementptr inbounds i8, i8* %14, i64 1
%35 = icmp ult i8* %34, %11
br i1 %35, label %13, label %36
36: ; preds = %29, %8
ret void
}