#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*/ delete (char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ insert(char *, char *, int);
int pos(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
char *do_edit(char *source, char command) {
  char str[100];
  int index;
  switch (command) {
  case 'D':
    printf("String to delete: \n");
    fgets(str, 100, stdin);
    index = pos(source, str);
    if (index == -1)
      printf("'%s' not found!\n", str);
    else
      delete (source, index, strlen(str));
    break;
  case 'I':
    printf("String to insert: \n");
    fgets(str, 100, stdin);
    printf("Position of insertion: \n");
    scanf("%d", &index);
    insert(source, str, index);
    break;
  case 'F':
    printf("String to find: \n");
    fgets(str, 100, stdin);
    index = pos(source, str);
    if (index == -1)
      printf("'%s' not found\n", str);
    else
      printf("'%s' found at position: %d\n", str, index);
    break;
  default:
    printf("Invalid command: '%c'\n", command);
  }
  return (source);
}


x86 assembly (clang, -O0):
<do_edit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
mov    %eax,-0x78(%rbp)
sub    $0x44,%eax
je     11bc <do_edit+0x4c>
jmp    119a <do_edit+0x2a>
mov    -0x78(%rbp),%eax
sub    $0x46,%eax
je     129a <do_edit+0x12a>
jmp    11ab <do_edit+0x3b>
mov    -0x78(%rbp),%eax
sub    $0x49,%eax
je     1242 <do_edit+0xd2>
jmp    130a <do_edit+0x19a>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1090 <pos@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    1212 <do_edit+0xa2>
lea    -0x70(%rbp),%rsi
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123d <do_edit+0xcd>
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x74(%rbp),%eax
mov    %eax,-0x7c(%rbp)
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    -0x7c(%rbp),%esi
mov    %eax,%edx
call   1080 <delete@plt>
jmp    131c <do_edit+0x1ac>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2d8d(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdd6(%rip),%rdi
lea    -0x74(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
call   1070 <insert@plt>
jmp    131c <do_edit+0x1ac>
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2d35(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
lea    -0x70(%rbp),%rsi
call   1090 <pos@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    12f0 <do_edit+0x180>
lea    -0x70(%rbp),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1305 <do_edit+0x195>
lea    -0x70(%rbp),%rsi
mov    -0x74(%rbp),%edx
lea    0xd79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131c <do_edit+0x1ac>
movsbl -0x9(%rbp),%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_edit>:
push   %rbp
push   %rbx
sub    $0x78,%rsp
mov    %rdi,%rbx
cmp    $0x49,%esi
je     11f8 <do_edit+0x78>
cmp    $0x46,%esi
je     124d <do_edit+0xcd>
cmp    $0x44,%esi
jne    129b <do_edit+0x11b>
lea    0xeec(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <pos@plt>
cmp    $0xffffffff,%eax
je     12ab <do_edit+0x12b>
mov    %eax,%ebp
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1090 <delete@plt>
jmp    12c7 <do_edit+0x147>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
lea    0xddf(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1080 <insert@plt>
jmp    12c7 <do_edit+0x147>
lea    0xe03(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10a0 <pos@plt>
cmp    $0xffffffff,%eax
je     12b4 <do_edit+0x134>
lea    0xd99(%rip),%rdi
lea    0x10(%rsp),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12c7 <do_edit+0x147>
lea    0xd9e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12c7 <do_edit+0x147>
lea    0xd4e(%rip),%rdi
jmp    12bb <do_edit+0x13b>
lea    0xd59(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rax
add    $0x78,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"String to delete: \0A\00"
@stdin = global i32 0
@.str.1 = [17 x i8] c"'%s' not found!\0A\00"
@.str.2 = [20 x i8] c"String to insert: \0A\00"
@.str.3 = [25 x i8] c"Position of insertion: \0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [18 x i8] c"String to find: \0A\00"
@.str.6 = [16 x i8] c"'%s' not found\0A\00"
@.str.7 = [28 x i8] c"'%s' found at position: %d\0A\00"
@.str.8 = [23 x i8] c"Invalid command: '%c'\0A\00"
define i8* @do_edit(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca [100 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = load i8, i8* %4
%8 = sext i8 %7 to i32
switch i32 %8, label %58 [
i32 68, label %9
i32 73, label %29
i32 70, label %40
]
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 100, i32 %12)
%14 = load i8*, i8** %3
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%16 = call i32 @pos(i8* %14, i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %9
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %28
22: ; preds = %9
%23 = load i8*, i8** %3
%24 = load i32, i32* %6
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%26 = call i32 @strlen(i8* %25)
%27 = call i32 @delete(i8* %23, i32 %24, i32 %26)
br label %28
28: ; preds = %22, %19
br label %62
29: ; preds = %2
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%32 = load i32, i32* @stdin
%33 = call i32 @fgets(i8* %31, i32 100, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %6)
%36 = load i8*, i8** %3
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%38 = load i32, i32* %6
%39 = call i32 @insert(i8* %36, i8* %37, i32 %38)
br label %62
40: ; preds = %2
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%43 = load i32, i32* @stdin
%44 = call i32 @fgets(i8* %42, i32 100, i32 %43)
%45 = load i8*, i8** %3
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%47 = call i32 @pos(i8* %45, i8* %46)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %53
50: ; preds = %40
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %51)
br label %57
53: ; preds = %40
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%55 = load i32, i32* %6
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %54, i32 %55)
br label %57
57: ; preds = %53, %50
br label %62
58: ; preds = %2
%59 = load i8, i8* %4
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %58, %57, %29, %28
%63 = load i8*, i8** %3
ret i8* %63
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.1 = [17 x i8] c"'%s' not found!\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.6 = [16 x i8] c"'%s' not found\0A\00"
@.str.7 = [28 x i8] c"'%s' found at position: %d\0A\00"
@.str.8 = [23 x i8] c"Invalid command: '%c'\0A\00"
@str = [17 x i8] c"String to find: \00"
@str.9 = [19 x i8] c"String to insert: \00"
@str.10 = [24 x i8] c"Position of insertion: \00"
@str.11 = [19 x i8] c"String to delete: \00"
define i8* @do_edit(i8* returned %0, i8 signext %1) {
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast i32* %4 to i8*
%7 = sext i8 %1 to i32
switch i32 %7, label %37 [
i32 68, label %8
i32 73, label %19
i32 70, label %27
]
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.11, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %5, i32 100, i32 %10)
%12 = call i32 @pos(i8* %0, i8* %5)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %39
16: ; preds = %8
%17 = call i32 @strlen(i8* %5)
%18 = call i32 @delete(i8* %0, i32 %12, i32 %17)
br label %39
19: ; preds = %2
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%21 = load i32, i32* @stdin
%22 = call i32 @fgets(i8* %5, i32 100, i32 %21)
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.10, i64 0, i64 0))
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%25 = load i32, i32* %4
%26 = call i32 @insert(i8* %0, i8* %5, i32 %25)
br label %39
27: ; preds = %2
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %5, i32 100, i32 %29)
%31 = call i32 @pos(i8* %0, i8* %5)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i8* %5)
br label %39
35: ; preds = %27
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.7, i64 0, i64 0), i8* %5, i32 %31)
br label %39
37: ; preds = %2
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %7)
br label %39
39: ; preds = %33, %35, %14, %16, %37, %19
ret i8* %0
}