#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*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ replace_substring(char *, char *, char *);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n;
  char *s1;
  scanf("%d", &n);
  s1 = (char *)malloc((n + 1) * sizeof(char));
  scanf("%s", s1);
  int m;
  char *s2;
  scanf("%d", &m);
  s2 = (char *)malloc((m + 1) * sizeof(char));
  scanf("%s", s2);
  int k;
  char *s3;
  scanf("%d", &k);
  s3 = (char *)malloc((k + 1) * sizeof(char));
  scanf("%s", s3);
  replace_substring(s1, s2, s3);
  free(s3);
  free(s2);
  free(s1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe6f(%rip),%rdi
lea    -0x14(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
lea    0xe34(%rip),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <replace_substring@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xeac(%rip),%r14
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0xc(%rsp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
lea    0xe8a(%rip),%r15
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x8(%rsp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r13
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
lea    0x4(%rsp),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <scanf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1030 <replace_substring@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
mov    %r13,%rdi
call   1040 <free@plt>
mov    %r12,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %1
%8 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = mul i64 %11, 1
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = mul i64 %21, 1
%23 = trunc i64 %22 to i32
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = mul i64 %31, 1
%33 = trunc i64 %32 to i32
%34 = call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = load i8*, i8** %3
%39 = load i8*, i8** %5
%40 = load i8*, i8** %7
%41 = call i32 @replace_substring(i8* %38, i8* %39, i8* %40)
%42 = load i8*, i8** %7
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %5
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %3
%47 = call i32 @free(i8* %46)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %1 to i8*
%5 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, 1
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = bitcast i32* %2 to i8*
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = bitcast i32* %3 to i8*
%19 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
%24 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = call i32 @replace_substring(i8* %9, i8* %16, i8* %23)
%26 = call i32 @free(i8* %23)
%27 = call i32 @free(i8* %16)
%28 = call i32 @free(i8* %9)
ret i32 0
}