#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*/ do_edit(char *, char);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
char get_command();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
void edit_string() {
  char source[100], command;
  printf("Enter the source string: \n");
  fgets(source, 100, stdin);
  for (command = get_command(); command != 'Q'; command = get_command()) {
    do_edit(source, command);
    printf("New source: %s\n\n", source);
  }
  printf("String after editing: %s\n", source);
}


x86 assembly (clang, -O0):
<edit_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e84(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    $0x0,%al
call   1060 <get_command@plt>
mov    %al,-0x71(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0x51,%eax
je     11b5 <edit_string+0x75>
lea    -0x70(%rbp),%rdi
movsbl -0x71(%rbp),%esi
call   1040 <do_edit@plt>
lea    -0x70(%rbp),%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <get_command@plt>
mov    %al,-0x71(%rbp)
jmp    117a <edit_string+0x3a>
lea    -0x70(%rbp),%rsi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edit_string>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xecd(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
xor    %eax,%eax
call   1070 <get_command@plt>
cmp    $0x51,%al
je     11b3 <edit_string+0x63>
mov    %rsp,%rbx
lea    0xe72(%rip),%r14
xchg   %ax,%ax
movsbl %al,%esi
mov    %rbx,%rdi
call   1050 <do_edit@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <get_command@plt>
cmp    $0x51,%al
jne    1190 <edit_string+0x40>
lea    0xe57(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"Enter the source string: \0A\00"
@stdin = global i32 0
@.str.1 = [17 x i8] c"New source: %s\0A\0A\00"
@.str.2 = [26 x i8] c"String after editing: %s\0A\00"
define void @edit_string() {
%1 = alloca [100 x i8]
%2 = alloca i8
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %4, i32 100, i32 %5)
%7 = call signext i8 (...) @get_command()
store i8 %7, i8* %2
br label %8
8: ; preds = %18, %0
%9 = load i8, i8* %2
%10 = sext i8 %9 to i32
%11 = icmp ne i32 %10, 81
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%14 = load i8, i8* %2
%15 = call i32 @do_edit(i8* %13, i8 signext %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %12
%19 = call signext i8 (...) @get_command()
store i8 %19, i8* %2
br label %8
20: ; preds = %8
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %21)
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [17 x i8] c"New source: %s\0A\0A\00"
@.str.2 = [26 x i8] c"String after editing: %s\0A\00"
@str = [26 x i8] c"Enter the source string: \00"
define void @edit_string() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call i32 @fgets(i8* %2, i32 100, i32 %4)
%6 = call signext i8 (...) @get_command()
%7 = icmp eq i8 %6, 81
br i1 %7, label %14, label %8
8: ; preds = %0, %8
%9 = phi i8 [ %12, %8 ], [ %6, %0 ]
%10 = call i32 @do_edit(i8* %2, i8 signext %9)
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%12 = call signext i8 (...) @get_command()
%13 = icmp eq i8 %12, 81
br i1 %13, label %14, label %8
14: ; preds = %8, %0
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %2)
ret void
}