#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 */
int /*<<< orphan*/ s_del(char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ s_insert(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ s_len(char *);
int s_pos(char *, char *);
char *s_replaceall(char *substr, char *newsubstr, char *str) {
  int i;
  while ((i = s_pos(substr, str)) != -1)
    s_insert(newsubstr, s_del(str, str, i, s_len(substr)), i);
  return (str);
}


x86 assembly (clang, -O0):
<s_replaceall>:
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    -0x18(%rbp),%rsi
call   1040 <s_pos@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11b9 <s_replaceall+0x79>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <s_len@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
call   1060 <s_del@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
mov    -0x1c(%rbp),%edx
call   1050 <s_insert@plt>
jmp    1154 <s_replaceall+0x14>
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_replaceall>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rsi
call   1040 <s_pos@plt>
cmp    $0xffffffff,%eax
je     1195 <s_replaceall+0x55>
mov    %eax,%ebp
nop
mov    %r15,%rdi
call   1030 <s_len@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <s_del@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    %ebp,%edx
call   1050 <s_insert@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <s_pos@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1160 <s_replaceall+0x20>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @s_replaceall(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
br label %8
8: ; preds = %13, %3
%9 = load i8*, i8** %4
%10 = load i8*, i8** %6
%11 = call i32 @s_pos(i8* %9, i8* %10)
store i32 %11, i32* %7
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = load i8*, i8** %6
%17 = load i32, i32* %7
%18 = load i8*, i8** %4
%19 = call i32 @s_len(i8* %18)
%20 = call i32 @s_del(i8* %15, i8* %16, i32 %17, i32 %19)
%21 = load i32, i32* %7
%22 = call i32 @s_insert(i8* %14, i32 %20, i32 %21)
br label %8
23: ; preds = %8
%24 = load i8*, i8** %6
ret i8* %24
}

LLVM IR (-O2):
define i8* @s_replaceall(i8* %0, i8* %1, i8* returned %2) {
%4 = tail call i32 @s_pos(i8* %0, i8* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %13, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %11, %6 ], [ %4, %3 ]
%8 = tail call i32 @s_len(i8* %0)
%9 = tail call i32 @s_del(i8* %2, i8* %2, i32 %7, i32 %8)
%10 = tail call i32 @s_insert(i8* %1, i32 %9, i32 %7)
%11 = tail call i32 @s_pos(i8* %0, i8* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %6
13: ; preds = %6, %3
ret i8* %2
}