#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);
int /*<<< orphan*/ prepend_zeros_to_piece(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ replace_piece(char *, char, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char input_buffer[1024];
  char piece_buffer[1024];
  char delimiter;
  int piece_offset, field_size;
  if (argc != 4) {
    fprintf(stderr, "Usage: %s delimiter piece_offset field_size\n", argv[0]);
    exit(1);
  }
  delimiter = *argv[1];
  piece_offset = atoi(argv[2]);
  field_size = atoi(argv[3]);
  while (get_line(input_buffer, stdin)) {
    if (*input_buffer && *input_buffer != '#') {
      if (!piece(piece_buffer, delimiter, input_buffer, piece_offset)) {
        fprintf(stderr, "ERROR in %s: Cannot get piece(%d) from (%s)\n",
                argv[0], piece_offset, input_buffer);
        continue;
      }
      prepend_zeros_to_piece(piece_buffer, field_size);
      replace_piece(input_buffer, delimiter, piece_buffer, piece_offset);
    }
    printf("%s\n", input_buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11cb <main+0x4b>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%al
mov    %al,-0x811(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x818(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x81c(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     12e7 <main+0x167>
movsbl -0x410(%rbp),%eax
cmp    $0x0,%eax
je     12cf <main+0x14f>
movsbl -0x410(%rbp),%eax
cmp    $0x23,%eax
je     12cf <main+0x14f>
lea    -0x810(%rbp),%rdi
mov    -0x811(%rbp),%al
lea    -0x410(%rbp),%rdx
mov    -0x818(%rbp),%ecx
movsbl %al,%esi
call   1090 <piece@plt>
cmp    $0x0,%eax
jne    129b <main+0x11b>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x818(%rbp),%ecx
lea    -0x410(%rbp),%r8
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1201 <main+0x81>
lea    -0x810(%rbp),%rdi
mov    -0x81c(%rbp),%esi
call   1060 <prepend_zeros_to_piece@plt>
lea    -0x410(%rbp),%rdi
mov    -0x811(%rbp),%al
lea    -0x810(%rbp),%rdx
mov    -0x818(%rbp),%ecx
movsbl %al,%esi
call   10a0 <replace_piece@plt>
lea    -0x410(%rbp),%rsi
lea    0xd7d(%rip),%rdi
call   1040 <printf@plt>
jmp    1201 <main+0x81>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    1293 <main+0x113>
mov    0x8(%rbx),%rax
mov    0x10(%rbx),%rdi
mov    (%rax),%bpl
call   1070 <atoi@plt>
mov    %eax,%r13d
mov    %rbx,0x8(%rsp)
mov    0x18(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,0x4(%rsp)
mov    0x2e1f(%rip),%r15
mov    (%r15),%esi
lea    0x10(%rsp),%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     127f <main+0xff>
lea    0xe74(%rip),%r12
lea    0x10(%rsp),%rbx
movsbl %bpl,%ebp
lea    0x410(%rsp),%r14
jmp    1237 <main+0xb7>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    0x4(%rsp),%esi
call   1060 <prepend_zeros_to_piece@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
mov    %r13d,%ecx
call   10a0 <replace_piece@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    (%r15),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     127f <main+0xff>
movzbl 0x10(%rsp),%eax
test   %al,%al
je     121c <main+0x9c>
cmp    $0x23,%al
je     121c <main+0x9c>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r13d,%ecx
call   1090 <piece@plt>
test   %eax,%eax
jne    1200 <main+0x80>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0xdbd(%rip),%rsi
mov    %r13d,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1227 <main+0xa7>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d3e(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd5a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: %s delimiter piece_offset field_size\0A\00"
@stdin = global i32 0
@.str.1 = [45 x i8] c"ERROR in %s: Cannot get piece(%d) from (%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 [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8
%9 = alloca i32
%10 = alloca i32
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, 4
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 ([45 x i8], [45 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 = load i8, i8* %23
store i8 %24, i8* %8
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %9
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %10
br label %33
33: ; preds = %72, %55, %20
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%35 = load i32, i32* @stdin
%36 = call i64 @get_line(i8* %34, i32 %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %75
38: ; preds = %33
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %72
43: ; preds = %38
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp ne i32 %46, 35
br i1 %47, label %48, label %72
48: ; preds = %43
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%50 = load i8, i8* %8
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = load i32, i32* %9
%53 = call i32 @piece(i8* %49, i8 signext %50, i8* %51, i32 %52)
%54 = icmp ne i32 %53, 0
br i1 %54, label %63, label %55
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = load i32, i32* %9
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %59, i32 %60, i8* %61)
br label %33
63: ; preds = %48
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%65 = load i32, i32* %10
%66 = call i32 @prepend_zeros_to_piece(i8* %64, i32 %65)
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%68 = load i8, i8* %8
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%70 = load i32, i32* %9
%71 = call i32 @replace_piece(i8* %67, i8 signext %68, i8* %69, i32 %70)
br label %72
72: ; preds = %63, %43, %38
%73 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%74 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %73)
br label %33
75: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [45 x i8] c"Usage: %s delimiter piece_offset field_size\0A\00"
@stdin = global i32 0
@.str.1 = [45 x i8] c"ERROR in %s: Cannot get piece(%d) from (%s)\0A\00"
@.str.2 = [4 x i8] c"%s\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, 4
br i1 %7, label %13, label %8
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 ([45 x i8], [45 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 = load i8, i8* %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = load i32, i32* @stdin
%24 = call i64 @get_line(i8* %5, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %44, label %26
26: ; preds = %13, %35
%27 = load i8, i8* %5
switch i8 %27, label %28 [
i8 35, label %42
i8 0, label %42
]
28: ; preds = %26
%29 = call i32 @piece(i8* %6, i8 signext %16, i8* %5, i32 %19)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %1
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i8* %33, i32 %19, i8* %5)
br label %35
35: ; preds = %31, %42
%36 = load i32, i32* @stdin
%37 = call i64 @get_line(i8* %5, i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %44, label %26
39: ; preds = %28
%40 = call i32 @prepend_zeros_to_piece(i8* %6, i32 %22)
%41 = call i32 @replace_piece(i8* %5, i8 signext %16, i8* %6, i32 %19)
br label %42
42: ; preds = %26, %26, %39
%43 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %35
44: ; preds = %35, %13
ret i32 0
}