#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int piece_delimiter_position(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char **argv) {
  char buffer[4096];
  char delimiter;
  int offset_parent_ends;
  char parent_string[1024];
  char old_parent_string[1024];
  int position_child_begin;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s delimiter offset_parent_ends\n", argv[0]);
    exit(1);
  }
  delimiter = *argv[1];
  offset_parent_ends = atoi(argv[2]);
  *old_parent_string = '\0';
  while (get_line(buffer, stdin)) {
    if ((position_child_begin = piece_delimiter_position(
             buffer, delimiter, offset_parent_ends)) == -1) {
      printf(".ignored %s\n", buffer);
      continue;
    }
    if (!*old_parent_string) {
      strncpy(old_parent_string, buffer, position_child_begin);
      *(old_parent_string + position_child_begin) = '\0';
      printf(".parent %s\n", old_parent_string);
      printf(".child %s\n", buffer + position_child_begin + 1);
      continue;
    }
    strncpy(parent_string, buffer, position_child_begin);
    *(parent_string + position_child_begin) = '\0';
    if (strcmp(parent_string, old_parent_string) == 0) {
      printf(".child %s\n", buffer + position_child_begin + 1);
    } else {
      strcpy(old_parent_string, parent_string);
      printf(".end\n");
      printf(".parent %s\n", old_parent_string);
      printf(".child %s\n", buffer + position_child_begin + 1);
    }
  }
  printf(".end\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1830,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11d9 <main+0x49>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe36(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x1011(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1018(%rbp)
movb   $0x0,-0x1820(%rbp)
lea    -0x1010(%rbp),%rdi
mov    0x2dd7(%rip),%rax
mov    (%rax),%esi
call   1050 <get_line@plt>
cmp    $0x0,%rax
je     13a3 <main+0x213>
lea    -0x1010(%rbp),%rdi
mov    -0x1011(%rbp),%al
mov    -0x1018(%rbp),%edx
movsbl %al,%esi
call   1090 <piece_delimiter_position@plt>
mov    %eax,-0x1824(%rbp)
cmp    $0xffffffff,%eax
jne    1266 <main+0xd6>
lea    -0x1010(%rbp),%rsi
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1203 <main+0x73>
cmpb   $0x0,-0x1820(%rbp)
jne    12d8 <main+0x148>
lea    -0x1820(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    -0x1824(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x1824(%rbp),%rax
movb   $0x0,-0x1820(%rbp,%rax,1)
lea    -0x1820(%rbp),%rsi
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1010(%rbp),%rsi
movslq -0x1824(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
lea    0xd75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1203 <main+0x73>
lea    -0x1420(%rbp),%rdi
lea    -0x1010(%rbp),%rsi
mov    -0x1824(%rbp),%edx
call   1030 <strncpy@plt>
movslq -0x1824(%rbp),%rax
movb   $0x0,-0x1420(%rbp,%rax,1)
lea    -0x1420(%rbp),%rdi
lea    -0x1820(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1345 <main+0x1b5>
lea    -0x1010(%rbp),%rsi
movslq -0x1824(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    139e <main+0x20e>
lea    -0x1820(%rbp),%rdi
lea    -0x1420(%rbp),%rsi
call   1040 <strcpy@plt>
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1820(%rbp),%rsi
lea    0xcc1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1010(%rbp),%rsi
movslq -0x1824(%rbp),%rax
add    %rax,%rsi
add    $0x1,%rsi
lea    0xcaa(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1203 <main+0x73>
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1808,%rsp
cmp    $0x3,%edi
jne    12fa <main+0x15a>
mov    0x8(%rsi),%rax
mov    0x10(%rsi),%rdi
mov    (%rax),%bl
call   10b0 <atoi@plt>
mov    %eax,%r14d
movb   $0x0,(%rsp)
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
lea    0x800(%rsp),%rdi
call   1060 <get_line@plt>
test   %rax,%rax
je     12da <main+0x13a>
movsbl %bl,%ebp
lea    0x800(%rsp),%rbx
mov    %rsp,%r12
lea    0x400(%rsp),%r13
jmp    123b <main+0x9b>
nopw   0x0(%rax,%rax,1)
lea    0xe11(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <get_line@plt>
test   %rax,%rax
je     12da <main+0x13a>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   10a0 <piece_delimiter_position@plt>
cmp    $0xffffffff,%eax
je     1210 <main+0x70>
cmpb   $0x0,(%rsp)
movslq %eax,%r15
je     12a0 <main+0x100>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x400(%rsp,%r15,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     12c3 <main+0x123>
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
lea    0xdbe(%rip),%rdi
call   1050 <puts@plt>
jmp    12b2 <main+0x112>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%rsp,%r15,1)
lea    0xd7c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    (%rsp,%r15,1),%rsi
add    $0x801,%rsi
lea    0xd6c(%rip),%rdi
jmp    121a <main+0x7a>
lea    0xd6b(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x1808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xcf3(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s delimiter offset_parent_ends\0A\00"
@stdin = global i32 0
@.str.1 = [13 x i8] c".ignored %s\0A\00"
@.str.2 = [12 x i8] c".parent %s\0A\00"
@.str.3 = [11 x i8] c".child %s\0A\00"
@.str.4 = [6 x i8] c".end\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca [1024 x i8]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 3
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 ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
store i8 %25, i8* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
store i8 0, i8* %30
br label %31
31: ; preds = %99, %49, %42, %21
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%33 = load i32, i32* @stdin
%34 = call i64 @get_line(i8* %32, i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %100
36: ; preds = %31
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%38 = load i8, i8* %7
%39 = load i32, i32* %8
%40 = call i32 @piece_delimiter_position(i8* %37, i8 signext %38, i32 %39)
store i32 %40, i32* %11
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %31
45: ; preds = %36
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%47 = load i8, i8* %46
%48 = icmp ne i8 %47, 0
br i1 %48, label %66, label %49
49: ; preds = %45
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%52 = load i32, i32* %11
%53 = call i32 @strncpy(i8* %50, i8* %51, i32 %52)
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%55 = load i32, i32* %11
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 0, i8* %57
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %58)
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%61 = load i32, i32* %11
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %64)
br label %31
66: ; preds = %45
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%68 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%69 = load i32, i32* %11
%70 = call i32 @strncpy(i8* %67, i8* %68, i32 %69)
%71 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%72 = load i32, i32* %11
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
store i8 0, i8* %74
%75 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%76 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%77 = call i64 @strcmp(i8* %75, i8* %76)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %86
79: ; preds = %66
%80 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%81 = load i32, i32* %11
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = getelementptr inbounds i8, i8* %83, i64 1
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %84)
br label %99
86: ; preds = %66
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%89 = call i32 @strcpy(i8* %87, i8* %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%91 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %91)
%93 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%94 = load i32, i32* %11
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %93, i64 %95
%97 = getelementptr inbounds i8, i8* %96, i64 1
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %97)
br label %99
99: ; preds = %86, %79
br label %31
100: ; preds = %31
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s delimiter offset_parent_ends\0A\00"
@stdin = global i32 0
@.str.1 = [13 x i8] c".ignored %s\0A\00"
@.str.2 = [12 x i8] c".parent %s\0A\00"
@.str.3 = [11 x i8] c".child %s\0A\00"
@str.5 = [5 x i8] c".end\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = load i8, i8* %17
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
store i8 0, i8* %8
%22 = load i32, i32* @stdin
%23 = call i64 @get_line(i8* %6, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %62, label %25
25: ; preds = %15, %30
%26 = call i32 @piece_delimiter_position(i8* %6, i8 signext %18, i32 %21)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %30
30: ; preds = %51, %55, %28, %37
%31 = load i32, i32* @stdin
%32 = call i64 @get_line(i8* %6, i32 %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %62, label %25
34: ; preds = %25
%35 = load i8, i8* %8
%36 = icmp eq i8 %35, 0
br i1 %36, label %37, label %45
37: ; preds = %34
%38 = call i32 @strncpy(i8* %8, i8* %6, i32 %26)
%39 = sext i32 %26 to i64
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %39
store i8 0, i8* %40
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%42 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %39
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %30
45: ; preds = %34
%46 = call i32 @strncpy(i8* %7, i8* %6, i32 %26)
%47 = sext i32 %26 to i64
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %47
store i8 0, i8* %48
%49 = call i64 @strcmp(i8* %7, i8* %8)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %47
%53 = getelementptr inbounds i8, i8* %52, i64 1
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %30
55: ; preds = %45
%56 = call i32 @strcpy(i8* %8, i8* %7)
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %47
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8* %60)
br label %30
62: ; preds = %30, %15
%63 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
ret i32 0
}