#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 *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ iscntrl(int);
int /*<<< orphan*/ putc(char const, int /*<<< orphan*/ *);
void formatString(FILE *ofile, const char *s, int len) {
  putc('"', ofile);
  for (; len > 0; --len, ++s) {
    int c = *s;
    switch (c) {
    case '&':
      fputs("&amp;", ofile);
      break;
    case '"':
      fputs("&quot;", ofile);
      break;
    default:
      if (iscntrl(c))
        fprintf(ofile, "&#%d;", c);
      else
        putc(*s, ofile);
      break;
    }
  }
  fputs("\"\n", ofile);
}


x86 assembly (clang, -O0):
<formatString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1050 <putc@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1223 <formatString+0xe3>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x22,%eax
je     11af <formatString+0x6f>
jmp    1189 <formatString+0x49>
mov    -0x1c(%rbp),%eax
sub    $0x26,%eax
jne    11c4 <formatString+0x84>
jmp    119a <formatString+0x5a>
mov    -0x8(%rbp),%rsi
lea    0xe5b(%rip),%rdi
call   1040 <fputs@plt>
jmp    1204 <formatString+0xc4>
mov    -0x8(%rbp),%rsi
lea    0xe4c(%rip),%rdi
call   1040 <fputs@plt>
jmp    1204 <formatString+0xc4>
mov    -0x18(%rbp),%edi
call   1030 <iscntrl@plt>
cmp    $0x0,%eax
je     11ed <formatString+0xad>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe2a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11ff <formatString+0xbf>
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1050 <putc@plt>
jmp    1204 <formatString+0xc4>
jmp    1209 <formatString+0xc9>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1161 <formatString+0x21>
mov    -0x8(%rbp),%rsi
lea    0xde5(%rip),%rdi
call   1040 <fputs@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<formatString>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x22,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
test   %ebp,%ebp
jle    11ed <formatString+0xad>
add    $0x1,%ebp
lea    0xe94(%rip),%r15
lea    0xe87(%rip),%r12
jmp    11a1 <formatString+0x61>
nopl   0x0(%rax,%rax,1)
mov    $0x6,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1060 <fwrite@plt>
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
jle    11ed <formatString+0xad>
movsbl (%rbx),%r13d
cmp    $0x22,%r13d
je     1180 <formatString+0x40>
cmp    $0x26,%r13d
jne    11c0 <formatString+0x80>
mov    $0x5,%esi
mov    $0x1,%edx
mov    %r12,%rdi
jmp    118d <formatString+0x4d>
mov    %r13d,%edi
call   1030 <iscntrl@plt>
test   %eax,%eax
je     11e0 <formatString+0xa0>
mov    %r14,%rdi
lea    0xe37(%rip),%rsi
mov    %r13d,%edx
call   1050 <fprintf@plt>
jmp    1195 <formatString+0x55>
mov    %r13d,%edi
mov    %r14,%rsi
call   1040 <putc@plt>
jmp    1195 <formatString+0x55>
lea    0xe1f(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fwrite@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"&amp;\00"
@.str.1 = [7 x i8] c"&quot;\00"
@.str.2 = [6 x i8] c"&#%d;\00"
@.str.3 = [3 x i8] c"\22\0A\00"
define void @formatString(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32*, i32** %4
%9 = call i32 @putc(i8 signext 34, i32* %8)
br label %10
10: ; preds = %39, %3
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %44
13: ; preds = %10
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
store i32 %16, i32* %7
%17 = load i32, i32* %7
switch i32 %17, label %24 [
i32 38, label %18
i32 34, label %21
]
18: ; preds = %13
%19 = load i32*, i32** %4
%20 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %19)
br label %38
21: ; preds = %13
%22 = load i32*, i32** %4
%23 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %38
24: ; preds = %13
%25 = load i32, i32* %7
%26 = call i32 @iscntrl(i32 %25)
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32*, i32** %4
%30 = load i32, i32* %7
%31 = call i32 @fprintf(i32* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %37
32: ; preds = %24
%33 = load i8*, i8** %5
%34 = load i8, i8* %33
%35 = load i32*, i32** %4
%36 = call i32 @putc(i8 signext %34, i32* %35)
br label %37
37: ; preds = %32, %28
br label %38
38: ; preds = %37, %21, %18
br label %39
39: ; preds = %38
%40 = load i32, i32* %6
%41 = add nsw i32 %40, -1
store i32 %41, i32* %6
%42 = load i8*, i8** %5
%43 = getelementptr inbounds i8, i8* %42, i32 1
store i8* %43, i8** %5
br label %10
44: ; preds = %10
%45 = load i32*, i32** %4
%46 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %45)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"&amp;\00"
@.str.1 = [7 x i8] c"&quot;\00"
@.str.2 = [6 x i8] c"&#%d;\00"
@.str.3 = [3 x i8] c"\22\0A\00"
define void @formatString(i32* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32 @putc(i8 signext 34, i32* %0)
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %26
6: ; preds = %3, %22
%7 = phi i8* [ %24, %22 ], [ %1, %3 ]
%8 = phi i32 [ %23, %22 ], [ %2, %3 ]
%9 = load i8, i8* %7
%10 = sext i8 %9 to i32
switch i32 %10, label %15 [
i32 38, label %11
i32 34, label %13
]
11: ; preds = %6
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 5, i64 1, i32* %0)
br label %22
13: ; preds = %6
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 6, i64 1, i32* %0)
br label %22
15: ; preds = %6
%16 = tail call i32 @iscntrl(i32 %10)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = tail call i32 @fprintf(i32* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %22
20: ; preds = %15
%21 = tail call i32 @putc(i8 signext %9, i32* %0)
br label %22
22: ; preds = %18, %20, %13, %11
%23 = add nsw i32 %8, -1
%24 = getelementptr inbounds i8, i8* %7, i64 1
%25 = icmp sgt i32 %8, 1
br i1 %25, label %6, label %26
26: ; preds = %22, %3
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %0)
ret void
}