#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 */
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*/ stdin;
char *to_ora_date(char *, char *);
void piece_ora_date(int piece_offset, char *format_mask) {
  char input_buffer[1024];
  char piece_buffer[128];
  char *ora_date;
  while (get_line(input_buffer, stdin)) {
    if (!piece(piece_buffer, '|', input_buffer, piece_offset)) {
      printf("%s\n", input_buffer);
      continue;
    }
    ora_date = to_ora_date(piece_buffer, format_mask);
    printf("%s\n", replace_piece(input_buffer, '|', ora_date, piece_offset));
  }
}


x86 assembly (clang, -O0):
<piece_ora_date>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1203 <piece_ora_date+0xb3>
lea    -0x490(%rbp),%rdi
lea    -0x410(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    $0x7c,%esi
call   1060 <piece@plt>
cmp    $0x0,%eax
jne    11bd <piece_ora_date+0x6d>
lea    -0x410(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
jmp    1162 <piece_ora_date+0x12>
lea    -0x490(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <to_ora_date@plt>
mov    %rax,-0x498(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x498(%rbp),%rdx
mov    -0x4(%rbp),%ecx
mov    $0x7c,%esi
call   1070 <replace_piece@plt>
mov    %rax,%rsi
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
jmp    1162 <piece_ora_date+0x12>
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piece_ora_date>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x488,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e7b(%rip),%r13
mov    0x0(%r13),%esi
lea    0x80(%rsp),%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11f7 <piece_ora_date+0xa7>
mov    %rsp,%r15
lea    0x80(%rsp),%rbx
lea    0xe6b(%rip),%r12
jmp    11bc <piece_ora_date+0x6c>
nopw   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     11f7 <piece_ora_date+0xa7>
mov    %r15,%rdi
mov    $0x7c,%esi
mov    %rbx,%rdx
mov    %ebp,%ecx
call   1060 <piece@plt>
test   %eax,%eax
je     11a0 <piece_ora_date+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
call   1050 <to_ora_date@plt>
mov    %rbx,%rdi
mov    $0x7c,%esi
mov    %rax,%rdx
mov    %ebp,%ecx
call   1070 <replace_piece@plt>
mov    %r12,%rdi
mov    %rax,%rsi
jmp    11a6 <piece_ora_date+0x56>
add    $0x488,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @piece_ora_date(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [1024 x i8]
%6 = alloca [128 x i8]
%7 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
br label %8
8: ; preds = %22, %19, %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%10 = load i32, i32* @stdin
%11 = call i64 @get_line(i8* %9, i32 %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i32 @piece(i8* %14, i8 signext 124, i8* %15, i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %20)
br label %8
22: ; preds = %13
%23 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i8* @to_ora_date(i8* %23, i8* %24)
store i8* %25, i8** %7
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%27 = load i8*, i8** %7
%28 = load i32, i32* %3
%29 = call i8* @replace_piece(i8* %26, i8 signext 124, i8* %27, i32 %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %29)
br label %8
31: ; preds = %8
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
define void @piece_ora_date(i32 %0, i8* %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 = load i32, i32* @stdin
%8 = call i64 @get_line(i8* %5, i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %23, label %10
10: ; preds = %2, %15
%11 = call i32 @piece(i8* %6, i8 signext 124, i8* %5, i32 %0)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %15
15: ; preds = %13, %19
%16 = load i32, i32* @stdin
%17 = call i64 @get_line(i8* %5, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %10
19: ; preds = %10
%20 = call i8* @to_ora_date(i8* %6, i8* %1)
%21 = call i8* @replace_piece(i8* %5, i8 signext 124, i8* %20, i32 %0)
%22 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %15
23: ; preds = %15, %2
ret void
}