#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getLine(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ replace(char *, char *, char *);
int main(int argc, char **argv) {
  char *src, *pat, *replacement;
  if ((src = (char *)malloc(1001 * sizeof(char))) == NULL) {
    exit(EXIT_FAILURE);
  }
  if ((pat = (char *)malloc(1001 * sizeof(char))) == NULL) {
    exit(EXIT_FAILURE);
  }
  if ((replacement = (char *)malloc(1001 * sizeof(char))) == NULL) {
    exit(EXIT_FAILURE);
  }
  getLine(src);
  getLine(pat);
  getLine(replacement);
  replace(src, pat, replacement);
  printf("%s", src);
  free(src);
  free(pat);
  free(replacement);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x3e9,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119c <main+0x3c>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x3e9,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c2 <main+0x62>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x3e9,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e8 <main+0x88>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1070 <getLine@plt>
mov    -0x20(%rbp),%rdi
call   1070 <getLine@plt>
mov    -0x28(%rbp),%rdi
call   1070 <getLine@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <replace@plt>
mov    -0x18(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1040 <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>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x3e9,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11fb <main+0x9b>
mov    %rax,%rbx
mov    $0x3e9,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11fb <main+0x9b>
mov    %rax,%r14
mov    $0x3e9,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11fb <main+0x9b>
mov    %rax,%r15
mov    %rbx,%rdi
call   1070 <getLine@plt>
mov    %r14,%rdi
call   1070 <getLine@plt>
mov    %r15,%rdi
call   1070 <getLine@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1060 <replace@plt>
lea    0xe34(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i64 @malloc(i32 1001)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = call i64 @malloc(i32 1001)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %7
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %15
%23 = call i64 @malloc(i32 1001)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %22
%30 = load i8*, i8** %6
%31 = call i32 @getLine(i8* %30)
%32 = load i8*, i8** %7
%33 = call i32 @getLine(i8* %32)
%34 = load i8*, i8** %8
%35 = call i32 @getLine(i8* %34)
%36 = load i8*, i8** %6
%37 = load i8*, i8** %7
%38 = load i8*, i8** %8
%39 = call i32 @replace(i8* %36, i8* %37, i8* %38)
%40 = load i8*, i8** %6
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load i8*, i8** %6
%43 = call i32 @free(i8* %42)
%44 = load i8*, i8** %7
%45 = call i32 @free(i8* %44)
%46 = load i8*, i8** %8
%47 = call i32 @free(i8* %46)
%48 = load i32, i32* @EXIT_SUCCESS
ret i32 %48
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [3 x i8] c"%s\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 1001)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = tail call i64 @malloc(i32 1001)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %9
%17 = tail call i64 @malloc(i32 1001)
%18 = inttoptr i64 %17 to i8*
%19 = icmp eq i64 %17, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %16
%24 = tail call i32 @getLine(i8* %4)
%25 = tail call i32 @getLine(i8* %11)
%26 = tail call i32 @getLine(i8* %18)
%27 = tail call i32 @replace(i8* %4, i8* %11, i8* %18)
%28 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%29 = tail call i32 @free(i8* %4)
%30 = tail call i32 @free(i8* %11)
%31 = tail call i32 @free(i8* %18)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}