void test_str_sep(char *input, char sep) {
  int i;
  char **output = malloc(6 * sizeof(char *));
  for (i = 0; i < 6; i++) {
    output[i] = malloc(32);
    *output[i] = '\0';
  }
  unsigned long t1, t2;
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  old_str_sep(output, input, sep);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("old = (%5lu) |%s|%s|%s|%s|%s|%s|\n", t2 - t1, output[0], output[1],
         output[2], output[3], output[4], output[5]);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  new_str_sep(output, input, sep);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("new = (%5lu) |%s|%s|%s|%s|%s|%s|\n", t2 - t1, output[0], output[1],
         output[2], output[3], output[4], output[5]);
  asm volatile("rdtsc" : "=A"(t1) : :);
  ;
  asm_str_sep(output, input, sep);
  asm volatile("rdtsc" : "=A"(t2) : :);
  ;
  printf("asm = (%5lu) |%s|%s|%s|%s|%s|%s|\n", t2 - t1, output[0], output[1],
         output[2], output[3], output[4], output[5]);
  for (i = 0; i < 6; i++) {
    free(output[i]);
  }
  free(output);
}


x86 assembly (clang, -O0):
<test_str_sep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jge    11c7 <test_str_sep+0x67>
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1187 <test_str_sep+0x27>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsbl -0x9(%rbp),%edx
mov    $0x0,%al
call   1050 <old_str_sep@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r8
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r9
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%r10
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xddc(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsbl -0x9(%rbp),%edx
mov    $0x0,%al
call   1060 <new_str_sep@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r8
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r9
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%r10
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xd91(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
rdtsc
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movsbl -0x9(%rbp),%edx
mov    $0x0,%al
call   1080 <asm_str_sep@plt>
rdtsc
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%r8
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%r9
mov    -0x18(%rbp),%rax
mov    0x20(%rax),%r10
mov    -0x18(%rbp),%rax
mov    0x28(%rax),%rax
lea    0xd46(%rip),%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x6,-0x10(%rbp)
jge    133e <test_str_sep+0x1de>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1315 <test_str_sep+0x1b5>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_str_sep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    $0x30,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,(%rbx)
movb   $0x0,(%rax)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,0x8(%rbx)
movb   $0x0,(%rax)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,0x10(%rbx)
movb   $0x0,(%rax)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,0x18(%rbx)
movb   $0x0,(%rax)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,0x20(%rbx)
movb   $0x0,(%rax)
mov    $0x20,%edi
call   1070 <malloc@plt>
mov    %rax,0x28(%rbx)
movb   $0x0,(%rax)
rdtsc
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <old_str_sep@plt>
rdtsc
sub    %rbp,%rax
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
mov    0x18(%rbx),%r9
movups 0x20(%rbx),%xmm0
movups %xmm0,(%rsp)
lea    0xde6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
rdtsc
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <new_str_sep@plt>
rdtsc
sub    %rbp,%rax
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
mov    0x18(%rbx),%r9
movups 0x20(%rbx),%xmm0
movups %xmm0,(%rsp)
lea    0xdc6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
rdtsc
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1080 <asm_str_sep@plt>
rdtsc
sub    %rbp,%rax
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
mov    0x10(%rbx),%r8
mov    0x18(%rbx),%r9
movups 0x20(%rbx),%xmm0
movups %xmm0,(%rsp)
lea    0xda6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rdi
call   1030 <free@plt>
mov    0x8(%rbx),%rdi
call   1030 <free@plt>
mov    0x10(%rbx),%rdi
call   1030 <free@plt>
mov    0x18(%rbx),%rdi
call   1030 <free@plt>
mov    0x20(%rbx),%rdi
call   1030 <free@plt>
mov    0x28(%rbx),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [34 x i8] c"old = (%5lu) |%s|%s|%s|%s|%s|%s|\0A\00"
@.str.1 = [34 x i8] c"new = (%5lu) |%s|%s|%s|%s|%s|%s|\0A\00"
@.str.2 = [34 x i8] c"asm = (%5lu) |%s|%s|%s|%s|%s|%s|\0A\00"
define void @test_str_sep(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i8 %1, i8* %4
%9 = call i8* @malloc(i64 48)
%10 = bitcast i8* %9 to i8**
store i8** %10, i8*** %6
store i32 0, i32* %5
br label %11
11: ; preds = %25, %2
%12 = load i32, i32* %5
%13 = icmp slt i32 %12, 6
br i1 %13, label %14, label %28
14: ; preds = %11
%15 = call i8* @malloc(i64 32)
%16 = load i8**, i8*** %6
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8*, i8** %16, i64 %18
store i8* %15, i8** %19
%20 = load i8**, i8*** %6
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
%24 = load i8*, i8** %23
store i8 0, i8* %24
br label %25
25: ; preds = %14
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
br label %11
28: ; preds = %11
%29 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %29, i64* %7
%30 = load i8**, i8*** %6
%31 = load i8*, i8** %3
%32 = load i8, i8* %4
%33 = sext i8 %32 to i32
%34 = call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @old_str_sep to i32 (i8**, i8*, i32, ...)*)(i8** %30, i8* %31, i32 %33)
%35 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %35, i64* %8
%36 = load i64, i64* %8
%37 = load i64, i64* %7
%38 = sub i64 %36, %37
%39 = load i8**, i8*** %6
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %6
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %6
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %6
%49 = getelementptr inbounds i8*, i8** %48, i64 3
%50 = load i8*, i8** %49
%51 = load i8**, i8*** %6
%52 = getelementptr inbounds i8*, i8** %51, i64 4
%53 = load i8*, i8** %52
%54 = load i8**, i8*** %6
%55 = getelementptr inbounds i8*, i8** %54, i64 5
%56 = load i8*, i8** %55
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %38, i8* %41, i8* %44, i8* %47, i8* %50, i8* %53, i8* %56)
%58 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %58, i64* %7
%59 = load i8**, i8*** %6
%60 = load i8*, i8** %3
%61 = load i8, i8* %4
%62 = sext i8 %61 to i32
%63 = call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @new_str_sep to i32 (i8**, i8*, i32, ...)*)(i8** %59, i8* %60, i32 %62)
%64 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %64, i64* %8
%65 = load i64, i64* %8
%66 = load i64, i64* %7
%67 = sub i64 %65, %66
%68 = load i8**, i8*** %6
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = load i8**, i8*** %6
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = load i8**, i8*** %6
%75 = getelementptr inbounds i8*, i8** %74, i64 2
%76 = load i8*, i8** %75
%77 = load i8**, i8*** %6
%78 = getelementptr inbounds i8*, i8** %77, i64 3
%79 = load i8*, i8** %78
%80 = load i8**, i8*** %6
%81 = getelementptr inbounds i8*, i8** %80, i64 4
%82 = load i8*, i8** %81
%83 = load i8**, i8*** %6
%84 = getelementptr inbounds i8*, i8** %83, i64 5
%85 = load i8*, i8** %84
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 %67, i8* %70, i8* %73, i8* %76, i8* %79, i8* %82, i8* %85)
%87 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %87, i64* %7
%88 = load i8**, i8*** %6
%89 = load i8*, i8** %3
%90 = load i8, i8* %4
%91 = sext i8 %90 to i32
%92 = call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @asm_str_sep to i32 (i8**, i8*, i32, ...)*)(i8** %88, i8* %89, i32 %91)
%93 = call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
store i64 %93, i64* %8
%94 = load i64, i64* %8
%95 = load i64, i64* %7
%96 = sub i64 %94, %95
%97 = load i8**, i8*** %6
%98 = getelementptr inbounds i8*, i8** %97, i64 0
%99 = load i8*, i8** %98
%100 = load i8**, i8*** %6
%101 = getelementptr inbounds i8*, i8** %100, i64 1
%102 = load i8*, i8** %101
%103 = load i8**, i8*** %6
%104 = getelementptr inbounds i8*, i8** %103, i64 2
%105 = load i8*, i8** %104
%106 = load i8**, i8*** %6
%107 = getelementptr inbounds i8*, i8** %106, i64 3
%108 = load i8*, i8** %107
%109 = load i8**, i8*** %6
%110 = getelementptr inbounds i8*, i8** %109, i64 4
%111 = load i8*, i8** %110
%112 = load i8**, i8*** %6
%113 = getelementptr inbounds i8*, i8** %112, i64 5
%114 = load i8*, i8** %113
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %96, i8* %99, i8* %102, i8* %105, i8* %108, i8* %111, i8* %114)
store i32 0, i32* %5
br label %116
116: ; preds = %125, %28
%117 = load i32, i32* %5
%118 = icmp slt i32 %117, 6
br i1 %118, label %119, label %128
119: ; preds = %116
%120 = load i8**, i8*** %6
%121 = load i32, i32* %5
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds i8*, i8** %120, i64 %122
%124 = load i8*, i8** %123
br label %125
125: ; preds = %119
%126 = load i32, i32* %5
%127 = add nsw i32 %126, 1
store i32 %127, i32* %5
br label %116
128: ; preds = %116
%129 = load i8**, i8*** %6
%130 = bitcast i8** %129 to i8*
ret void
}

