#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*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, char *, char *);
int strlen(char *);
int main() {
  char str[100];
  char ch;
  int i, len, j;
  scanf("%s %c", str, &ch);
  len = strlen(str);
  for (i = 0; i < len; i++) {
    printf("i is %d, %c\n", i, str[i]);
    if (str[i] == ch) {
      puts("Found match");
      for (j = i; j < len; j++) {
        printf("j is %d\n", j);
        str[j] = str[j + 1];
      }
      printf("New string after replacing one instance is: %s\n", str);
      len--;
      i--;
    }
  }
  printf("%s\n", str);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rsi
lea    0xea3(%rip),%rdi
lea    -0x71(%rbp),%rdx
call   1060 <scanf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x7c(%rbp)
movl   $0x0,-0x78(%rbp)
mov    -0x78(%rbp),%eax
cmp    -0x7c(%rbp),%eax
jge    123c <main+0xfc>
mov    -0x78(%rbp),%esi
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%edx
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movslq -0x78(%rbp),%rax
movsbl -0x70(%rbp,%rax,1),%eax
movsbl -0x71(%rbp),%ecx
cmp    %ecx,%eax
jne    1229 <main+0xe9>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    -0x78(%rbp),%eax
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x7c(%rbp),%eax
jge    1205 <main+0xc5>
mov    -0x80(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
cltq
mov    -0x70(%rbp,%rax,1),%cl
movslq -0x80(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    11c6 <main+0x86>
lea    -0x70(%rbp),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x7c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x7c(%rbp)
mov    -0x78(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x78(%rbp)
jmp    122e <main+0xee>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1179 <main+0x39>
lea    -0x70(%rbp),%rsi
lea    0xe0d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
lea    0xeab(%rip),%rdi
lea    0x10(%rsp),%rbx
lea    0xb(%rsp),%rdx
mov    %rbx,%rsi
call   1060 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1235 <main+0xf5>
mov    %eax,%r14d
lea    0xe85(%rip),%rbp
lea    0xe97(%rip),%r15
xor    %r12d,%r12d
jmp    11c0 <main+0x80>
nopl   (%rax)
lea    0xe91(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%r14d
add    $0xffffffff,%r14d
add    $0xffffffff,%r12d
lea    0xe4f(%rip),%rbp
add    $0x1,%r12d
cmp    %r14d,%r12d
jge    1235 <main+0xf5>
movslq %r12d,%rbx
movsbl 0x10(%rsp,%rbx,1),%edx
mov    %rbp,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%rsp,%rbx,1),%al
cmp    0xb(%rsp),%al
jne    11b7 <main+0x77>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,0xc(%rsp)
cmp    %r14d,%r12d
jge    1190 <main+0x50>
movslq 0xc(%rsp),%r13
lea    0x11(%rsp),%rax
lea    (%rax,%rbx,1),%r14
mov    %r12d,%ebp
sub    %rbx,%r13
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
lea    (%rbx,%rbp,1),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movzbl (%r14,%rbx,1),%eax
mov    %al,-0x1(%r14,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r13
jne    1210 <main+0xd0>
jmp    1190 <main+0x50>
lea    0x10(%rsp),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %c\00"
@.str.1 = [13 x i8] c"i is %d, %c\0A\00"
@.str.2 = [12 x i8] c"Found match\00"
@.str.3 = [9 x i8] c"j is %d\0A\00"
@.str.4 = [48 x i8] c"New string after replacing one instance is: %s\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%8 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %3)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %5
store i32 0, i32* %4
br label %11
11: ; preds = %60, %0
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %63
15: ; preds = %11
%16 = load i32, i32* %4
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %21)
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %27, %29
br i1 %30, label %31, label %59
31: ; preds = %15
%32 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* %4
store i32 %33, i32* %6
br label %34
34: ; preds = %49, %31
%35 = load i32, i32* %6
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = load i32, i32* %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %39)
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %43
%45 = load i8, i8* %44
%46 = load i32, i32* %6
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %47
store i8 %45, i8* %48
br label %49
49: ; preds = %38
%50 = load i32, i32* %6
%51 = add nsw i32 %50, 1
store i32 %51, i32* %6
br label %34
52: ; preds = %34
%53 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i32, i32* %5
%56 = add nsw i32 %55, -1
store i32 %56, i32* %5
%57 = load i32, i32* %4
%58 = add nsw i32 %57, -1
store i32 %58, i32* %4
br label %59
59: ; preds = %52, %15
br label %60
60: ; preds = %59
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %11
63: ; preds = %11
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %64)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %c\00"
@.str.1 = [13 x i8] c"i is %d, %c\0A\00"
@.str.2 = [12 x i8] c"Found match\00"
@.str.3 = [9 x i8] c"j is %d\0A\00"
@.str.4 = [48 x i8] c"New string after replacing one instance is: %s\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i32 @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %2)
%5 = call i32 @strlen(i8* %3)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %41
7: ; preds = %0, %36
%8 = phi i32 [ %38, %36 ], [ %5, %0 ]
%9 = phi i32 [ %39, %36 ], [ 0, %0 ]
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %13)
%15 = load i8, i8* %11
%16 = load i8, i8* %2
%17 = icmp eq i8 %15, %16
br i1 %17, label %18, label %36
18: ; preds = %7
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp slt i32 %9, %8
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = sext i32 %8 to i64
br label %23
23: ; preds = %21, %23
%24 = phi i64 [ %10, %21 ], [ %27, %23 ]
%25 = trunc i64 %24 to i32
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %25)
%27 = add nsw i64 %24, 1
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %24
store i8 %29, i8* %30
%31 = icmp eq i64 %27, %22
br i1 %31, label %32, label %23
32: ; preds = %23, %18
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%34 = add nsw i32 %8, -1
%35 = add nsw i32 %9, -1
br label %36
36: ; preds = %7, %32
%37 = phi i32 [ %35, %32 ], [ %9, %7 ]
%38 = phi i32 [ %34, %32 ], [ %8, %7 ]
%39 = add nsw i32 %37, 1
%40 = icmp slt i32 %39, %38
br i1 %40, label %7, label %41
41: ; preds = %36, %0
%42 = call i32 @puts(i8* %3)
ret i32 0
}