#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 /*<<< orphan*/ piece(char *, char, char *, int);
char *piece_replace(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ trim_length(char *, int);
int main(int argc, char **argv) {
  int length;
  char buffer[65536];
  char component[65536];
  char delimiter = ':';
  int offset = 0;
  if (argc == 1) {
    fprintf(stderr, "Usage: %s length [delimiter offset]\n", argv[0]);
    exit(1);
  }
  length = atoi(argv[1]);
  if (argc == 4) {
    delimiter = *argv[2];
    offset = atoi(argv[3]);
  }
  while (get_line(buffer, stdin)) {
    if (!piece(component, delimiter, buffer, offset)) {
      fprintf(stderr,
              "Warning %s: There are less than %d delimiters (%c) in: (%s)\n",
              argv[0], offset, delimiter, buffer);
    }
    trim_length(component, length);
    printf("%s\n", piece_replace(buffer, delimiter, component, offset));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x3a,-0x20021(%rbp)
movl   $0x0,-0x20028(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11dc <main+0x5c>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1219 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x20021(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x20028(%rbp)
jmp    121e <main+0x9e>
lea    -0x10020(%rbp),%rdi
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     12e0 <main+0x160>
lea    -0x20020(%rbp),%rdi
mov    -0x20021(%rbp),%al
lea    -0x10020(%rbp),%rdx
mov    -0x20028(%rbp),%ecx
movsbl %al,%esi
call   1090 <piece@plt>
cmp    $0x0,%eax
jne    129b <main+0x11b>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20028(%rbp),%ecx
movsbl -0x20021(%rbp),%r8d
ff
lea    -0x10020(%rbp),%r9
lea    0xd91(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    -0x20020(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10a0 <trim_length@plt>
lea    -0x10020(%rbp),%rdi
mov    -0x20021(%rbp),%al
lea    -0x20020(%rbp),%rdx
mov    -0x20028(%rbp),%ecx
movsbl %al,%esi
call   1060 <piece_replace@plt>
mov    %rax,%rsi
lea    0xd8c(%rip),%rdi
call   1040 <printf@plt>
jmp    121e <main+0x9e>
xor    %eax,%eax
add    $0x20030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20018,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
je     129b <main+0x11b>
mov    %edi,%ebx
mov    0x8(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%r15d
cmp    $0x4,%ebx
mov    %rbp,0x8(%rsp)
jne    11c9 <main+0x49>
mov    0x10(%rbp),%rax
mov    0x18(%rbp),%rdi
mov    (%rax),%bpl
call   1070 <atoi@plt>
mov    %eax,%ebx
jmp    11ce <main+0x4e>
xor    %ebx,%ebx
mov    $0x3a,%bpl
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1287 <main+0x107>
movsbl %bpl,%ebp
lea    0x10010(%rsp),%r12
lea    0x10(%rsp),%r13
lea    0xe60(%rip),%r14
jmp    124b <main+0xcb>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12,%rdi
mov    %r15d,%esi
call   10a0 <trim_length@plt>
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1060 <piece_replace@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    %r13,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     1287 <main+0x107>
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r13,%rdx
mov    %ebx,%ecx
call   1090 <piece@plt>
test   %eax,%eax
jne    1210 <main+0x90>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0xdaf(%rip),%rsi
mov    %ebx,%ecx
mov    %ebp,%r8d
mov    %r13,%r9
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1210 <main+0x90>
xor    %eax,%eax
add    $0x20018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xd51(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s length [delimiter offset]\0A\00"
@stdin = global i32 0
@.str.1 = [61 x i8] c"Warning %s: There are less than %d delimiters (%c) in: (%s)\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [65536 x i8]
%8 = alloca [65536 x i8]
%9 = alloca i8
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8 58, i8* %9
store i32 0, i32* %10
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %4
%26 = icmp eq i32 %25, 4
br i1 %26, label %27, label %36
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = load i8, i8* %30
store i8 %31, i8* %9
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 3
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
store i32 %35, i32* %10
br label %36
36: ; preds = %27, %20
br label %37
37: ; preds = %59, %36
%38 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%39 = load i32, i32* @stdin
%40 = call i64 @get_line(i8* %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %69
42: ; preds = %37
%43 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%44 = load i8, i8* %9
%45 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%46 = load i32, i32* %10
%47 = call i32 @piece(i8* %43, i8 signext %44, i8* %45, i32 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %59, label %49
49: ; preds = %42
%50 = load i32, i32* @stderr
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 0
%53 = load i8*, i8** %52
%54 = load i32, i32* %10
%55 = load i8, i8* %9
%56 = sext i8 %55 to i32
%57 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%58 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %53, i32 %54, i32 %56, i8* %57)
br label %59
59: ; preds = %49, %42
%60 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%61 = load i32, i32* %6
%62 = call i32 @trim_length(i8* %60, i32 %61)
%63 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%64 = load i8, i8* %9
%65 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%66 = load i32, i32* %10
%67 = call i8* @piece_replace(i8* %63, i8 signext %64, i8* %65, i32 %66)
%68 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %67)
br label %37
69: ; preds = %37
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s length [delimiter offset]\0A\00"
@stdin = global i32 0
@.str.1 = [61 x i8] c"Warning %s: There are less than %d delimiters (%c) in: (%s)\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = alloca [65536 x i8]
%5 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32 %0, 1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = icmp eq i32 %0, 4
br i1 %17, label %18, label %25
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = load i8, i8* %20
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
br label %25
25: ; preds = %18, %13
%26 = phi i8 [ %21, %18 ], [ 58, %13 ]
%27 = phi i32 [ %24, %18 ], [ 0, %13 ]
%28 = load i32, i32* @stdin
%29 = call i64 @get_line(i8* %5, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %47, label %31
31: ; preds = %25
%32 = sext i8 %26 to i32
br label %33
33: ; preds = %31, %40
%34 = call i32 @piece(i8* %6, i8 signext %26, i8* %5, i32 %27)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = load i8*, i8** %1
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.1, i64 0, i64 0), i8* %38, i32 %27, i32 %32, i8* %5)
br label %40
40: ; preds = %36, %33
%41 = call i32 @trim_length(i8* %6, i32 %16)
%42 = call i8* @piece_replace(i8* %5, i8 signext %26, i8* %6, i32 %27)
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @stdin
%45 = call i64 @get_line(i8* %5, i32 %44)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %33
47: ; preds = %40, %25
ret i32 0
}