#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 /*<<< orphan*/ atof(char *);
int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
char *julian_display_yyyy_mm_dd(int /*<<< orphan*/);
int /*<<< orphan*/ piece(char *, char, char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *replace_piece(char *, char, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  int piece_offset;
  char input_buffer[1024];
  char piece_buffer[128];
  char date_string[64];
  if (argc != 2) {
    fprintf(stderr, "Usage: %s piece_offset\n", argv[0]);
    exit(1);
  }
  piece_offset = atoi(argv[1]);
  while (get_line(input_buffer, stdin)) {
    if (!piece(piece_buffer, '|', input_buffer, piece_offset)) {
      printf("%s\n", input_buffer);
      continue;
    }
    sprintf(date_string, "%s", julian_display_yyyy_mm_dd(atof(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    $0x4f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e9 <main+0x49>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
call   1070 <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)
lea    -0x420(%rbp),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1040 <get_line@plt>
cmp    $0x0,%rax
je     12ba <main+0x11a>
lea    -0x4a0(%rbp),%rdi
lea    -0x420(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x7c,%esi
call   10b0 <piece@plt>
cmp    $0x0,%eax
jne    1254 <main+0xb4>
lea    -0x420(%rbp),%rsi
lea    0xdce(%rip),%rdi
call   1050 <printf@plt>
jmp    11f9 <main+0x59>
lea    -0x4e0(%rbp),%rax
mov    %rax,-0x4e8(%rbp)
lea    -0x4a0(%rbp),%rdi
call   1030 <atof@plt>
mov    %eax,%edi
call   1060 <julian_display_yyyy_mm_dd@plt>
mov    -0x4e8(%rbp),%rdi
mov    %rax,%rdx
lea    0xd96(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x4e0(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x7c,%esi
call   10c0 <replace_piece@plt>
mov    %rax,%rsi
lea    0xd68(%rip),%rdi
call   1050 <printf@plt>
jmp    11f9 <main+0x59>
xor    %eax,%eax
add    $0x4f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4c8,%rsp
cmp    $0x2,%edi
jne    127a <main+0xda>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    0x2e1c(%rip),%r13
mov    0x0(%r13),%esi
lea    0xc0(%rsp),%rdi
call   1050 <get_line@plt>
test   %rax,%rax
je     1266 <main+0xc6>
lea    0x40(%rsp),%r14
lea    0xc0(%rsp),%rbx
lea    0xe1e(%rip),%r15
mov    %rsp,%r12
jmp    121c <main+0x7c>
nop
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1050 <get_line@plt>
test   %rax,%rax
je     1266 <main+0xc6>
mov    %r14,%rdi
mov    $0x7c,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   10b0 <piece@plt>
test   %eax,%eax
je     1200 <main+0x60>
mov    %r14,%rdi
call   1040 <atof@plt>
mov    %eax,%edi
call   1070 <julian_display_yyyy_mm_dd@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x7c,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
call   10c0 <replace_piece@plt>
mov    %r15,%rdi
mov    %rax,%rsi
jmp    1206 <main+0x66>
xor    %eax,%eax
add    $0x4c8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd73(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s piece_offset\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [128 x i8]
%9 = alloca [64 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %6
br label %24
24: ; preds = %38, %35, %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* @stdin
%27 = call i64 @get_line(i8* %25, i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %49
29: ; preds = %24
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = load i32, i32* %6
%33 = call i32 @piece(i8* %30, i8 signext 124, i8* %31, i32 %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %36)
br label %24
38: ; preds = %29
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%41 = call i32 @atof(i8* %40)
%42 = call i8* @julian_display_yyyy_mm_dd(i32 %41)
%43 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%45 = getelementptr inbounds [64 x i8], [64 x i8]* %9, i64 0, i64 0
%46 = load i32, i32* %6
%47 = call i8* @replace_piece(i8* %44, i8 signext 124, i8* %45, i32 %46)
%48 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %47)
br label %24
49: ; preds = %24
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s piece_offset\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [128 x i8]
%5 = alloca [64 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %5, i64 0, i64 0
%9 = icmp eq i32 %0, 2
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 ([24 x i8], [24 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 = tail call i32 @atoi(i8* %17)
%19 = load i32, i32* @stdin
%20 = call i64 @get_line(i8* %6, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %37, label %22
22: ; preds = %15, %27
%23 = call i32 @piece(i8* %7, i8 signext 124, i8* %6, i32 %18)
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %27
27: ; preds = %25, %31
%28 = load i32, i32* @stdin
%29 = call i64 @get_line(i8* %6, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %37, label %22
31: ; preds = %22
%32 = call i32 @atof(i8* %7)
%33 = call i8* @julian_display_yyyy_mm_dd(i32 %32)
%34 = call i8* @strcpy(i8* %8, i8* dereferenceable(1) %33)
%35 = call i8* @replace_piece(i8* %6, i8 signext 124, i8* %8, i32 %18)
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %27
37: ; preds = %27, %15
ret i32 0
}