#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(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *search_replace_string(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  char buffer[2048];
  char *search_string;
  char *replace_string;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s: search replace\n", argv[0]);
    exit(1);
  }
  search_string = argv[1];
  replace_string = argv[2];
  while (get_line(buffer, stdin)) {
    printf("%s\n",
           search_replace_string(buffer, search_string, replace_string));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1199 <main+0x49>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe76(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x818(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x820(%rbp)
lea    -0x810(%rbp),%rdi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1204 <main+0xb4>
lea    -0x810(%rbp),%rdi
mov    -0x818(%rbp),%rsi
mov    -0x820(%rbp),%rdx
call   1040 <search_replace_string@plt>
mov    %rax,%rsi
lea    0xe21(%rip),%rdi
call   1050 <printf@plt>
jmp    11b7 <main+0x67>
xor    %eax,%eax
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x800,%rsp
cmp    $0x3,%edi
jne    11cd <main+0x7d>
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%r15
mov    0x2e74(%rip),%r13
mov    0x0(%r13),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11ba <main+0x6a>
mov    %rsp,%rbx
lea    0xe8c(%rip),%r12
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <search_replace_string@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
jne    1190 <main+0x40>
xor    %eax,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe20(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s: search replace\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2048 x i8]
%7 = alloca i8*
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
store i8* %21, i8** %7
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
store i8* %24, i8** %8
br label %25
25: ; preds = %30, %18
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%27 = load i32, i32* @stdin
%28 = call i64 @get_line(i8* %26, i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %25
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %6, i64 0, i64 0
%32 = load i8*, i8** %7
%33 = load i8*, i8** %8
%34 = call i8* @search_replace_string(i8* %31, i8* %32, i8* %33)
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %34)
br label %25
36: ; preds = %25
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Usage: %s: search replace\0A\00"
@stdin = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 3
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = load i32, i32* @stdin
%17 = call i64 @get_line(i8* %4, i32 %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %11, %19
%20 = call i8* @search_replace_string(i8* %4, i8* %13, i8* %15)
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @stdin
%23 = call i64 @get_line(i8* %4, i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %19
25: ; preds = %19, %11
ret i32 0
}