#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 int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ Q_strnrepl(char *, int, char *, char *, char *);
int /*<<< orphan*/ Scr_AddString(char *);
int /*<<< orphan*/ Scr_Error(char *);
int Scr_GetNumParam();
char *Scr_GetString(int);
void GScr_StrRepl() {
  char buffer[2048];
  if (Scr_GetNumParam() != 3) {
    Scr_Error("Usage: StrReplace(<string>, <string>, <string>)\n");
  }
  char *string = Scr_GetString(0);
  char *find = Scr_GetString(1);
  char *replacement = Scr_GetString(2);
  Q_strnrepl(buffer, sizeof(buffer), string, find, replacement);
  *buffer = 0;
  Scr_AddString(buffer);
}


x86 assembly (clang, -O0):
<GScr_StrRepl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    $0x0,%al
call   1030 <Scr_GetNumParam@plt>
cmp    $0x3,%eax
je     1177 <GScr_StrRepl+0x27>
lea    0xe8e(%rip),%rdi
call   1050 <Scr_Error@plt>
xor    %edi,%edi
call   1040 <Scr_GetString@plt>
mov    %rax,-0x808(%rbp)
mov    $0x1,%edi
call   1040 <Scr_GetString@plt>
mov    %rax,-0x810(%rbp)
mov    $0x2,%edi
call   1040 <Scr_GetString@plt>
mov    %rax,-0x818(%rbp)
lea    -0x800(%rbp),%rdi
mov    -0x808(%rbp),%rdx
mov    -0x810(%rbp),%rcx
mov    -0x818(%rbp),%r8
mov    $0x800,%esi
call   1070 <Q_strnrepl@plt>
movb   $0x0,-0x800(%rbp)
lea    -0x800(%rbp),%rdi
call   1060 <Scr_AddString@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GScr_StrRepl>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
xor    %eax,%eax
call   1030 <Scr_GetNumParam@plt>
cmp    $0x3,%eax
je     1174 <GScr_StrRepl+0x24>
lea    0xe91(%rip),%rdi
call   1050 <Scr_Error@plt>
xor    %edi,%edi
call   1040 <Scr_GetString@plt>
mov    %rax,%r14
mov    $0x1,%edi
call   1040 <Scr_GetString@plt>
mov    %rax,%rbx
mov    $0x2,%edi
call   1040 <Scr_GetString@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x800,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
call   1070 <Q_strnrepl@plt>
movb   $0x0,(%rsp)
mov    %r15,%rdi
call   1060 <Scr_AddString@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Usage: StrReplace(<string>, <string>, <string>)\0A\00"
define void @GScr_StrRepl() {
%1 = alloca [2048 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32 (...) @Scr_GetNumParam()
%6 = icmp ne i32 %5, 3
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @Scr_Error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i8* @Scr_GetString(i32 0)
store i8* %10, i8** %2
%11 = call i8* @Scr_GetString(i32 1)
store i8* %11, i8** %3
%12 = call i8* @Scr_GetString(i32 2)
store i8* %12, i8** %4
%13 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%14 = load i8*, i8** %2
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @Q_strnrepl(i8* %13, i32 2048, i8* %14, i8* %15, i8* %16)
%18 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
store i8 0, i8* %18
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%20 = call i32 @Scr_AddString(i8* %19)
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"Usage: StrReplace(<string>, <string>, <string>)\0A\00"
define void @GScr_StrRepl() {
%1 = alloca [2048 x i8]
%2 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @Scr_GetNumParam()
%4 = icmp eq i32 %3, 3
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @Scr_Error(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %0
%8 = tail call i8* @Scr_GetString(i32 0)
%9 = tail call i8* @Scr_GetString(i32 1)
%10 = tail call i8* @Scr_GetString(i32 2)
%11 = call i32 @Q_strnrepl(i8* %2, i32 2048, i8* %8, i8* %9, i8* %10)
store i8 0, i8* %2
%12 = call i32 @Scr_AddString(i8* %2)
ret void
}