#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 */
size_t jsonp_memcnt(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ jsonp_memmemmemi(char *, size_t, char const *, size_t,
                                    char const *, size_t);
int /*<<< orphan*/ jsonp_memsh(char *, int /*<<< orphan*/, size_t);
size_t jsonp_strnlen(char const *, size_t);
size_t jsonp_strirep(char *haystack, const char *needle, const char *replace) {
  size_t hn = jsonp_strnlen(haystack, (size_t)-1);
  size_t nn = jsonp_strnlen(needle, (size_t)-1);
  size_t rn = jsonp_strnlen(replace, (size_t)-1);
  jsonp_memmemmemi(haystack, hn, needle, nn, replace, rn);
  jsonp_memsh(haystack, 0, hn);
  return hn - jsonp_memcnt(haystack, 0, hn);
}


x86 assembly (clang, -O0):
<jsonp_strirep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <jsonp_strnlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <jsonp_strnlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <jsonp_strnlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1040 <jsonp_memmemmemi@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1060 <jsonp_memsh@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1050 <jsonp_memcnt@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
sub    %rcx,%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jsonp_strirep>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r14
mov    $0xffffffffffffffff,%rsi
call   1030 <jsonp_strnlen@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <jsonp_strnlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <jsonp_strnlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %r15,%r8
mov    %rax,%r9
call   1040 <jsonp_memmemmemi@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1060 <jsonp_memsh@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1050 <jsonp_memcnt@plt>
sub    %rax,%rbx
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @jsonp_strirep(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i64 @jsonp_strnlen(i8* %10, i64 -1)
store i64 %11, i64* %7
%12 = load i8*, i8** %5
%13 = call i64 @jsonp_strnlen(i8* %12, i64 -1)
store i64 %13, i64* %8
%14 = load i8*, i8** %6
%15 = call i64 @jsonp_strnlen(i8* %14, i64 -1)
store i64 %15, i64* %9
%16 = load i8*, i8** %4
%17 = load i64, i64* %7
%18 = load i8*, i8** %5
%19 = load i64, i64* %8
%20 = load i8*, i8** %6
%21 = load i64, i64* %9
%22 = call i32 @jsonp_memmemmemi(i8* %16, i64 %17, i8* %18, i64 %19, i8* %20, i64 %21)
%23 = load i8*, i8** %4
%24 = load i64, i64* %7
%25 = call i32 @jsonp_memsh(i8* %23, i32 0, i64 %24)
%26 = load i64, i64* %7
%27 = load i8*, i8** %4
%28 = load i64, i64* %7
%29 = call i64 @jsonp_memcnt(i8* %27, i32 0, i64 %28)
%30 = sub i64 %26, %29
ret i64 %30
}

LLVM IR (-O2):
define i64 @jsonp_strirep(i8* %0, i8* %1, i8* %2) {
%4 = tail call i64 @jsonp_strnlen(i8* %0, i64 -1)
%5 = tail call i64 @jsonp_strnlen(i8* %1, i64 -1)
%6 = tail call i64 @jsonp_strnlen(i8* %2, i64 -1)
%7 = tail call i32 @jsonp_memmemmemi(i8* %0, i64 %4, i8* %1, i64 %5, i8* %2, i64 %6)
%8 = tail call i32 @jsonp_memsh(i8* %0, i32 0, i64 %4)
%9 = tail call i64 @jsonp_memcnt(i8* %0, i32 0, i64 %4)
%10 = sub i64 %4, %9
ret i64 %10
}