#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 u_char;

/* Variables and functions */
int /*<<< orphan*/ isascii(int);
int /*<<< orphan*/ isprint(int);
int /*<<< orphan*/ putchar(char);
int toascii(int);
int printfn(u_char *s, u_char *ep) {
  u_char c;
  putchar('"');
  while ((c = *s++) != 0) {
    if (s > ep) {
      putchar('"');
      return (1);
    }
    if (!isascii(c)) {
      c = toascii(c);
      putchar('M');
      putchar('-');
    }
    if (!isprint(c)) {
      c ^= 0x40;
      putchar('^');
    }
    putchar(c);
  }
  putchar('"');
  return (0);
}


x86 assembly (clang, -O0):
<printfn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11ff <printfn+0xbf>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    119b <printfn+0x5b>
mov    $0x22,%edi
call   1030 <putchar@plt>
movl   $0x1,-0x4(%rbp)
jmp    1210 <printfn+0xd0>
mov    -0x1c(%rbp),%edi
call   1060 <isascii@plt>
cmp    $0x0,%eax
jne    11cb <printfn+0x8b>
mov    -0x1c(%rbp),%edi
call   1050 <toascii@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x4d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%edi
call   1040 <isprint@plt>
cmp    $0x0,%eax
jne    11ef <printfn+0xaf>
mov    -0x1c(%rbp),%eax
xor    $0x40,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x5e,%edi
call   1030 <putchar@plt>
mov    -0x1c(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
jmp    115a <printfn+0x1a>
mov    $0x22,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printfn>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%rbp
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    0x0(%rbp),%ebx
xor    %r14d,%r14d
test   %ebx,%ebx
je     11a7 <printfn+0x87>
add    $0x4,%rbp
jmp    1163 <printfn+0x43>
nopw   0x0(%rax,%rax,1)
movsbl %bl,%edi
call   1030 <putchar@plt>
mov    0x0(%rbp),%ebx
add    $0x4,%rbp
test   %ebx,%ebx
je     11a7 <printfn+0x87>
cmp    %r15,%rbp
ja     11a1 <printfn+0x81>
cmp    $0x80,%ebx
jb     1187 <printfn+0x67>
and    $0x7f,%ebx
mov    $0x4d,%edi
call   1030 <putchar@plt>
mov    $0x2d,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1040 <isprint@plt>
test   %eax,%eax
jne    1150 <printfn+0x30>
xor    $0x40,%ebx
mov    $0x5e,%edi
call   1030 <putchar@plt>
jmp    1150 <printfn+0x30>
mov    $0x1,%r14d
mov    $0x22,%edi
call   1030 <putchar@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @printfn(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %4
store i32* %1, i32** %5
%7 = call i32 @putchar(i8 signext 34)
br label %8
8: ; preds = %36, %2
%9 = load i32*, i32** %4
%10 = getelementptr inbounds i32, i32* %9, i32 1
store i32* %10, i32** %4
%11 = load i32, i32* %9
store i32 %11, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %40
13: ; preds = %8
%14 = load i32*, i32** %4
%15 = load i32*, i32** %5
%16 = icmp ugt i32* %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @putchar(i8 signext 34)
store i32 1, i32* %3
br label %42
19: ; preds = %13
%20 = load i32, i32* %6
%21 = call i32 @isascii(i32 %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %28, label %23
23: ; preds = %19
%24 = load i32, i32* %6
%25 = call i32 @toascii(i32 %24)
store i32 %25, i32* %6
%26 = call i32 @putchar(i8 signext 77)
%27 = call i32 @putchar(i8 signext 45)
br label %28
28: ; preds = %23, %19
%29 = load i32, i32* %6
%30 = call i32 @isprint(i32 %29)
%31 = icmp ne i32 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i32, i32* %6
%34 = xor i32 %33, 64
store i32 %34, i32* %6
%35 = call i32 @putchar(i8 signext 94)
br label %36
36: ; preds = %32, %28
%37 = load i32, i32* %6
%38 = trunc i32 %37 to i8
%39 = call i32 @putchar(i8 signext %38)
br label %8
40: ; preds = %8
%41 = call i32 @putchar(i8 signext 34)
store i32 0, i32* %3
br label %42
42: ; preds = %40, %17
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
define i32 @printfn(i32* %0, i32* readnone %1) {
%3 = tail call i32 @putchar(i8 signext 34)
%4 = load i32, i32* %0
%5 = icmp eq i32 %4, 0
br i1 %5, label %30, label %6
6: ; preds = %2, %24
%7 = phi i32 [ %28, %24 ], [ %4, %2 ]
%8 = phi i32* [ %9, %24 ], [ %0, %2 ]
%9 = getelementptr inbounds i32, i32* %8, i64 1
%10 = icmp ugt i32* %9, %1
br i1 %10, label %30, label %11
11: ; preds = %6
%12 = icmp ult i32 %7, 128
br i1 %12, label %17, label %13
13: ; preds = %11
%14 = and i32 %7, 127
%15 = tail call i32 @putchar(i8 signext 77)
%16 = tail call i32 @putchar(i8 signext 45)
br label %17
17: ; preds = %13, %11
%18 = phi i32 [ %7, %11 ], [ %14, %13 ]
%19 = tail call i32 @isprint(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = xor i32 %18, 64
%23 = tail call i32 @putchar(i8 signext 94)
br label %24
24: ; preds = %21, %17
%25 = phi i32 [ %18, %17 ], [ %22, %21 ]
%26 = trunc i32 %25 to i8
%27 = tail call i32 @putchar(i8 signext %26)
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %6
30: ; preds = %24, %6, %2
%31 = phi i32 [ 0, %2 ], [ 1, %6 ], [ 0, %24 ]
%32 = tail call i32 @putchar(i8 signext 34)
ret i32 %31
}