#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*/ printf(char *, char *);
char *replace_piece(char *, char, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
char *timlib_ora_date_to_yyyy_mm_dd(char *);
char *timlib_yyyy_mm_dd_to_julian(char *);
int main(int argc, char **argv) {
  int piece_offset;
  char *format_mask;
  char input_buffer[1024];
  char piece_buffer[128];
  char *date_string;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s piece_offset [yyyy_mm_dd]\n", argv[0]);
    exit(1);
  }
  piece_offset = atoi(argv[1]);
  if (argc == 3)
    format_mask = argv[2];
  else
    format_mask = "yyyy_mm_dd";
  while (get_line(input_buffer, stdin)) {
    if (!piece(piece_buffer, '|', input_buffer, piece_offset)) {
      printf("%s\n", input_buffer);
      continue;
    }
    if (strcmp(format_mask, "yyyy_mm_dd") == 0) {
      date_string = timlib_ora_date_to_yyyy_mm_dd(piece_buffer);
    } else if (strcmp(format_mask, "julian") == 0) {
      date_string = timlib_yyyy_mm_dd_to_julian(
          timlib_ora_date_to_yyyy_mm_dd(piece_buffer));
    } else {
      date_string = piece_buffer;
    }
    printf("%s\n", replace_piece(input_buffer, '|', date_string, piece_offset));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e9 <main+0x49>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1214 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    121f <main+0x7f>
lea    0xe0a(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1224 <main+0x84>
lea    -0x420(%rbp),%rdi
mov    0x2db6(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     132d <main+0x18d>
lea    -0x4a0(%rbp),%rdi
lea    -0x420(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x7c,%esi
call   10b0 <piece@plt>
cmp    $0x0,%eax
jne    127f <main+0xdf>
lea    -0x420(%rbp),%rsi
lea    0xdbb(%rip),%rdi
call   1040 <printf@plt>
jmp    1224 <main+0x84>
mov    -0x20(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12b1 <main+0x111>
lea    -0x4a0(%rbp),%rdi
call   1070 <timlib_ora_date_to_yyyy_mm_dd@plt>
mov    %rax,-0x4a8(%rbp)
jmp    12fe <main+0x15e>
mov    -0x20(%rbp),%rdi
lea    0xd78(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    12eb <main+0x14b>
lea    -0x4a0(%rbp),%rdi
call   1070 <timlib_ora_date_to_yyyy_mm_dd@plt>
mov    %rax,%rdi
call   1090 <timlib_yyyy_mm_dd_to_julian@plt>
mov    %rax,-0x4a8(%rbp)
jmp    12f9 <main+0x159>
lea    -0x4a0(%rbp),%rax
mov    %rax,-0x4a8(%rbp)
jmp    12fe <main+0x15e>
lea    -0x420(%rbp),%rdi
mov    -0x4a8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x7c,%esi
call   10c0 <replace_piece@plt>
mov    %rax,%rsi
lea    0xd0d(%rip),%rdi
call   1040 <printf@plt>
jmp    1224 <main+0x84>
xor    %eax,%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x488,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jle    12c9 <main+0x129>
mov    %edi,%ebx
mov    0x8(%r14),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
cmp    $0x3,%ebx
jne    11d5 <main+0x35>
mov    0x10(%r14),%r14
jmp    11dc <main+0x3c>
lea    0xe49(%rip),%r14
mov    0x2e05(%rip),%r13
mov    0x0(%r13),%esi
lea    0x80(%rsp),%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     12b5 <main+0x115>
mov    %rsp,%r15
lea    0x80(%rsp),%rbx
lea    0xe21(%rip),%r12
jmp    123c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     12b5 <main+0x115>
mov    %r15,%rdi
mov    $0x7c,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   10b0 <piece@plt>
test   %eax,%eax
je     1220 <main+0x80>
mov    %r14,%rdi
lea    0xdc9(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1290 <main+0xf0>
mov    %r14,%rdi
lea    0xdc4(%rip),%rsi
call   1050 <strcmp@plt>
mov    %r15,%rdx
test   %rax,%rax
jne    129b <main+0xfb>
mov    %r15,%rdi
call   1070 <timlib_ora_date_to_yyyy_mm_dd@plt>
mov    %rax,%rdi
call   1090 <timlib_yyyy_mm_dd_to_julian@plt>
jmp    1298 <main+0xf8>
nop
mov    %r15,%rdi
call   1070 <timlib_ora_date_to_yyyy_mm_dd@plt>
mov    %rax,%rdx
mov    %rbx,%rdi
mov    $0x7c,%esi
mov    %ebp,%ecx
call   10c0 <replace_piece@plt>
mov    %r12,%rdi
mov    %rax,%rsi
jmp    1226 <main+0x86>
xor    %eax,%eax
add    $0x488,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xd24(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s piece_offset [yyyy_mm_dd]\0A\00"
@.str.1 = [11 x i8] c"yyyy_mm_dd\00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [7 x i8] c"julian\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [128 x 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 slt i32 %11, 2
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 @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, 3
br i1 %26, label %27, label %31
27: ; preds = %20
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
store i8* %30, i8** %7
br label %32
31: ; preds = %20
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %32
32: ; preds = %31, %27
br label %33
33: ; preds = %65, %44, %32
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, 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 %71
38: ; preds = %33
%39 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%41 = load i32, i32* %6
%42 = call i32 @piece(i8* %39, i8 signext 124, i8* %40, i32 %41)
%43 = icmp ne i32 %42, 0
br i1 %43, label %47, label %44
44: ; preds = %38
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %33
47: ; preds = %38
%48 = load i8*, i8** %7
%49 = call i64 @strcmp(i8* %48, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%53 = call i8* @timlib_ora_date_to_yyyy_mm_dd(i8* %52)
store i8* %53, i8** %10
br label %65
54: ; preds = %47
%55 = load i8*, i8** %7
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %54
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%60 = call i8* @timlib_ora_date_to_yyyy_mm_dd(i8* %59)
%61 = call i8* @timlib_yyyy_mm_dd_to_julian(i8* %60)
store i8* %61, i8** %10
br label %64
62: ; preds = %54
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
store i8* %63, i8** %10
br label %64
64: ; preds = %62, %58
br label %65
65: ; preds = %64, %51
%66 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%67 = load i8*, i8** %10
%68 = load i32, i32* %6
%69 = call i8* @replace_piece(i8* %66, i8 signext 124, i8* %67, i32 %68)
%70 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %69)
br label %33
71: ; preds = %33
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Usage: %s piece_offset [yyyy_mm_dd]\0A\00"
@.str.1 = [11 x i8] c"yyyy_mm_dd\00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [7 x i8] c"julian\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 @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, 3
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
br label %21
21: ; preds = %13, %18
%22 = phi i8* [ %20, %18 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %13 ]
%23 = load i32, i32* @stdin
%24 = call i64 @get_line(i8* %5, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %50, label %26
26: ; preds = %21, %31
%27 = call i32 @piece(i8* %6, i8 signext 124, i8* %5, i32 %16)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %35
29: ; preds = %26
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %31
31: ; preds = %29, %46
%32 = load i32, i32* @stdin
%33 = call i64 @get_line(i8* %5, i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %50, label %26
35: ; preds = %26
%36 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = call i8* @timlib_ora_date_to_yyyy_mm_dd(i8* %6)
br label %46
40: ; preds = %35
%41 = call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i8* @timlib_ora_date_to_yyyy_mm_dd(i8* %6)
%45 = call i8* @timlib_yyyy_mm_dd_to_julian(i8* %44)
br label %46
46: ; preds = %40, %43, %38
%47 = phi i8* [ %39, %38 ], [ %45, %43 ], [ %6, %40 ]
%48 = call i8* @replace_piece(i8* %5, i8 signext 124, i8* %47, i32 %16)
%49 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %31
50: ; preds = %31, %21
ret i32 0
}