#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 /*<<< orphan*/ memmove(char *, char *, int);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void forth_print(FILE *outfd, char *buf) {
  char *obuf;
  obuf = buf;
  buf[strlen(buf) - 1] = '\0';
  if (strncmp(obuf, ": \\ ", 4) == 0) {
    fprintf(outfd, "\": \\\\ 10 parse drop drop ; immediate\\n\",\n");
    return;
  }
  while (*buf != '\0') {
    if (strncmp(buf, " \\ ", 3) == 0) {
      *buf = '\0';
      break;
    }
    if (*buf == '"') {
      memmove(buf + 1, buf, strlen(buf) + 1);
      *buf = '\\';
      buf++;
    }
    buf++;
  }
  if (*obuf == '\0' || *obuf == '\\')
    return;
  buf[0] = '\\';
  buf[1] = 'n';
  buf[2] = '\0';
  fprintf(outfd, "\"%s\",\n", obuf);
}


x86 assembly (clang, -O0):
<forth_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11af <forth_print+0x6f>
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    12a4 <forth_print+0x164>
jmp    11b4 <forth_print+0x74>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1252 <forth_print+0x112>
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11ef <forth_print+0xaf>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1252 <forth_print+0x112>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    1241 <forth_print+0x101>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memmove@plt>
mov    -0x10(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11b4 <forth_print+0x74>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1272 <forth_print+0x132>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1277 <forth_print+0x137>
jmp    12a4 <forth_print+0x164>
mov    -0x10(%rbp),%rax
movb   $0x5c,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x6e,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd92(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<forth_print>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     11e9 <forth_print+0x99>
cmpb   $0x0,(%r15)
je     121d <forth_print+0xcd>
lea    0xe68(%rip),%r12
mov    %r15,%rbx
jmp    11ad <forth_print+0x5d>
xchg   %ax,%ax
lea    0x1(%rbx),%rax
cmpb   $0x0,0x1(%rbx)
mov    %rax,%rbx
je     1211 <forth_print+0xc1>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     120b <forth_print+0xbb>
cmpb   $0x22,(%rbx)
jne    11a0 <forth_print+0x50>
lea    0x1(%rbx),%r13
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1060 <memmove@plt>
movb   $0x5c,(%rbx)
mov    %r13,%rbx
jmp    11a0 <forth_print+0x50>
lea    0xe15(%rip),%rdi
mov    $0x29,%esi
mov    $0x1,%edx
mov    %r14,%rcx
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1070 <fwrite@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rax
mov    (%r15),%cl
test   %cl,%cl
je     121d <forth_print+0xcd>
cmp    $0x5c,%cl
jne    1227 <forth_print+0xd7>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
movw   $0x6e5c,(%rax)
movb   $0x0,0x2(%rax)
lea    0xdf8(%rip),%rsi
mov    %r14,%rdi
mov    %r15,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1050 <fprintf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c": \\ \00"
@.str.1 = [42 x i8] c"\22: \\\\ 10 parse drop drop ; immediate\\n\22,\0A\00"
@.str.2 = [4 x i8] c" \\ \00"
@.str.3 = [7 x i8] c"\22%s\22,\0A\00"
define void @forth_print(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 i8*, i8** %4
store i8* %6, i8** %5
%7 = load i8*, i8** %4
%8 = load i8*, i8** %4
%9 = call i32 @strlen(i8* %8)
%10 = sub nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
store i8 0, i8* %12
%13 = load i8*, i8** %5
%14 = call i64 @strncmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32*, i32** %3
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %17, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
br label %71
19: ; preds = %2
br label %20
20: ; preds = %47, %19
%21 = load i8*, i8** %4
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %50
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = call i64 @strncmp(i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = load i8*, i8** %4
store i8 0, i8* %30
br label %50
31: ; preds = %25
%32 = load i8*, i8** %4
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 34
br i1 %35, label %36, label %47
36: ; preds = %31
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8*, i8** %4
%40 = load i8*, i8** %4
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %41, 1
%43 = call i32 @memmove(i8* %38, i8* %39, i32 %42)
%44 = load i8*, i8** %4
store i8 92, i8* %44
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i32 1
store i8* %46, i8** %4
br label %47
47: ; preds = %36, %31
%48 = load i8*, i8** %4
%49 = getelementptr inbounds i8, i8* %48, i32 1
store i8* %49, i8** %4
br label %20
50: ; preds = %29, %20
%51 = load i8*, i8** %5
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 0
br i1 %54, label %60, label %55
55: ; preds = %50
%56 = load i8*, i8** %5
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 92
br i1 %59, label %60, label %61
60: ; preds = %55, %50
br label %71
61: ; preds = %55
%62 = load i8*, i8** %4
%63 = getelementptr inbounds i8, i8* %62, i64 0
store i8 92, i8* %63
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i64 1
store i8 110, i8* %65
%66 = load i8*, i8** %4
%67 = getelementptr inbounds i8, i8* %66, i64 2
store i8 0, i8* %67
%68 = load i32*, i32** %3
%69 = load i8*, i8** %5
%70 = call i32 (i32*, i8*, ...) @fprintf(i32* %68, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %61, %60, %16
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c": \\ \00"
@.str.1 = [42 x i8] c"\22: \\\\ 10 parse drop drop ; immediate\\n\22,\0A\00"
@.str.2 = [4 x i8] c" \\ \00"
@.str.3 = [7 x i8] c"\22%s\22,\0A\00"
define void @forth_print(i32* nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, -1
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %1, i64 %5
store i8 0, i8* %6
%7 = tail call i64 @strncmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = load i8, i8* %1
%11 = icmp eq i8 %10, 0
br i1 %11, label %39, label %14
12: ; preds = %2
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i64 41, i64 1, i32* %0)
br label %39
14: ; preds = %9, %27
%15 = phi i8* [ %29, %27 ], [ %1, %9 ]
%16 = tail call i64 @strncmp(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i8 0, i8* %15
br label %32
19: ; preds = %14
%20 = load i8, i8* %15
%21 = icmp eq i8 %20, 34
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = getelementptr inbounds i8, i8* %15, i64 1
%24 = tail call i32 @strlen(i8* %15)
%25 = add nsw i32 %24, 1
%26 = tail call i32 @memmove(i8* %23, i8* %15, i32 %25)
store i8 92, i8* %15
br label %27
27: ; preds = %22, %19
%28 = phi i8* [ %23, %22 ], [ %15, %19 ]
%29 = getelementptr inbounds i8, i8* %28, i64 1
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %14
32: ; preds = %27, %18
%33 = phi i8* [ %15, %18 ], [ %29, %27 ]
%34 = load i8, i8* %1
switch i8 %34, label %35 [
i8 0, label %39
i8 92, label %39
]
35: ; preds = %32
store i8 92, i8* %33
%36 = getelementptr inbounds i8, i8* %33, i64 1
store i8 110, i8* %36
%37 = getelementptr inbounds i8, i8* %33, i64 2
store i8 0, i8* %37
%38 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %39
39: ; preds = %9, %32, %32, %35, %12
ret void
}