#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*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int i;
  char *str;
  char find;
  char replace;
  char c;
  if (argc != 4) {
    char c = '\n';
    write(1, &c, 1);
    return (1);
  }
  str = argv[1];
  find = *argv[2];
  replace = *argv[3];
  i = 0;
  while (str[i]) {
    if (str[i] == find) {
      c = replace;
    } else {
      c = str[i];
    }
    write(1, &c, 1);
    i++;
  }
  c = '\n';
  write(1, &c, 1);
  return (0);
}


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)
cmpl   $0x4,-0x8(%rbp)
je     1150 <main+0x40>
movb   $0xa,-0x24(%rbp)
mov    $0x1,%edx
lea    -0x24(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <main+0xe9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    (%rax),%al
mov    %al,-0x22(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11de <main+0xce>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x21(%rbp),%ecx
cmp    %ecx,%eax
jne    11b2 <main+0xa2>
mov    -0x22(%rbp),%al
mov    %al,-0x23(%rbp)
jmp    11c0 <main+0xb0>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x23(%rbp)
mov    $0x1,%edx
lea    -0x23(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <main+0x6d>
movb   $0xa,-0x23(%rbp)
mov    $0x1,%edx
lea    -0x23(%rbp),%rsi
mov    %edx,%edi
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1187 <main+0x77>
mov    0x8(%rsi),%rbx
mov    (%rbx),%al
test   %al,%al
je     116a <main+0x5a>
mov    0x10(%rsi),%rcx
mov    (%rcx),%r15b
mov    0x18(%rsi),%rcx
add    $0x1,%rbx
movzbl (%rcx),%ebp
lea    0x6(%rsp),%r14
nopl   (%rax)
cmp    %r15b,%al
movzbl %al,%eax
cmove  %ebp,%eax
mov    %al,0x6(%rsp)
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1140 <main+0x30>
movb   $0xa,0x6(%rsp)
lea    0x6(%rsp),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
jmp    11a5 <main+0x95>
movb   $0xa,0x7(%rsp)
lea    0x7(%rsp),%rsi
mov    $0x1,%ebx
mov    $0x1,%edi
mov    $0x1,%edx
call   1030 <write@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
store i8 10, i8* %11
%15 = call i32 @write(i32 1, i8* %11, i32 1)
store i32 1, i32* %3
br label %59
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i8, i8* %22
store i8 %23, i8* %8
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 3
%26 = load i8*, i8** %25
%27 = load i8, i8* %26
store i8 %27, i8* %9
store i32 0, i32* %6
br label %28
28: ; preds = %53, %16
%29 = load i8*, i8** %7
%30 = load i32, i32* %6
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
%33 = load i8, i8* %32
%34 = icmp ne i8 %33, 0
br i1 %34, label %35, label %57
35: ; preds = %28
%36 = load i8*, i8** %7
%37 = load i32, i32* %6
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = load i8, i8* %8
%43 = sext i8 %42 to i32
%44 = icmp eq i32 %41, %43
br i1 %44, label %45, label %47
45: ; preds = %35
%46 = load i8, i8* %9
store i8 %46, i8* %10
br label %53
47: ; preds = %35
%48 = load i8*, i8** %7
%49 = load i32, i32* %6
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
store i8 %52, i8* %10
br label %53
53: ; preds = %47, %45
%54 = call i32 @write(i32 1, i8* %10, i32 1)
%55 = load i32, i32* %6
%56 = add nsw i32 %55, 1
store i32 %56, i32* %6
br label %28
57: ; preds = %28
store i8 10, i8* %10
%58 = call i32 @write(i32 1, i8* %10, i32 1)
store i32 0, i32* %3
br label %59
59: ; preds = %57, %14
%60 = load i32, i32* %3
ret i32 %60
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = icmp eq i32 %0, 4
br i1 %5, label %8, label %6
6: ; preds = %2
store i8 10, i8* %4
%7 = call i32 @write(i32 1, i8* %4, i32 1)
br label %31
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = load i8, i8* %10
%18 = icmp eq i8 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %8, %19
%20 = phi i64 [ %25, %19 ], [ 0, %8 ]
%21 = phi i8 [ %27, %19 ], [ %17, %8 ]
%22 = icmp eq i8 %21, %13
%23 = select i1 %22, i8 %16, i8 %21
store i8 %23, i8* %3
%24 = call i32 @write(i32 1, i8* %3, i32 1)
%25 = add nuw i64 %20, 1
%26 = getelementptr inbounds i8, i8* %10, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 0
br i1 %28, label %29, label %19
29: ; preds = %19, %8
store i8 10, i8* %3
%30 = call i32 @write(i32 1, i8* %3, i32 1)
br label %31
31: ; preds = %29, %6
%32 = phi i32 [ 1, %6 ], [ 0, %29 ]
ret i32 %32
}