LLVM IR (-O2):
@.str = [34 x i8] c"old = (%5lu) |%s|%s|%s|%s|%s|%s|\0A\00"
@.str.1 = [34 x i8] c"new = (%5lu) |%s|%s|%s|%s|%s|%s|\0A\00"
@.str.2 = [34 x i8] c"asm = (%5lu) |%s|%s|%s|%s|%s|%s|\0A\00"
define void @test_str_sep(i8* %0, i8 signext %1) {
%3 = tail call dereferenceable_or_null(48) i8* @malloc(i64 48)
%4 = bitcast i8* %3 to i8**
%5 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
store i8* %5, i8** %4
store i8 0, i8* %5
%6 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%7 = getelementptr inbounds i8*, i8** %4, i64 1
store i8* %6, i8** %7
store i8 0, i8* %6
%8 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%9 = getelementptr inbounds i8*, i8** %4, i64 2
store i8* %8, i8** %9
store i8 0, i8* %8
%10 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%11 = getelementptr inbounds i8*, i8** %4, i64 3
store i8* %10, i8** %11
store i8 0, i8* %10
%12 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%13 = getelementptr inbounds i8*, i8** %4, i64 4
store i8* %12, i8** %13
store i8 0, i8* %12
%14 = tail call dereferenceable_or_null(32) i8* @malloc(i64 32)
%15 = getelementptr inbounds i8*, i8** %4, i64 5
store i8* %14, i8** %15
store i8 0, i8* %14
%16 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%17 = sext i8 %1 to i32
%18 = tail call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @old_str_sep to i32 (i8**, i8*, i32, ...)*)(i8** %4, i8* %0, i32 %17)
%19 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%20 = sub i64 %19, %16
%21 = load i8*, i8** %4
%22 = load i8*, i8** %7
%23 = load i8*, i8** %9
%24 = load i8*, i8** %11
%25 = load i8*, i8** %13
%26 = load i8*, i8** %15
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i64 %20, i8* %21, i8* %22, i8* %23, i8* %24, i8* %25, i8* %26)
%28 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%29 = tail call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @new_str_sep to i32 (i8**, i8*, i32, ...)*)(i8** %4, i8* %0, i32 %17)
%30 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%31 = sub i64 %30, %28
%32 = load i8*, i8** %4
%33 = load i8*, i8** %7
%34 = load i8*, i8** %9
%35 = load i8*, i8** %11
%36 = load i8*, i8** %13
%37 = load i8*, i8** %15
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i64 %31, i8* %32, i8* %33, i8* %34, i8* %35, i8* %36, i8* %37)
%39 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%40 = tail call i32 (i8**, i8*, i32, ...) bitcast (i32 (...)* @asm_str_sep to i32 (i8**, i8*, i32, ...)*)(i8** %4, i8* %0, i32 %17)
%41 = tail call i64 asm sideeffect "rdtsc", "=A,~{dirflag},~{fpsr},~{flags}"()
%42 = sub i64 %41, %39
%43 = load i8*, i8** %4
%44 = load i8*, i8** %7
%45 = load i8*, i8** %9
%46 = load i8*, i8** %11
%47 = load i8*, i8** %13
%48 = load i8*, i8** %15
%49 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i64 %42, i8* %43, i8* %44, i8* %45, i8* %46, i8* %47, i8* %48)
%50 = load i8*, i8** %4
tail call void @free(i8* %50)
%51 = load i8*, i8** %7
tail call void @free(i8* %51)
%52 = load i8*, i8** %9
tail call void @free(i8* %52)
%53 = load i8*, i8** %11
tail call void @free(i8* %53)
%54 = load i8*, i8** %13
tail call void @free(i8* %54)
%55 = load i8*, i8** %15
tail call void @free(i8* %55)
tail call void @free(i8* %3)
ret void
}