#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 EOF;
int /*<<< orphan*/ addCharToText(int);
int /*<<< orphan*/ addStrToLabel(char *);
int /*<<< orphan*/ flushtext();
int getc(int /*<<< orphan*/ *);
void printtoST(int term, char *label, FILE *fd) {
  int c;
  addStrToLabel(label);
  while ((c = getc(fd)) != EOF) {
    addCharToText(c);
    if (c == 0x1b) {
      if ((c = getc(fd)) != EOF) {
        addCharToText(c);
        if (c == '\\') {
          flushtext();
          return;
        }
      }
    } else if (c == term) {
      flushtext();
      return;
    } else if (c == 0x0a) {
      addStrToLabel(" interrupted escape sequence");
      flushtext();
      return;
    }
  }
  addStrToLabel(" interrupted escape sequence");
  flushtext();
}


x86 assembly (clang, -O0):
<printtoST>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <addStrToLabel@plt>
mov    -0x18(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%eax
je     1215 <printtoST+0xd5>
mov    -0x1c(%rbp),%edi
call   1040 <addCharToText@plt>
cmpl   $0x1b,-0x1c(%rbp)
jne    11cc <printtoST+0x8c>
mov    -0x18(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%eax
je     11c7 <printtoST+0x87>
mov    -0x1c(%rbp),%edi
call   1040 <addCharToText@plt>
cmpl   $0x5c,-0x1c(%rbp)
jne    11c2 <printtoST+0x82>
mov    $0x0,%al
call   1060 <flushtext@plt>
jmp    1228 <printtoST+0xe8>
jmp    11c7 <printtoST+0x87>
jmp    1210 <printtoST+0xd0>
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jne    11e4 <printtoST+0xa4>
mov    $0x0,%al
call   1060 <flushtext@plt>
jmp    1228 <printtoST+0xe8>
cmpl   $0xa,-0x1c(%rbp)
jne    1206 <printtoST+0xc6>
lea    0xe0b(%rip),%rdi
call   1030 <addStrToLabel@plt>
mov    $0x0,%al
call   1060 <flushtext@plt>
jmp    1228 <printtoST+0xe8>
jmp    120b <printtoST+0xcb>
jmp    1210 <printtoST+0xd0>
jmp    115c <printtoST+0x1c>
lea    0xde4(%rip),%rdi
call   1030 <addStrToLabel@plt>
mov    $0x0,%al
call   1060 <flushtext@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printtoST>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %edi,%r14d
mov    %rsi,%rdi
call   1030 <addStrToLabel@plt>
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    0x2e84(%rip),%r15
cmp    (%r15),%eax
jne    1186 <printtoST+0x46>
lea    0xe90(%rip),%rdi
call   1030 <addStrToLabel@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <flushtext@plt>
mov    %eax,%ebp
jmp    119f <printtoST+0x5f>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <getc@plt>
mov    %eax,%ebp
cmp    (%r15),%eax
je     1169 <printtoST+0x29>
mov    %ebp,%edi
call   1040 <addCharToText@plt>
cmp    $0x1b,%ebp
jne    11d0 <printtoST+0x90>
mov    %rbx,%rdi
call   1050 <getc@plt>
cmp    (%r15),%eax
je     1190 <printtoST+0x50>
mov    %eax,%ebp
mov    %eax,%edi
call   1040 <addCharToText@plt>
cmp    $0x5c,%ebp
jne    1190 <printtoST+0x50>
jmp    1175 <printtoST+0x35>
nopl   0x0(%rax,%rax,1)
cmp    %r14d,%ebp
je     1175 <printtoST+0x35>
cmp    $0xa,%ebp
jne    1190 <printtoST+0x50>
jmp    1169 <printtoST+0x29>

LLVM IR (-O0):
@EOF = global i32 0
@.str = [29 x i8] c" interrupted escape sequence\00"
define void @printtoST(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 i8*, i8** %5
%9 = call i32 @addStrToLabel(i8* %8)
br label %10
10: ; preds = %48, %3
%11 = load i32*, i32** %6
%12 = call i32 @getc(i32* %11)
store i32 %12, i32* %7
%13 = load i32, i32* @EOF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %49
15: ; preds = %10
%16 = load i32, i32* %7
%17 = call i32 @addCharToText(i32 %16)
%18 = load i32, i32* %7
%19 = icmp eq i32 %18, 27
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = load i32*, i32** %6
%22 = call i32 @getc(i32* %21)
store i32 %22, i32* %7
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = load i32, i32* %7
%27 = call i32 @addCharToText(i32 %26)
%28 = load i32, i32* %7
%29 = icmp eq i32 %28, 92
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 (...) @flushtext()
br label %52
32: ; preds = %25
br label %33
33: ; preds = %32, %20
br label %48
34: ; preds = %15
%35 = load i32, i32* %7
%36 = load i32, i32* %4
%37 = icmp eq i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (...) @flushtext()
br label %52
40: ; preds = %34
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, 10
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @addStrToLabel(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%45 = call i32 (...) @flushtext()
br label %52
46: ; preds = %40
br label %47
47: ; preds = %46
br label %48
48: ; preds = %47, %33
br label %10
49: ; preds = %10
%50 = call i32 @addStrToLabel(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%51 = call i32 (...) @flushtext()
br label %52
52: ; preds = %49, %43, %38, %30
ret void
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [29 x i8] c" interrupted escape sequence\00"
define void @printtoST(i32 %0, i8* %1, i32* nocapture %2) {
%4 = tail call i32 @addStrToLabel(i8* %1)
%5 = tail call i32 @getc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %27, label %8
8: ; preds = %3, %23
%9 = phi i32 [ %24, %23 ], [ %5, %3 ]
%10 = tail call i32 @addCharToText(i32 %9)
%11 = icmp eq i32 %9, 27
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = tail call i32 @getc(i32* %2)
%14 = load i32, i32* @EOF
%15 = icmp eq i32 %13, %14
br i1 %15, label %23, label %16
16: ; preds = %12
%17 = tail call i32 @addCharToText(i32 %13)
%18 = icmp eq i32 %13, 92
br i1 %18, label %29, label %23
19: ; preds = %8
%20 = icmp eq i32 %9, %0
br i1 %20, label %29, label %21
21: ; preds = %19
%22 = icmp eq i32 %9, 10
br i1 %22, label %27, label %23
23: ; preds = %21, %12, %16
%24 = tail call i32 @getc(i32* %2)
%25 = load i32, i32* @EOF
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %8
27: ; preds = %23, %21, %3
%28 = tail call i32 @addStrToLabel(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %19, %16, %27
%30 = tail call i32 (...) @flushtext()
ret void
}