#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 do_gets(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  char buf[1024];
  char buf1[1024];
  char *tmp;
  int len, r = 0, r1 = 0;
  if (argc != 2) {
    fprintf(stderr, "Syntax: %s (name|data <boundary>)\n", argv[0]);
    exit(1);
  }
  while ((tmp = strchr(argv[1], '\r')))
    *tmp = 0;
  len = strlen(argv[1]);
  *buf = 0;
  while ((strncmp(buf, argv[1], len) != 0) &&
         (strncmp(buf + 2, argv[1], len) != 0)) {
    if (r > 0) {
      if (r1 > 0)
        write(1, buf1, r1);
      r1 = r;
      memcpy(buf1, buf, r);
    }
    if ((r = do_gets(buf)) <= 0)
      exit(1);
  }
  if (r1 > 2)
    write(1, buf1, r1 - 2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x820(%rbp)
movl   $0x0,-0x824(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11dd <main+0x5d>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe32(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11e2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
mov    %rax,-0x818(%rbp)
cmp    $0x0,%rax
je     1214 <main+0x94>
mov    -0x818(%rbp),%rax
movb   $0x0,(%rax)
jmp    11e2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x81c(%rbp)
movb   $0x0,-0x410(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x81c(%rbp),%edx
call   1030 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x825(%rbp)
je     1288 <main+0x108>
lea    -0x410(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x81c(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x825(%rbp)
mov    -0x825(%rbp),%al
test   $0x1,%al
jne    129b <main+0x11b>
jmp    131b <main+0x19b>
cmpl   $0x0,-0x820(%rbp)
jle    12f1 <main+0x171>
cmpl   $0x0,-0x824(%rbp)
jle    12cc <main+0x14c>
lea    -0x810(%rbp),%rsi
mov    -0x824(%rbp),%edx
mov    $0x1,%edi
call   1040 <write@plt>
mov    -0x820(%rbp),%eax
mov    %eax,-0x824(%rbp)
lea    -0x810(%rbp),%rdi
lea    -0x410(%rbp),%rsi
mov    -0x820(%rbp),%edx
call   1080 <memcpy@plt>
lea    -0x410(%rbp),%rdi
call   1090 <do_gets@plt>
mov    %eax,-0x820(%rbp)
cmp    $0x0,%eax
jg     1316 <main+0x196>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    122e <main+0xae>
cmpl   $0x2,-0x824(%rbp)
jle    1342 <main+0x1c2>
lea    -0x810(%rbp),%rsi
mov    -0x824(%rbp),%edx
sub    $0x2,%edx
mov    $0x1,%edi
call   1040 <write@plt>
xor    %eax,%eax
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1281 <main+0x101>
nopl   (%rax)
mov    0x8(%rbx),%rbp
mov    %rbp,%rdi
mov    $0xd,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     11bb <main+0x3b>
movb   $0x0,(%rax)
jmp    11a0 <main+0x20>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
movb   $0x0,(%rsp)
xor    %r12d,%r12d
mov    %rsp,%r15
lea    0x400(%rsp),%r13
xor    %r14d,%r14d
jmp    1200 <main+0x80>
nopl   0x0(%rax)
mov    %r13,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1080 <memcpy@plt>
mov    %r12d,%r14d
mov    %r15,%rdi
call   1090 <do_gets@plt>
mov    %eax,%r12d
test   %eax,%eax
jle    1277 <main+0xf7>
mov    0x8(%rbx),%rsi
mov    %r15,%rdi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1244 <main+0xc4>
mov    0x8(%rbx),%rsi
lea    0x2(%rsp),%rdi
mov    %ebp,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1244 <main+0xc4>
test   %r12d,%r12d
je     11f1 <main+0x71>
test   %r14d,%r14d
jle    11e0 <main+0x60>
mov    $0x1,%edi
mov    %r13,%rsi
mov    %r14d,%edx
call   1040 <write@plt>
jmp    11e0 <main+0x60>
cmp    $0x3,%r14d
jl     1263 <main+0xe3>
add    $0xfffffffe,%r14d
lea    0x400(%rsp),%rsi
mov    $0x1,%edi
mov    %r14d,%edx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd6c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [35 x i8] c"Syntax: %s (name|data <boundary>)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
br label %22
22: ; preds = %28, %21
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i8* @strchr(i8* %25, i8 signext 13)
store i8* %26, i8** %8
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i8*, i8** %8
store i8 0, i8* %29
br label %22
30: ; preds = %22
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
store i32 %34, i32* %9
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
store i8 0, i8* %35
br label %36
36: ; preds = %77, %30
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = load i32, i32* %9
%42 = call i64 @strncmp(i8* %37, i8* %40, i32 %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %53
44: ; preds = %36
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 2
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 1
%49 = load i8*, i8** %48
%50 = load i32, i32* %9
%51 = call i64 @strncmp(i8* %46, i8* %49, i32 %50)
%52 = icmp ne i64 %51, 0
br label %53
53: ; preds = %44, %36
%54 = phi i1 [ false, %36 ], [ %52, %44 ]
br i1 %54, label %55, label %78
55: ; preds = %53
%56 = load i32, i32* %10
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %71
58: ; preds = %55
%59 = load i32, i32* %11
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %58
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%63 = load i32, i32* %11
%64 = call i32 @write(i32 1, i8* %62, i32 %63)
br label %65
65: ; preds = %61, %58
%66 = load i32, i32* %10
store i32 %66, i32* %11
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%69 = load i32, i32* %10
%70 = call i32 @memcpy(i8* %67, i8* %68, i32 %69)
br label %71
71: ; preds = %65, %55
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%73 = call i32 @do_gets(i8* %72)
store i32 %73, i32* %10
%74 = icmp sle i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %71
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %71
br label %36
78: ; preds = %53
%79 = load i32, i32* %11
%80 = icmp sgt i32 %79, 2
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%83 = load i32, i32* %11
%84 = sub nsw i32 %83, 2
%85 = call i32 @write(i32 1, i8* %82, i32 %84)
br label %86
86: ; preds = %81, %78
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [35 x i8] c"Syntax: %s (name|data <boundary>)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i8* @strchr(i8* dereferenceable(1) %10, i8 signext 13)
%12 = icmp eq i8* %11, null
br i1 %12, label %23, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8, %18
%19 = phi i8* [ %21, %18 ], [ %11, %8 ]
store i8 0, i8* %19
%20 = load i8*, i8** %9
%21 = tail call i8* @strchr(i8* dereferenceable(1) %20, i8 signext 13)
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %18
23: ; preds = %18, %8
%24 = phi i8* [ %10, %8 ], [ %20, %18 ]
%25 = tail call i32 @strlen(i8* %24)
store i8 0, i8* %5
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 2
br label %27
27: ; preds = %45, %23
%28 = phi i32 [ 0, %23 ], [ %47, %45 ]
%29 = phi i32 [ 0, %23 ], [ %46, %45 ]
%30 = load i8*, i8** %9
%31 = call i64 @strncmp(i8* %5, i8* %30, i32 %25)
%32 = icmp eq i64 %31, 0
br i1 %32, label %51, label %33
33: ; preds = %27
%34 = load i8*, i8** %9
%35 = call i64 @strncmp(i8* %26, i8* %34, i32 %25)
%36 = icmp eq i64 %35, 0
br i1 %36, label %51, label %37
37: ; preds = %33
%38 = icmp eq i32 %28, 0
br i1 %38, label %45, label %39
39: ; preds = %37
%40 = icmp sgt i32 %29, 0
br i1 %40, label %41, label %43
41: ; preds = %39
%42 = call i32 @write(i32 1, i8* %6, i32 %29)
br label %43
43: ; preds = %41, %39
%44 = call i32 @memcpy(i8* %6, i8* %5, i32 %28)
br label %45
45: ; preds = %43, %37
%46 = phi i32 [ %28, %43 ], [ %29, %37 ]
%47 = call i32 @do_gets(i8* %5)
%48 = icmp slt i32 %47, 1
br i1 %48, label %49, label %27
49: ; preds = %45
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %27, %33
%52 = icmp sgt i32 %29, 2
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = add nsw i32 %29, -2
%55 = call i32 @write(i32 1, i8* %6, i32 %54)
br label %56
56: ; preds = %53, %51
ret i32 0
}