#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 */
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
unsigned int strlen(char *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/);
scalar_t__ waitfor(char *);
int main(int argc, char **argv) {
  char c;
  unsigned int i;
  char *begin, *end, *buf;
  if (argc != 3) {
    fprintf(stderr, "skip begin end\n");
    exit(1);
  }
  begin = argv[1];
  end = argv[2];
  buf = (char *)malloc(sizeof(char) * (strlen(begin) > strlen(end)
                                           ? strlen(begin)
                                           : strlen(end)));
  if (buf == NULL) {
    fprintf(stderr, "error: no random access memory left, exiting.\n");
    exit(2);
  }
  while (1) {
    if ((c = getchar()) == begin[0]) {
      for (i = 0; begin[i] == c && i <= strlen(begin); i++) {
        buf[i] = c;
        c = getchar();
      }
      ungetc(c, stdin);
      if (i == strlen(begin)) {
        if (waitfor(end))
          continue;
        else
          break;
      } else {
        buf[i] = '\0';
        printf("%s", buf);
        continue;
      }
    }
    if (feof(stdin))
      break;
    else
      putchar(c);
  }
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11ef <main+0x3f>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jbe    123a <main+0x8a>
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
jmp    1246 <main+0x96>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1284 <main+0xd4>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
jmp    1289 <main+0xd9>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
movsbl %al,%eax
mov    -0x20(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1386 <main+0x1d6>
movl   $0x0,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%ecx
movsbl (%rax,%rcx,1),%ecx
movsbl -0x11(%rbp),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x39(%rbp)
jne    12e4 <main+0x134>
mov    -0x18(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
setbe  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
test   $0x1,%al
jne    12f4 <main+0x144>
jmp    1319 <main+0x169>
mov    -0x11(%rbp),%dl
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    $0x0,%al
call   1070 <getchar@plt>
mov    %al,-0x11(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12ac <main+0xfc>
mov    -0x11(%rbp),%al
mov    0x2cc5(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   10b0 <ungetc@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
cmp    %ecx,%eax
jne    1366 <main+0x1b6>
mov    -0x28(%rbp),%rdi
call   10c0 <waitfor@plt>
cmp    $0x0,%rax
je     1361 <main+0x1b1>
jmp    1289 <main+0xd9>
jmp    13b1 <main+0x201>
mov    -0x30(%rbp),%rax
mov    -0x18(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rsi
lea    0xcc3(%rip),%rdi
call   1060 <printf@plt>
jmp    1289 <main+0xd9>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
call   1090 <feof@plt>
cmp    $0x0,%rax
je     13a3 <main+0x1f3>
jmp    13b1 <main+0x201>
movsbl -0x11(%rbp),%edi
call   1040 <putchar@plt>
jmp    1289 <main+0xd9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    12c0 <main+0x110>
mov    0x8(%rsi),%r13
mov    0x10(%rsi),%r14
mov    %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
mov    %r14,%rdi
cmova  %r13,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12df <main+0x12f>
mov    %rax,%r15
mov    0x2de2(%rip),%rbp
jmp    1227 <main+0x77>
nopl   0x0(%rax,%rax,1)
mov    %r12d,%eax
movb   $0x0,(%r15,%rax,1)
lea    0xe20(%rip),%rdi
mov    %r15,%rsi
call   1060 <printf@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
cmp    0x0(%r13),%al
jne    1290 <main+0xe0>
xor    %r12d,%r12d
nopl   0x0(%rax)
mov    %r13,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r12d
ja     1265 <main+0xb5>
mov    %bl,(%r15,%r12,1)
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %eax,%ebx
add    $0x1,%r12d
cmp    %al,0x0(%r13,%r12,1)
je     1240 <main+0x90>
mov    0x0(%rbp),%esi
movsbl %bl,%edi
call   10b0 <ungetc@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
cmp    %eax,%r12d
jne    1210 <main+0x60>
mov    %r14,%rdi
call   10c0 <waitfor@plt>
test   %rax,%rax
jne    1227 <main+0x77>
jmp    12a7 <main+0xf7>
nopl   0x0(%rax)
mov    0x0(%rbp),%edi
call   1090 <feof@plt>
test   %rax,%rax
jne    12a7 <main+0xf7>
movsbl %bl,%edi
call   1040 <putchar@plt>
jmp    1227 <main+0x77>
mov    %r15,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd30(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd21(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"skip begin end\0A\00"
@.str.1 = [47 x i8] c"error: no random access memory left, exiting.\0A\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
store i8* %20, i8** %8
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 2
%23 = load i8*, i8** %22
store i8* %23, i8** %9
%24 = load i8*, i8** %8
%25 = call i32 @strlen(i8* %24)
%26 = load i8*, i8** %9
%27 = call i32 @strlen(i8* %26)
%28 = icmp ugt i32 %25, %27
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = load i8*, i8** %8
%31 = call i32 @strlen(i8* %30)
br label %35
32: ; preds = %17
%33 = load i8*, i8** %9
%34 = call i32 @strlen(i8* %33)
br label %35
35: ; preds = %32, %29
%36 = phi i32 [ %31, %29 ], [ %34, %32 ]
%37 = zext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i64 @malloc(i32 %39)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %10
%42 = load i8*, i8** %10
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %48
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 2)
unreachable
48: ; preds = %35
br label %49
49: ; preds = %48, %97, %99, %114
%50 = call signext i8 (...) @getchar()
store i8 %50, i8* %6
%51 = sext i8 %50 to i32
%52 = load i8*, i8** %8
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %51, %55
br i1 %56, label %57, label %106
57: ; preds = %49
store i32 0, i32* %7
br label %58
58: ; preds = %82, %57
%59 = load i8*, i8** %8
%60 = load i32, i32* %7
%61 = zext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %59, i64 %61
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = load i8, i8* %6
%66 = sext i8 %65 to i32
%67 = icmp eq i32 %64, %66
br i1 %67, label %68, label %73
68: ; preds = %58
%69 = load i32, i32* %7
%70 = load i8*, i8** %8
%71 = call i32 @strlen(i8* %70)
%72 = icmp ule i32 %69, %71
br label %73
73: ; preds = %68, %58
%74 = phi i1 [ false, %58 ], [ %72, %68 ]
br i1 %74, label %75, label %85
75: ; preds = %73
%76 = load i8, i8* %6
%77 = load i8*, i8** %10
%78 = load i32, i32* %7
%79 = zext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
store i8 %76, i8* %80
%81 = call signext i8 (...) @getchar()
store i8 %81, i8* %6
br label %82
82: ; preds = %75
%83 = load i32, i32* %7
%84 = add i32 %83, 1
store i32 %84, i32* %7
br label %58
85: ; preds = %73
%86 = load i8, i8* %6
%87 = load i32, i32* @stdin
%88 = call i32 @ungetc(i8 signext %86, i32 %87)
%89 = load i32, i32* %7
%90 = load i8*, i8** %8
%91 = call i32 @strlen(i8* %90)
%92 = icmp eq i32 %89, %91
br i1 %92, label %93, label %99
93: ; preds = %85
%94 = load i8*, i8** %9
%95 = call i64 @waitfor(i8* %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %98
97: ; preds = %93
br label %49
98: ; preds = %93
br label %115
99: ; preds = %85
%100 = load i8*, i8** %10
%101 = load i32, i32* %7
%102 = zext i32 %101 to i64
%103 = getelementptr inbounds i8, i8* %100, i64 %102
store i8 0, i8* %103
%104 = load i8*, i8** %10
%105 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %104)
br label %49
106: ; preds = %49
%107 = load i32, i32* @stdin
%108 = call i64 @feof(i32 %107)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %106
br label %115
111: ; preds = %106
%112 = load i8, i8* %6
%113 = call i32 @putchar(i8 signext %112)
br label %114
114: ; preds = %111
br label %49
115: ; preds = %110, %98
%116 = load i8*, i8** %10
%117 = call i32 @free(i8* %116)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"skip begin end\0A\00"
@.str.1 = [47 x i8] c"error: no random access memory left, exiting.\0A\00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = tail call i32 @strlen(i8* %10)
%14 = tail call i32 @strlen(i8* %12)
%15 = icmp ugt i32 %13, %14
%16 = select i1 %15, i8* %10, i8* %12
%17 = tail call i32 @strlen(i8* %16)
%18 = tail call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
%20 = icmp eq i64 %18, 0
br i1 %20, label %21, label %25
21: ; preds = %8
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0))
%24 = tail call i32 @exit(i32 2)
unreachable
25: ; preds = %8, %57
%26 = tail call signext i8 (...) @getchar()
%27 = load i8, i8* %10
%28 = icmp eq i8 %26, %27
br i1 %28, label %29, label %58
29: ; preds = %25, %35
%30 = phi i64 [ %39, %35 ], [ 0, %25 ]
%31 = phi i8 [ %37, %35 ], [ %26, %25 ]
%32 = phi i32 [ %38, %35 ], [ 0, %25 ]
%33 = tail call i32 @strlen(i8* %10)
%34 = icmp ugt i32 %32, %33
br i1 %34, label %43, label %35
35: ; preds = %29
%36 = getelementptr inbounds i8, i8* %19, i64 %30
store i8 %31, i8* %36
%37 = tail call signext i8 (...) @getchar()
%38 = add i32 %32, 1
%39 = zext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %10, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, %37
br i1 %42, label %29, label %43
43: ; preds = %29, %35
%44 = phi i32 [ %32, %29 ], [ %38, %35 ]
%45 = phi i8 [ %31, %29 ], [ %37, %35 ]
%46 = load i32, i32* @stdin
%47 = tail call i32 @ungetc(i8 signext %45, i32 %46)
%48 = tail call i32 @strlen(i8* %10)
%49 = icmp eq i32 %44, %48
br i1 %49, label %50, label %53
50: ; preds = %43
%51 = tail call i64 @waitfor(i8* %12)
%52 = icmp eq i64 %51, 0
br i1 %52, label %64, label %57
53: ; preds = %43
%54 = zext i32 %44 to i64
%55 = getelementptr inbounds i8, i8* %19, i64 %54
store i8 0, i8* %55
%56 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %57
57: ; preds = %53, %62, %50
br label %25
58: ; preds = %25
%59 = load i32, i32* @stdin
%60 = tail call i64 @feof(i32 %59)
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = tail call i32 @putchar(i8 signext %26)
br label %57
64: ; preds = %58, %50
%65 = tail call i32 @free(i8* %19)
ret i32 0
}