#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*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
char *strchr(char const *, char);
__attribute__((unused)) void write_quoted(FILE *f, const char *s) {
  fputc('"', f);
  for (const char *t; (t = strchr(s, '"'));) {
    fwrite(s, 1, t - s, f);
    fputs("\\\"", f);
    s = t + 1;
  }
  fputs(s, f);
  fputc('"', f);
}


x86 assembly (clang, -O0):
<write_quoted>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1050 <fputc@plt>
mov    -0x10(%rbp),%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ba <write_quoted+0x7a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    -0x8(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1040 <fputs@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    115e <write_quoted+0x1e>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <fputs@plt>
mov    -0x8(%rbp),%rsi
mov    $0x22,%edi
call   1050 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_quoted>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x22,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
mov    %rbx,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11c6 <write_quoted+0x86>
mov    %rax,%r12
lea    0xe89(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edx
sub    %ebx,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    $0x2,%esi
mov    $0x1,%edx
mov    %r15,%rdi
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %r12,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x22,%esi
call   1030 <strchr@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1180 <write_quoted+0x40>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <fputs@plt>
mov    $0x22,%edi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <fputc@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"\\\22\00"
define void @write_quoted(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%6 = load i32*, i32** %3
%7 = call i32 @fputc(i8 signext 34, i32* %6)
br label %8
8: ; preds = %12, %2
%9 = load i8*, i8** %4
%10 = call i8* @strchr(i8* %9, i8 signext 34)
store i8* %10, i8** %5
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %26
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = ptrtoint i8* %14 to i64
%17 = ptrtoint i8* %15 to i64
%18 = sub i64 %16, %17
%19 = trunc i64 %18 to i32
%20 = load i32*, i32** %3
%21 = call i32 @fwrite(i8* %13, i32 1, i32 %19, i32* %20)
%22 = load i32*, i32** %3
%23 = call i32 @fputs(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %22)
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 1
store i8* %25, i8** %4
br label %8
26: ; preds = %8
%27 = load i8*, i8** %4
%28 = load i32*, i32** %3
%29 = call i32 @fputs(i8* %27, i32* %28)
%30 = load i32*, i32** %3
%31 = call i32 @fputc(i8 signext 34, i32* %30)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"\\\22\00"
define void @write_quoted(i32* %0, i8* %1) {
%3 = tail call i32 @fputc(i8 signext 34, i32* %0)
%4 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 34)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %10
6: ; preds = %10, %2
%7 = phi i8* [ %1, %2 ], [ %19, %10 ]
%8 = tail call i32 @fputs(i8* %7, i32* %0)
%9 = tail call i32 @fputc(i8 signext 34, i32* %0)
ret void
10: ; preds = %2, %10
%11 = phi i8* [ %20, %10 ], [ %4, %2 ]
%12 = phi i8* [ %19, %10 ], [ %1, %2 ]
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = tail call i32 @fwrite(i8* %12, i32 1, i32 %16, i32* %0)
%18 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i64 2, i64 1, i32* %0)
%19 = getelementptr inbounds i8, i8* %11, i64 1
%20 = tail call i8* @strchr(i8* dereferenceable(1) %19, i8 signext 34)
%21 = icmp eq i8* %20, null
br i1 %21, label %6, label %10
}