void test_piece_delete(void) {
  char s[128];
  strcpy(s, "zero|one|two");
  printf(
      "%s(): piece_delete( \"zero|one|two\", 0 ) should be (one|two) is (%s)\n",
      __FUNCTION__, piece_delete(s, '|', 0));
  strcpy(s, "zero|one|two");
  printf("%s(): piece_delete( \"zero|one|two\", 1 ) should be (zero|two) is "
         "(%s)\n",
         __FUNCTION__, piece_delete(s, '|', 1));
  strcpy(s, "zero|one|two");
  printf("%s(): should be (zero|one) is (%s)\n", __FUNCTION__,
         piece_delete(s, '|', 2));
}


x86 assembly (clang, -O0):
<test_piece_delete>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x80(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
mov    $0x7c,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <piece_delete@plt>
mov    %eax,%edx
lea    0xea7(%rip),%rdi
lea    0xee5(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
mov    $0x7c,%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <piece_delete@plt>
mov    %eax,%edx
lea    0xec2(%rip),%rdi
lea    0xea9(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x80(%rbp),%rdi
mov    $0x7c,%esi
mov    $0x2,%edx
mov    $0x0,%al
call   1050 <piece_delete@plt>
mov    %eax,%edx
lea    0xecc(%rip),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_piece_delete>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
movabs $0x6f77747c656e6f,%r15
mov    %r15,0x5(%rsp)
movabs $0x656e6f7c6f72657a,%r12
6f 6e 65
mov    %r12,(%rsp)
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x7c,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <piece_delete@plt>
lea    0xea7(%rip),%rdi
lea    0xee5(%rip),%rbx
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,(%rsp)
mov    %r15,0x5(%rsp)
mov    %r14,%rdi
mov    $0x7c,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <piece_delete@plt>
lea    0xec7(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12,(%rsp)
mov    %r15,0x5(%rsp)
mov    %r14,%rdi
mov    $0x7c,%esi
mov    $0x2,%edx
xor    %eax,%eax
call   1040 <piece_delete@plt>
lea    0xedd(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"zero|one|two\00"
@.str.1 = [69 x i8] c"%s(): piece_delete( \22zero|one|two\22, 0 ) should be (one|two) is (%s)\0A\00"
@__FUNCTION__.test_piece_delete = [18 x i8] c"test_piece_delete\00"
@.str.2 = [70 x i8] c"%s(): piece_delete( \22zero|one|two\22, 1 ) should be (zero|two) is (%s)\0A\00"
@.str.3 = [36 x i8] c"%s(): should be (zero|one) is (%s)\0A\00"
define void @test_piece_delete() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i8* @strcpy(i8* %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @piece_delete to i32 (i8*, i32, i32, ...)*)(i8* %4, i32 124, i32 0)
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.test_piece_delete, i64 0, i64 0), i32 %5)
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%8 = call i8* @strcpy(i8* %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%10 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @piece_delete to i32 (i8*, i32, i32, ...)*)(i8* %9, i32 124, i32 1)
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.test_piece_delete, i64 0, i64 0), i32 %10)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%13 = call i8* @strcpy(i8* %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%15 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @piece_delete to i32 (i8*, i32, i32, ...)*)(i8* %14, i32 124, i32 2)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.test_piece_delete, i64 0, i64 0), i32 %15)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"zero|one|two\00"
@.str.1 = [69 x i8] c"%s(): piece_delete( \22zero|one|two\22, 0 ) should be (one|two) is (%s)\0A\00"
@__FUNCTION__.test_piece_delete = [18 x i8] c"test_piece_delete\00"
@.str.2 = [70 x i8] c"%s(): piece_delete( \22zero|one|two\22, 1 ) should be (zero|two) is (%s)\0A\00"
@.str.3 = [36 x i8] c"%s(): should be (zero|one) is (%s)\0A\00"
define void @test_piece_delete() {
%1 = alloca [128 x i8]
%2 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @piece_delete to i32 (i8*, i32, i32, ...)*)(i8* %2, i32 124, i32 0)
%4 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.test_piece_delete, i64 0, i64 0), i32 %3)
%5 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @piece_delete to i32 (i8*, i32, i32, ...)*)(i8* %2, i32 124, i32 1)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.test_piece_delete, i64 0, i64 0), i32 %5)
%7 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @piece_delete to i32 (i8*, i32, i32, ...)*)(i8* %2, i32 124, i32 2)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__FUNCTION__.test_piece_delete, i64 0, i64 0), i32 %7)
ret void
}