#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*/ printf(char *, char const *, ...);
int /*<<< orphan*/ quotechar(char const);
void quoteat(const char *prefix, const void *p, int len, int at) {
  static const int CTXLEN = 15;
  int i;
  const char *pre = "\"";
  const char *post = "\"";
  const char *s = p;
  if (at > CTXLEN) {
    s += at - CTXLEN;
    len -= at - CTXLEN;
    pre = "...\"";
  }
  if (at >= 0 && len > 2 * CTXLEN + 1) {
    len = 2 * CTXLEN + 1;
    post = "\"...";
  }
  printf("%4s: %s", prefix, pre);
  for (i = 0; i < len; i++)
    quotechar(s[i]);
  printf("%s\n", post);
}


x86 assembly (clang, -O0):
<quoteat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    0xeca(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xebf(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
cmpl   $0xf,-0x18(%rbp)
jle    118b <quoteat+0x6b>
mov    -0x18(%rbp),%ecx
sub    $0xf,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%ecx
sub    $0xf,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
lea    0xe7d(%rip),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     11b1 <quoteat+0x91>
cmpl   $0x1f,-0x14(%rbp)
jle    11b1 <quoteat+0x91>
movl   $0x1f,-0x14(%rbp)
lea    0xe5c(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f9 <quoteat+0xd9>
mov    -0x38(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1030 <quotechar@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <quoteat+0xae>
mov    -0x30(%rbp),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quoteat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r13
mov    %rdi,%rsi
lea    -0xf(%rcx),%r12d
xor    %eax,%eax
cmp    $0x10,%ecx
cmovl  %eax,%r12d
lea    0xebb(%rip),%rax
lea    0xeb7(%rip),%r14
cmovl  %r14,%rax
sub    %r12d,%edx
test   %ecx,%ecx
setns  %cl
cmp    $0x20,%edx
setge  %r15b
and    %cl,%r15b
mov    $0x1f,%ebp
cmove  %edx,%ebp
lea    0xe99(%rip),%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jle    11a4 <quoteat+0x84>
add    %r12,%r13
mov    %ebp,%ebp
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movsbl 0x0(%r13,%rbx,1),%edi
call   1030 <quotechar@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1190 <quoteat+0x70>
lea    0xe5a(%rip),%rax
test   %r15b,%r15b
cmovne %rax,%r14
lea    0xe59(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@quoteat.CTXLEN = internal constant i32 15
@.str = [2 x i8] c"\22\00"
@.str.1 = [5 x i8] c"...\22\00"
@.str.2 = [5 x i8] c"\22...\00"
@.str.3 = [8 x i8] c"%4s: %s\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @quoteat(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %10
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11
%13 = load i8*, i8** %6
store i8* %13, i8** %12
%14 = load i32, i32* %8
%15 = icmp sgt i32 %14, 15
br i1 %15, label %16, label %26
16: ; preds = %4
%17 = load i32, i32* %8
%18 = sub nsw i32 %17, 15
%19 = load i8*, i8** %12
%20 = sext i32 %18 to i64
%21 = getelementptr inbounds i8, i8* %19, i64 %20
store i8* %21, i8** %12
%22 = load i32, i32* %8
%23 = sub nsw i32 %22, 15
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, %23
store i32 %25, i32* %7
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %10
br label %26
26: ; preds = %16, %4
%27 = load i32, i32* %8
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 31
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 31, i32* %7
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %11
br label %33
33: ; preds = %32, %29, %26
%34 = load i8*, i8** %5
%35 = load i8*, i8** %10
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %35)
store i32 0, i32* %9
br label %37
37: ; preds = %48, %33
%38 = load i32, i32* %9
%39 = load i32, i32* %7
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = load i8*, i8** %12
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = call i32 @quotechar(i8 signext %46)
br label %48
48: ; preds = %41
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
br label %37
51: ; preds = %37
%52 = load i8*, i8** %11
%53 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %52)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"\22\00"
@.str.1 = [5 x i8] c"...\22\00"
@.str.2 = [5 x i8] c"\22...\00"
@.str.3 = [8 x i8] c"%4s: %s\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @quoteat(i8* %0, i8* nocapture %1, i32 %2, i32 %3) {
%5 = icmp sgt i32 %3, 15
%6 = add nsw i32 %3, -15
%7 = select i1 %5, i32 %6, i32 0
%8 = sub nsw i32 %2, %7
%9 = select i1 %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%10 = zext i32 %7 to i64
%11 = getelementptr i8, i8* %1, i64 %10
%12 = icmp sgt i32 %3, -1
%13 = icmp sgt i32 %8, 31
%14 = select i1 %12, i1 %13, i1 false
%15 = select i1 %14, i32 31, i32 %8
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %9)
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %27
18: ; preds = %4
%19 = zext i32 %15 to i64
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 0, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds i8, i8* %11, i64 %21
%23 = load i8, i8* %22
%24 = tail call i32 @quotechar(i8 signext %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20, %4
%28 = select i1 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%29 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
ret void
}