#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 */
char *column_replace(char *, char *, int);
int instr_character(char, char *);
int /*<<< orphan*/ piece_delete(char *, char, int);
int /*<<< orphan*/ piece_insert(char *, char, char *, int);
char *piece_replace_quote_comma(char *, char *, char *, int);
int /*<<< orphan*/ timlib_strcpy(char *, char *, int);
char *piece_replace(char *source_destination, char delimiter, char *new_data,
                    int piece_offset) {
  if (delimiter == 1) {
    char source[1024];
    timlib_strcpy(source, source_destination, 1024);
    *source_destination = '\0';
    return piece_replace_quote_comma(source_destination, source, new_data,
                                     piece_offset);
  } else if (delimiter == 2 || delimiter == 9 || delimiter == 't') {
    return column_replace(source_destination, new_data, piece_offset);
  }
  if (instr_character(delimiter, source_destination) == -1) {
    *source_destination = '\0';
    delimiter = 0;
  } else {
    piece_delete(source_destination, delimiter, piece_offset);
  }
  piece_insert(source_destination, delimiter, new_data, piece_offset);
  return source_destination;
}


x86 assembly (clang, -O0):
<piece_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %sil,%al
mov    %rdi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x1,%eax
jne    11c5 <piece_replace+0x65>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x400,%edx
call   1040 <timlib_strcpy@plt>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1080 <piece_replace_quote_comma@plt>
mov    %rax,-0x8(%rbp)
jmp    1262 <piece_replace+0x102>
movsbl -0x11(%rbp),%eax
cmp    $0x2,%eax
je     11ec <piece_replace+0x8c>
movsbl -0x11(%rbp),%eax
cmp    $0x9,%eax
je     11ec <piece_replace+0x8c>
movsbl -0x11(%rbp),%eax
cmp    $0x74,%eax
jne    1205 <piece_replace+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <column_replace@plt>
mov    %rax,-0x8(%rbp)
jmp    1262 <piece_replace+0x102>
jmp    120a <piece_replace+0xaa>
mov    -0x11(%rbp),%al
mov    -0x10(%rbp),%rsi
movsbl %al,%edi
call   1050 <instr_character@plt>
cmp    $0xffffffff,%eax
jne    1232 <piece_replace+0xd2>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
movb   $0x0,-0x11(%rbp)
jmp    1244 <piece_replace+0xe4>
mov    -0x10(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x24(%rbp),%edx
movsbl %al,%esi
call   1030 <piece_delete@plt>
mov    -0x10(%rbp),%rdi
mov    -0x11(%rbp),%al
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
movsbl %al,%esi
call   1060 <piece_insert@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<piece_replace>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %ecx,%r15d
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
cmp    $0x8,%bpl
jg     118e <piece_replace+0x2e>
cmp    $0x1,%bpl
je     11b7 <piece_replace+0x57>
cmp    $0x2,%bpl
je     119a <piece_replace+0x3a>
jmp    11e3 <piece_replace+0x83>
cmp    $0x9,%bpl
je     119a <piece_replace+0x3a>
cmp    $0x74,%bpl
jne    11e3 <piece_replace+0x83>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <column_replace@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1040 <timlib_strcpy@plt>
movb   $0x0,(%rbx)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1080 <piece_replace_quote_comma@plt>
mov    %rax,%rbx
jmp    121e <piece_replace+0xbe>
movsbl %bpl,%r12d
mov    %r12d,%edi
mov    %rbx,%rsi
call   1050 <instr_character@plt>
cmp    $0xffffffff,%eax
je     1207 <piece_replace+0xa7>
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r15d,%edx
call   1030 <piece_delete@plt>
jmp    120c <piece_replace+0xac>
movb   $0x0,(%rbx)
xor    %ebp,%ebp
movsbl %bpl,%esi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r15d,%ecx
call   1060 <piece_insert@plt>
mov    %rbx,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @piece_replace(i8* %0, i8 signext %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [1024 x i8]
store i8* %0, i8** %6
store i8 %1, i8* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i8, i8* %7
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %24
14: ; preds = %4
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %6
%17 = call i32 @timlib_strcpy(i8* %15, i8* %16, i32 1024)
%18 = load i8*, i8** %6
store i8 0, i8* %18
%19 = load i8*, i8** %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %10, i64 0, i64 0
%21 = load i8*, i8** %8
%22 = load i32, i32* %9
%23 = call i8* @piece_replace_quote_comma(i8* %19, i8* %20, i8* %21, i32 %22)
store i8* %23, i8** %5
br label %61
24: ; preds = %4
%25 = load i8, i8* %7
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 2
br i1 %27, label %36, label %28
28: ; preds = %24
%29 = load i8, i8* %7
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 9
br i1 %31, label %36, label %32
32: ; preds = %28
%33 = load i8, i8* %7
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 116
br i1 %35, label %36, label %41
36: ; preds = %32, %28, %24
%37 = load i8*, i8** %6
%38 = load i8*, i8** %8
%39 = load i32, i32* %9
%40 = call i8* @column_replace(i8* %37, i8* %38, i32 %39)
store i8* %40, i8** %5
br label %61
41: ; preds = %32
br label %42
42: ; preds = %41
%43 = load i8, i8* %7
%44 = load i8*, i8** %6
%45 = call i32 @instr_character(i8 signext %43, i8* %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %49
47: ; preds = %42
%48 = load i8*, i8** %6
store i8 0, i8* %48
store i8 0, i8* %7
br label %54
49: ; preds = %42
%50 = load i8*, i8** %6
%51 = load i8, i8* %7
%52 = load i32, i32* %9
%53 = call i32 @piece_delete(i8* %50, i8 signext %51, i32 %52)
br label %54
54: ; preds = %49, %47
%55 = load i8*, i8** %6
%56 = load i8, i8* %7
%57 = load i8*, i8** %8
%58 = load i32, i32* %9
%59 = call i32 @piece_insert(i8* %55, i8 signext %56, i8* %57, i32 %58)
%60 = load i8*, i8** %6
store i8* %60, i8** %5
br label %61
61: ; preds = %54, %36, %14
%62 = load i8*, i8** %5
ret i8* %62
}

LLVM IR (-O2):
define i8* @piece_replace(i8* %0, i8 signext %1, i8* %2, i32 %3) {
%5 = alloca [1024 x i8]
switch i8 %1, label %12 [
i8 1, label %6
i8 116, label %10
i8 9, label %10
i8 2, label %10
]
6: ; preds = %4
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = call i32 @timlib_strcpy(i8* %7, i8* %0, i32 1024)
store i8 0, i8* %0
%9 = call i8* @piece_replace_quote_comma(i8* %0, i8* %7, i8* %2, i32 %3)
br label %21
10: ; preds = %4, %4, %4
%11 = tail call i8* @column_replace(i8* %0, i8* %2, i32 %3)
br label %21
12: ; preds = %4
%13 = tail call i32 @instr_character(i8 signext %1, i8* %0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %12
store i8 0, i8* %0
br label %18
16: ; preds = %12
%17 = tail call i32 @piece_delete(i8* %0, i8 signext %1, i32 %3)
br label %18
18: ; preds = %16, %15
%19 = phi i8 [ 0, %15 ], [ %1, %16 ]
%20 = tail call i32 @piece_insert(i8* %0, i8 signext %19, i8* %2, i32 %3)
br label %21
21: ; preds = %18, %10, %6
%22 = phi i8* [ %9, %6 ], [ %11, %10 ], [ %0, %18 ]
ret i8* %22
}