#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ command_prompt();
int /*<<< orphan*/ done(int, int);
int scan_for_escape(ssize_t cc, char *ibuf) {
  static int got_newline = 0;
  static int got_escape = 0;
  int i;
  for (i = 0; i < cc; i++) {
    if (got_escape && ibuf[i] == '.') {
      done(255, 1);
    } else if (got_escape && ibuf[i] == 'C') {
      got_newline = got_escape = 0;
      command_prompt();
      return 1;
    } else if (got_newline && ibuf[i] == '~') {
      got_escape = 1;
      got_newline = 0;
      return 1;
    } else if (ibuf[i] == '\r') {
      got_newline = 1;
      got_escape = 0;
    } else {
      got_newline = got_escape = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<scan_for_escape>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1267 <scan_for_escape+0x147>
cmpl   $0x0,0x2eef(%rip)
je     1178 <scan_for_escape+0x58>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
jne    1178 <scan_for_escape+0x58>
mov    $0xff,%edi
mov    $0x1,%esi
call   1030 <done@plt>
jmp    1254 <scan_for_escape+0x134>
cmpl   $0x0,0x2eb9(%rip)
je     11c1 <scan_for_escape+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x43,%eax
jne    11c1 <scan_for_escape+0xa1>
movl   $0x0,0x2e94(%rip)
movl   $0x0,0x2e86(%rip)
mov    $0x0,%al
call   1040 <command_prompt@plt>
movl   $0x1,-0x4(%rbp)
jmp    126e <scan_for_escape+0x14e>
cmpl   $0x0,0x2e6c(%rip)
je     1203 <scan_for_escape+0xe3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x7e,%eax
jne    1203 <scan_for_escape+0xe3>
movl   $0x1,0x2e4b(%rip)
movl   $0x0,0x2e3d(%rip)
movl   $0x1,-0x4(%rbp)
jmp    126e <scan_for_escape+0x14e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1231 <scan_for_escape+0x111>
movl   $0x1,0x2e12(%rip)
movl   $0x0,0x2e0c(%rip)
jmp    1245 <scan_for_escape+0x125>
movl   $0x0,0x2dfd(%rip)
movl   $0x0,0x2def(%rip)
jmp    124a <scan_for_escape+0x12a>
jmp    124f <scan_for_escape+0x12f>
jmp    1254 <scan_for_escape+0x134>
jmp    1259 <scan_for_escape+0x139>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1136 <scan_for_escape+0x16>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_for_escape>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
jle    11a8 <scan_for_escape+0x88>
mov    %rsi,%r15
mov    %edi,%r14d
mov    0x2f03(%rip),%al
xor    %ebx,%ebx
jmp    1159 <scan_for_escape+0x39>
nopl   0x0(%rax)
movb   $0x0,0x2ef1(%rip)
movb   $0x0,0x2ee6(%rip)
xor    %eax,%eax
add    $0x1,%rbx
cmp    %rbx,%r14
je     11a8 <scan_for_escape+0x88>
test   $0x1,%al
je     116a <scan_for_escape+0x4a>
movzbl (%r15,%rbx,1),%eax
cmp    $0x2e,%al
je     1190 <scan_for_escape+0x70>
cmp    $0x43,%al
je     11bc <scan_for_escape+0x9c>
movzbl (%r15,%rbx,1),%eax
cmpb   $0x1,0x2ebe(%rip)
jne    117c <scan_for_escape+0x5c>
cmp    $0x7e,%al
je     11ac <scan_for_escape+0x8c>
cmp    $0xd,%al
jne    1140 <scan_for_escape+0x20>
movb   $0x1,0x2ead(%rip)
movb   $0x0,0x2eaa(%rip)
jmp    114e <scan_for_escape+0x2e>
mov    $0xff,%edi
mov    $0x1,%esi
call   1030 <done@plt>
movzbl 0x2e92(%rip),%eax
jmp    1150 <scan_for_escape+0x30>
xor    %eax,%eax
jmp    11d6 <scan_for_escape+0xb6>
movb   $0x1,0x2e85(%rip)
movb   $0x0,0x2e7a(%rip)
jmp    11d1 <scan_for_escape+0xb1>
movb   $0x0,0x2e75(%rip)
movb   $0x0,0x2e6a(%rip)
xor    %eax,%eax
call   1040 <command_prompt@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@scan_for_escape.got_newline = internal global i32 0
@scan_for_escape.got_escape = internal global i32 0
define i32 @scan_for_escape(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 0, i32* %6
br label %7
7: ; preds = %63, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %66
11: ; preds = %7
%12 = load i32, i32* @scan_for_escape.got_escape
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %11
%15 = load i8*, i8** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @done(i32 255, i32 1)
br label %62
24: ; preds = %14, %11
%25 = load i32, i32* @scan_for_escape.got_escape
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i8*, i8** %5
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 67
br i1 %34, label %35, label %37
35: ; preds = %27
store i32 0, i32* @scan_for_escape.got_escape
store i32 0, i32* @scan_for_escape.got_newline
%36 = call i32 (...) @command_prompt()
store i32 1, i32* %3
br label %67
37: ; preds = %27, %24
%38 = load i32, i32* @scan_for_escape.got_newline
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i8*, i8** %5
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 126
br i1 %47, label %48, label %49
48: ; preds = %40
store i32 1, i32* @scan_for_escape.got_escape
store i32 0, i32* @scan_for_escape.got_newline
store i32 1, i32* %3
br label %67
49: ; preds = %40, %37
%50 = load i8*, i8** %5
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 13
br i1 %56, label %57, label %58
57: ; preds = %49
store i32 1, i32* @scan_for_escape.got_newline
store i32 0, i32* @scan_for_escape.got_escape
br label %59
58: ; preds = %49
store i32 0, i32* @scan_for_escape.got_escape
store i32 0, i32* @scan_for_escape.got_newline
br label %59
59: ; preds = %58, %57
br label %60
60: ; preds = %59
br label %61
61: ; preds = %60
br label %62
62: ; preds = %61, %22
br label %63
63: ; preds = %62
%64 = load i32, i32* %6
%65 = add nsw i32 %64, 1
store i32 %65, i32* %6
br label %7
66: ; preds = %7
store i32 0, i32* %3
br label %67
67: ; preds = %66, %48, %35
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@scan_for_escape.got_newline = internal unnamed_addr global i1 false
@scan_for_escape.got_escape = internal unnamed_addr global i1 false
define i32 @scan_for_escape(i32 %0, i8* nocapture %1) {
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %33
4: ; preds = %2
%5 = zext i32 %0 to i64
%6 = load i1, i1* @scan_for_escape.got_escape
br label %7
7: ; preds = %4, %29
%8 = phi i1 [ %6, %4 ], [ %30, %29 ]
%9 = phi i64 [ 0, %4 ], [ %31, %29 ]
br i1 %8, label %10, label %18
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %1, i64 %9
%12 = load i8, i8* %11
switch i8 %12, label %18 [
i8 46, label %13
i8 67, label %16
]
13: ; preds = %10
%14 = tail call i32 @done(i32 255, i32 1)
%15 = load i1, i1* @scan_for_escape.got_escape
br label %29
16: ; preds = %10
store i1 false, i1* @scan_for_escape.got_escape
store i1 false, i1* @scan_for_escape.got_newline
%17 = tail call i32 (...) @command_prompt()
br label %33
18: ; preds = %10, %7
%19 = load i1, i1* @scan_for_escape.got_newline
%20 = getelementptr inbounds i8, i8* %1, i64 %9
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 126
%23 = select i1 %19, i1 %22, i1 false
br i1 %23, label %24, label %25
24: ; preds = %18
store i1 true, i1* @scan_for_escape.got_escape
store i1 false, i1* @scan_for_escape.got_newline
br label %33
25: ; preds = %18
%26 = icmp eq i8 %21, 13
br i1 %26, label %27, label %28
27: ; preds = %25
store i1 true, i1* @scan_for_escape.got_newline
store i1 false, i1* @scan_for_escape.got_escape
br label %29
28: ; preds = %25
store i1 false, i1* @scan_for_escape.got_escape
store i1 false, i1* @scan_for_escape.got_newline
br label %29
29: ; preds = %13, %28, %27
%30 = phi i1 [ %15, %13 ], [ false, %28 ], [ false, %27 ]
%31 = add nuw nsw i64 %9, 1
%32 = icmp eq i64 %31, %5
br i1 %32, label %33, label %7
33: ; preds = %29, %2, %24, %16
%34 = phi i32 [ 1, %16 ], [ 1, %24 ], [ 0, %2 ], [ 0, %29 ]
ret i32 %34
}