#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 */
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
void echo_quote(FILE *in, FILE *out, char ch) {
  char d;
  fputc(ch, out);
  while ((d = fgetc(in)) != ch) {
    fputc(d, out);
    if (d == '\\') {
      fputc(fgetc(in), out);
    }
  }
  fputc(d, out);
}


x86 assembly (clang, -O0):
<echo_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x12(%rbp)
movsbl %al,%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     1195 <echo_quote+0x75>
mov    -0x12(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
movsbl -0x12(%rbp),%eax
cmp    $0x5c,%eax
jne    1190 <echo_quote+0x70>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
jmp    1144 <echo_quote+0x24>
mov    -0x12(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1040 <fputc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<echo_quote>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbp
mov    %edx,%edi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <fputc@plt>
mov    %rbp,%rdi
call   1030 <fgetc@plt>
cmp    %r14b,%al
je     1174 <echo_quote+0x54>
movsbl %al,%ebx
mov    %ebx,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
cmp    $0x5c,%bl
jne    1145 <echo_quote+0x25>
mov    %rbp,%rdi
call   1030 <fgetc@plt>
movsbl %al,%edi
mov    %r15,%rsi
jmp    1140 <echo_quote+0x20>
movsbl %r14b,%edi
mov    %r15,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fputc@plt>

LLVM IR (-O0):
define void @echo_quote(i32* %0, i32* %1, i8 signext %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i8
%7 = alloca i8
store i32* %0, i32** %4
store i32* %1, i32** %5
store i8 %2, i8* %6
%8 = load i8, i8* %6
%9 = load i32*, i32** %5
%10 = call i32 @fputc(i8 signext %8, i32* %9)
br label %11
11: ; preds = %30, %3
%12 = load i32*, i32** %4
%13 = call signext i8 @fgetc(i32* %12)
store i8 %13, i8* %7
%14 = sext i8 %13 to i32
%15 = load i8, i8* %6
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %14, %16
br i1 %17, label %18, label %31
18: ; preds = %11
%19 = load i8, i8* %7
%20 = load i32*, i32** %5
%21 = call i32 @fputc(i8 signext %19, i32* %20)
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 92
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i32*, i32** %4
%27 = call signext i8 @fgetc(i32* %26)
%28 = load i32*, i32** %5
%29 = call i32 @fputc(i8 signext %27, i32* %28)
br label %30
30: ; preds = %25, %18
br label %11
31: ; preds = %11
%32 = load i8, i8* %7
%33 = load i32*, i32** %5
%34 = call i32 @fputc(i8 signext %32, i32* %33)
ret void
}

LLVM IR (-O2):
define void @echo_quote(i32* nocapture %0, i32* nocapture %1, i8 signext %2) {
%4 = tail call i32 @fputc(i8 signext %2, i32* %1)
%5 = tail call signext i8 @fgetc(i32* %0)
%6 = icmp eq i8 %5, %2
br i1 %6, label %17, label %7
7: ; preds = %3, %14
%8 = phi i8 [ %15, %14 ], [ %5, %3 ]
%9 = tail call i32 @fputc(i8 signext %8, i32* %1)
%10 = icmp eq i8 %8, 92
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call signext i8 @fgetc(i32* %0)
%13 = tail call i32 @fputc(i8 signext %12, i32* %1)
br label %14
14: ; preds = %11, %7
%15 = tail call signext i8 @fgetc(i32* %0)
%16 = icmp eq i8 %15, %2
br i1 %16, label %17, label %7
17: ; preds = %14, %3
%18 = tail call i32 @fputc(i8 signext %2, i32* %1)
ret void
}