#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 */
char read_byte();
int /*<<< orphan*/ write_src(char *);
int /*<<< orphan*/ write_src_noindent(char *, ...);
void writestr_handler(void) {
  write_src("vid_write(\"");
  while (1) {
    char c = read_byte();
    if (c)
      write_src_noindent("%c", c & 0xFF);
    else
      break;
    if (c == '\\')
      write_src_noindent("%c", '\\');
  }
  write_src_noindent("\");\n");
}


x86 assembly (clang, -O0):
<writestr_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1040 <write_src@plt>
mov    $0x0,%al
call   1030 <read_byte@plt>
mov    %al,-0x1(%rbp)
cmpb   $0x0,-0x1(%rbp)
je     1175 <writestr_handler+0x45>
movsbl -0x1(%rbp),%esi
and    $0xff,%esi
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1050 <write_src_noindent@plt>
jmp    117a <writestr_handler+0x4a>
jmp    119f <writestr_handler+0x6f>
movsbl -0x1(%rbp),%eax
cmp    $0x5c,%eax
jne    119a <writestr_handler+0x6a>
lea    0xe7e(%rip),%rdi
mov    $0x5c,%esi
mov    $0x0,%al
call   1050 <write_src_noindent@plt>
jmp    1144 <writestr_handler+0x14>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1050 <write_src_noindent@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writestr_handler>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1040 <write_src@plt>
xor    %eax,%eax
call   1030 <read_byte@plt>
test   %al,%al
je     1191 <writestr_handler+0x61>
lea    0xebb(%rip),%rbx
jmp    116b <writestr_handler+0x3b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1030 <read_byte@plt>
test   %al,%al
je     1191 <writestr_handler+0x61>
movzbl %al,%ebp
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <write_src_noindent@plt>
cmp    $0x5c,%bpl
jne    1160 <writestr_handler+0x30>
mov    %rbx,%rdi
mov    $0x5c,%esi
xor    %eax,%eax
call   1050 <write_src_noindent@plt>
jmp    1160 <writestr_handler+0x30>
lea    0xe77(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <write_src_noindent@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"vid_write(\22\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [5 x i8] c"\22);\0A\00"
define void @writestr_handler() {
%1 = alloca i8
%2 = call i32 @write_src(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %3
3: ; preds = %0, %19
%4 = call signext i8 (...) @read_byte()
store i8 %4, i8* %1
%5 = load i8, i8* %1
%6 = icmp ne i8 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = load i8, i8* %1
%9 = sext i8 %8 to i32
%10 = and i32 %9, 255
%11 = call i32 (i8*, ...) @write_src_noindent(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %10)
br label %13
12: ; preds = %3
br label %20
13: ; preds = %7
%14 = load i8, i8* %1
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 92
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 (i8*, ...) @write_src_noindent(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 92)
br label %19
19: ; preds = %17, %13
br label %3
20: ; preds = %12
%21 = call i32 (i8*, ...) @write_src_noindent(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"vid_write(\22\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [5 x i8] c"\22);\0A\00"
define void @writestr_handler() {
%1 = tail call i32 @write_src(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%2 = tail call signext i8 (...) @read_byte()
%3 = icmp eq i8 %2, 0
br i1 %3, label %14, label %4
4: ; preds = %0, %11
%5 = phi i8 [ %12, %11 ], [ %2, %0 ]
%6 = zext i8 %5 to i32
%7 = tail call i32 (i8*, ...) @write_src_noindent(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp eq i8 %5, 92
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @write_src_noindent(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 92)
br label %11
11: ; preds = %4, %9
%12 = tail call signext i8 (...) @read_byte()
%13 = icmp eq i8 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %11, %0
%15 = tail call i32 (i8*, ...) @write_src_noindent(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret void
}