#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 */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, ...);
int print_escaped(int count, char *buf, int pos, FILE *out) {
  int i;
  for (i = 0; i < count; ++i) {
    int c;
    if (pos >= 68) {
      fprintf(out, "\"\n\t\"");
      pos = 0;
    }
    pos += fprintf(out, "\\%03hho", *buf++);
  }
  return pos;
}


x86 assembly (clang, -O0):
<print_escaped>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    119b <print_escaped+0x8b>
cmpl   $0x44,-0x14(%rbp)
jl     115c <print_escaped+0x4c>
mov    -0x20(%rbp),%rdi
lea    0xeb2(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%edx
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    %rax,%rcx
movslq -0x14(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112d <print_escaped+0x1d>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_escaped>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
test   %edi,%edi
jle    1191 <print_escaped+0x71>
mov    %rcx,%rbx
mov    %rsi,%r14
mov    %edi,%r13d
lea    0xec4(%rip),%r12
xor    %r15d,%r15d
jmp    116f <print_escaped+0x4f>
cs nopw 0x0(%rax,%rax,1)
movsbl (%r14,%r15,1),%edx
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    %ebp,%eax
add    $0x1,%r15
mov    %eax,%ebp
cmp    %r15d,%r13d
je     1193 <print_escaped+0x73>
cmp    $0x44,%ebp
jl     1150 <print_escaped+0x30>
mov    $0x4,%esi
mov    $0x1,%edx
lea    0xe7b(%rip),%rdi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
xor    %ebp,%ebp
jmp    1150 <print_escaped+0x30>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"\22\0A\09\22\00"
@.str.1 = [8 x i8] c"\\%03hho\00"
define i32 @print_escaped(i32 %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
br label %11
11: ; preds = %32, %4
%12 = load i32, i32* %9
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %35
15: ; preds = %11
%16 = load i32, i32* %7
%17 = icmp sge i32 %16, 68
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load i32*, i32** %8
%20 = call i64 (i32*, i8*, ...) @fprintf(i32* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %21
21: ; preds = %18, %15
%22 = load i32*, i32** %8
%23 = load i8*, i8** %6
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %6
%25 = load i8, i8* %23
%26 = sext i8 %25 to i32
%27 = call i64 (i32*, i8*, ...) @fprintf(i32* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %26)
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = add nsw i64 %29, %27
%31 = trunc i64 %30 to i32
store i32 %31, i32* %7
br label %32
32: ; preds = %21
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %11
35: ; preds = %11
%36 = load i32, i32* %7
ret i32 %36
}

LLVM IR (-O2):
@.str = [5 x i8] c"\22\0A\09\22\00"
@.str.1 = [8 x i8] c"\\%03hho\00"
define i32 @print_escaped(i32 %0, i8* nocapture %1, i32 %2, i32* nocapture %3) {
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %23
6: ; preds = %4, %13
%7 = phi i8* [ %15, %13 ], [ %1, %4 ]
%8 = phi i32 [ %21, %13 ], [ 0, %4 ]
%9 = phi i32 [ %20, %13 ], [ %2, %4 ]
%10 = icmp sgt i32 %9, 67
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 4, i64 1, i32* %3)
br label %13
13: ; preds = %11, %6
%14 = phi i32 [ 0, %11 ], [ %9, %6 ]
%15 = getelementptr inbounds i8, i8* %7, i64 1
%16 = load i8, i8* %7
%17 = sext i8 %16 to i32
%18 = tail call i64 (i32*, i8*, ...) @fprintf(i32* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = trunc i64 %18 to i32
%20 = add i32 %14, %19
%21 = add nuw nsw i32 %8, 1
%22 = icmp eq i32 %21, %0
br i1 %22, label %23, label %6
23: ; preds = %13, %4
%24 = phi i32 [ %2, %4 ], [ %20, %13 ]
ret i32 %24
}