#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 */
typedef scalar_t__ uint64_t;

/* Variables and functions */
int /*<<< orphan*/ asm_str_repblock(char *, char *, char, char);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ new_str_repblock(char *, char *, char, char);
int /*<<< orphan*/ old_str_repblock(char *, char *, char, char);
int /*<<< orphan*/ printf(char *, scalar_t__, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void test_repblock(char *cmp, char find, char rep) {
  char *o1 = malloc(128);
  char *o2 = malloc(128);
  char *o3 = malloc(128);
  strcpy(o1, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
  strcpy(o2, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
  strcpy(o3, "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq");
  uint64_t t1, t2;
  0;
  old_str_repblock(o1, cmp, find, rep);
  0;
  printf("old - (%5llu cycles) %s\n", (long long unsigned int)t2 - t1, o1);
  0;
  new_str_repblock(o2, cmp, find, rep);
  0;
  printf("new - (%5llu cycles) %s\n", (long long unsigned int)t2 - t1, o2);
  0;
  asm_str_repblock(o3, cmp, find, rep);
  0;
  printf("asm - (%5llu cycles) %s\n", (long long unsigned int)t2 - t1, o3);
  free(o1);
  free(o2);
  free(o3);
}


x86 assembly (clang, -O0):
<test_repblock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x28(%rbp),%rdi
lea    0xe24(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x9(%rbp),%al
movsbl %al,%edx
movsbl -0xa(%rbp),%ecx
call   1070 <old_str_repblock@plt>
mov    -0x38(%rbp),%rsi
sub    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe24(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x9(%rbp),%al
movsbl %al,%edx
movsbl -0xa(%rbp),%ecx
call   1090 <new_str_repblock@plt>
mov    -0x38(%rbp),%rsi
sub    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe0e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x9(%rbp),%al
movsbl %al,%edx
movsbl -0xa(%rbp),%ecx
call   1050 <asm_str_repblock@plt>
mov    -0x38(%rbp),%rsi
sub    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdf8(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_repblock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,0x4(%rsp)
mov    %esi,%ebx
mov    %rdi,%rbp
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    $0x80,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
lea    0xe4e(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %rbp,%r15
mov    %rbp,%rsi
mov    %ebx,%ebp
mov    %ebx,%edx
mov    0x4(%rsp),%ebx
mov    %ebx,%ecx
call   1070 <old_str_repblock@plt>
lea    0xe3d(%rip),%rdi
mov    %r14,%rdx
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1090 <new_str_repblock@plt>
lea    0xe38(%rip),%rdi
mov    %r12,%rdx
call   1060 <printf@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
call   1050 <asm_str_repblock@plt>
lea    0xe33(%rip),%rdi
mov    %r13,%rdx
call   1060 <printf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\00"
@.str.1 = [25 x i8] c"old - (%5llu cycles) %s\0A\00"
@.str.2 = [25 x i8] c"new - (%5llu cycles) %s\0A\00"
@.str.3 = [25 x i8] c"asm - (%5llu cycles) %s\0A\00"
define void @test_repblock(i8* %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8 %2, i8* %6
%12 = call i8* @malloc(i32 128)
store i8* %12, i8** %7
%13 = call i8* @malloc(i32 128)
store i8* %13, i8** %8
%14 = call i8* @malloc(i32 128)
store i8* %14, i8** %9
%15 = load i8*, i8** %7
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %8
%18 = call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %9
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %7
%22 = load i8*, i8** %4
%23 = load i8, i8* %5
%24 = load i8, i8* %6
%25 = call i32 @old_str_repblock(i8* %21, i8* %22, i8 signext %23, i8 signext %24)
%26 = load i64, i64* %11
%27 = load i64, i64* %10
%28 = sub i64 %26, %27
%29 = load i8*, i8** %7
%30 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 %28, i8* %29)
%31 = load i8*, i8** %8
%32 = load i8*, i8** %4
%33 = load i8, i8* %5
%34 = load i8, i8* %6
%35 = call i32 @new_str_repblock(i8* %31, i8* %32, i8 signext %33, i8 signext %34)
%36 = load i64, i64* %11
%37 = load i64, i64* %10
%38 = sub i64 %36, %37
%39 = load i8*, i8** %8
%40 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 %38, i8* %39)
%41 = load i8*, i8** %9
%42 = load i8*, i8** %4
%43 = load i8, i8* %5
%44 = load i8, i8* %6
%45 = call i32 @asm_str_repblock(i8* %41, i8* %42, i8 signext %43, i8 signext %44)
%46 = load i64, i64* %11
%47 = load i64, i64* %10
%48 = sub i64 %46, %47
%49 = load i8*, i8** %9
%50 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i64 %48, i8* %49)
%51 = load i8*, i8** %7
%52 = call i32 @free(i8* %51)
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
%55 = load i8*, i8** %9
%56 = call i32 @free(i8* %55)
ret void
}

LLVM IR (-O2):
@.str = [47 x i8] c"qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\00"
@.str.1 = [25 x i8] c"old - (%5llu cycles) %s\0A\00"
@.str.2 = [25 x i8] c"new - (%5llu cycles) %s\0A\00"
@.str.3 = [25 x i8] c"asm - (%5llu cycles) %s\0A\00"
define void @test_repblock(i8* %0, i8 signext %1, i8 signext %2) {
%4 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%5 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%6 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
%7 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @old_str_repblock(i8* %4, i8* %0, i8 signext %1, i8 signext %2)
%11 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i64 undef, i8* %4)
%12 = tail call i32 @new_str_repblock(i8* %5, i8* %0, i8 signext %1, i8 signext %2)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i64 undef, i8* %5)
%14 = tail call i32 @asm_str_repblock(i8* %6, i8* %0, i8 signext %1, i8 signext %2)
%15 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i64 undef, i8* %6)
%16 = tail call i32 @free(i8* %4)
%17 = tail call i32 @free(i8* %5)
%18 = tail call i32 @free(i8* %6)
ret void
}