void fwriteStrEscapedMaxNumChars(int f, const char *c) {
  static const int N = 60;
  char buffer[N + 5];
  char *t = buffer;
  int numChars = 0;
  while (numChars < N && c != '\0') {
    *t++ = *c++;
    numChars++;
  }
  if (c != '\0') {
    *t++ = '.';
    *t++ = '.';
    *t++ = '.';
  }
  *t++ = '\0';
  fwriteStrEscaped(f, buffer);
}


x86 assembly (clang, -O0):
<fwriteStrEscapedMaxNumChars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rsp,%rax
mov    %rax,-0x18(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
xor    %eax,%eax
cmpl   $0x3c,-0x24(%rbp)
mov    %al,-0x71(%rbp)
jge    1152 <fwriteStrEscapedMaxNumChars+0x42>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    1162 <fwriteStrEscapedMaxNumChars+0x52>
jmp    1192 <fwriteStrEscapedMaxNumChars+0x82>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1138 <fwriteStrEscapedMaxNumChars+0x28>
cmpq   $0x0,-0x10(%rbp)
je     11d3 <fwriteStrEscapedMaxNumChars+0xc3>
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x2e,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movb   $0x0,(%rax)
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x0,%al
call   1030 <fwriteStrEscaped@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fwriteStrEscapedMaxNumChars>:
sub    $0x48,%rsp
test   %rsi,%rsi
je     114e <fwriteStrEscapedMaxNumChars+0x3e>
movups (%rsi),%xmm0
movups 0x10(%rsi),%xmm1
movups 0x20(%rsi),%xmm2
movups 0x2c(%rsi),%xmm3
movups %xmm3,0x2c(%rsp)
movaps %xmm2,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x2e2e,0x3c(%rsp)
lea    0x3f(%rsp),%rax
movb   $0x2e,0x3e(%rsp)
jmp    1151 <fwriteStrEscapedMaxNumChars+0x41>
mov    %rsp,%rax
movb   $0x0,(%rax)
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <fwriteStrEscaped@plt>
add    $0x48,%rsp
ret

LLVM IR (-O0):
@fwriteStrEscapedMaxNumChars.N = internal constant i32 60
define void @fwriteStrEscapedMaxNumChars(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %5
%9 = alloca i8, i64 65
store i8* %9, i8** %6
store i32 0, i32* %7
br label %10
10: ; preds = %18, %2
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 60
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load i8*, i8** %4
%15 = icmp ne i8* %14, null
br label %16
16: ; preds = %13, %10
%17 = phi i1 [ false, %10 ], [ %15, %13 ]
br i1 %17, label %18, label %26
18: ; preds = %16
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %6
store i8 %21, i8* %22
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
br label %10
26: ; preds = %16
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %36
29: ; preds = %26
%30 = load i8*, i8** %6
%31 = getelementptr inbounds i8, i8* %30, i32 1
store i8* %31, i8** %6
store i8 46, i8* %30
%32 = load i8*, i8** %6
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %6
store i8 46, i8* %32
%34 = load i8*, i8** %6
%35 = getelementptr inbounds i8, i8* %34, i32 1
store i8* %35, i8** %6
store i8 46, i8* %34
br label %36
36: ; preds = %29, %26
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %6
store i8 0, i8* %37
%39 = load i32, i32* %3
%40 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @fwriteStrEscaped to i32 (i32, i8*, ...)*)(i32 %39, i8* %9)
%41 = load i8*, i8** %5
ret void
}

LLVM IR (-O2):
define void @fwriteStrEscapedMaxNumChars(i32 %0, i8* %1) {
%3 = alloca [65 x i8]
%4 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 60
%9 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 61
store i8 46, i8* %8
%10 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 62
store i8 46, i8* %9
%11 = getelementptr inbounds [65 x i8], [65 x i8]* %3, i64 0, i64 63
store i8 46, i8* %10
br label %12
12: ; preds = %2, %6
%13 = phi i8* [ %11, %6 ], [ %4, %2 ]
store i8 0, i8* %13
%14 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @fwriteStrEscaped to i32 (i32, i8*, ...)*)(i32 %0, i8* %4)
ret void
}