#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*/ delnchars(char *, int, int);
char getchar();
int /*<<< orphan*/ ins_string(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  char str1[2 * 100], str2[100];
  int i, x, n;
  printf("Enter the main string: ");
  i = 0;
  while ((str1[i++] = getchar()) != '\n')
    ;
  str1[i - 1] = '\0';
  printf("Enter the sub-string: ");
  i = 0;
  while ((str2[i++] = getchar()) != '\n')
    ;
  str2[i - 1] = '\0';
  printf("Enter the position to insert sub-string to main string: ");
  scanf("%d", &x);
  ins_string(str1, str2, x);
  printf("The main string is now:\n%s\n", str1);
  printf("Enter the number of characters and the position to delete from in "
         "the above string: ");
  scanf("%d", &n);
  scanf("%d", &x);
  delnchars(str1, n, x);
  printf("The string is now:\n%s\n", str1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x144(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x144(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x144(%rbp)
movslq %ecx,%rcx
mov    %al,-0xd0(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     11ad <main+0x5d>
jmp    117a <main+0x2a>
mov    -0x144(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0xd0(%rbp,%rax,1)
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x144(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x144(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x144(%rbp)
movslq %ecx,%rcx
mov    %al,-0x140(%rbp,%rcx,1)
movsbl %al,%eax
cmp    $0xa,%eax
je     120b <main+0xbb>
jmp    11d8 <main+0x88>
mov    -0x144(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x140(%rbp,%rax,1)
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe35(%rip),%rdi
lea    -0x148(%rbp),%rsi
call   1070 <scanf@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x140(%rbp),%rsi
mov    -0x148(%rbp),%edx
call   1060 <ins_string@plt>
lea    -0xd0(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde6(%rip),%rdi
lea    -0x14c(%rbp),%rsi
call   1070 <scanf@plt>
lea    0xdd3(%rip),%rdi
lea    -0x148(%rbp),%rsi
call   1070 <scanf@plt>
lea    -0xd0(%rbp),%rdi
mov    -0x14c(%rbp),%esi
mov    -0x148(%rbp),%edx
call   1030 <delnchars@plt>
lea    -0xd0(%rbp),%rsi
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x150,%rsp
lea    0xe9d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x81(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1180 <main+0x30>
mov    %ebx,%eax
movb   $0x0,0x80(%rsp,%rax,1)
lea    0xe71(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %al,0x11(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    11c0 <main+0x70>
mov    %ebx,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xe4e(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe79(%rip),%r14
lea    0x8(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%edx
lea    0x80(%rsp),%rbx
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <ins_string@plt>
lea    0xe4c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe57(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1070 <scanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0xc(%rsp),%esi
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
call   1030 <delnchars@plt>
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Enter the main string: \00"
@.str.1 = [23 x i8] c"Enter the sub-string: \00"
@.str.2 = [57 x i8] c"Enter the position to insert sub-string to main string: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [28 x i8] c"The main string is now:\0A%s\0A\00"
@.str.5 = [85 x i8] c"Enter the number of characters and the position to delete from in the above string: \00"
@.str.6 = [23 x i8] c"The string is now:\0A%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [200 x i8]
%3 = alloca [100 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %4
br label %8
8: ; preds = %16, %0
%9 = call signext i8 (...) @getchar()
%10 = load i32, i32* %4
%11 = add nsw i32 %10, 1
store i32 %11, i32* %4
%12 = sext i32 %10 to i64
%13 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %12
store i8 %9, i8* %13
%14 = sext i8 %9 to i32
%15 = icmp ne i32 %14, 10
br i1 %15, label %16, label %17
16: ; preds = %8
br label %8
17: ; preds = %8
%18 = load i32, i32* %4
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 %20
store i8 0, i8* %21
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %4
br label %23
23: ; preds = %31, %17
%24 = call signext i8 (...) @getchar()
%25 = load i32, i32* %4
%26 = add nsw i32 %25, 1
store i32 %26, i32* %4
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %27
store i8 %24, i8* %28
%29 = sext i8 %24 to i32
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %23
br label %23
32: ; preds = %23
%33 = load i32, i32* %4
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%39 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%40 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%41 = load i32, i32* %5
%42 = call i32 @ins_string(i8* %39, i8* %40, i32 %41)
%43 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.5, i64 0, i64 0))
%46 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
%47 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %5)
%48 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%49 = load i32, i32* %6
%50 = load i32, i32* %5
%51 = call i32 @delnchars(i8* %48, i32 %49, i32 %50)
%52 = getelementptr inbounds [200 x i8], [200 x i8]* %2, i64 0, i64 0
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [24 x i8] c"Enter the main string: \00"
@.str.1 = [23 x i8] c"Enter the sub-string: \00"
@.str.2 = [57 x i8] c"Enter the position to insert sub-string to main string: \00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [28 x i8] c"The main string is now:\0A%s\0A\00"
@.str.5 = [85 x i8] c"Enter the number of characters and the position to delete from in the above string: \00"
@.str.6 = [23 x i8] c"The string is now:\0A%s\0A\00"
define i32 @main() {
%1 = alloca [200 x i8]
%2 = alloca [100 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %10, %0
%11 = phi i64 [ %13, %10 ], [ 0, %0 ]
%12 = tail call signext i8 (...) @getchar()
%13 = add nuw i64 %11, 1
%14 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 %11
store i8 %12, i8* %14
%15 = icmp eq i8 %12, 10
br i1 %15, label %16, label %10
16: ; preds = %10
%17 = and i64 %11, 4294967295
%18 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %20, %16
%21 = phi i64 [ %23, %20 ], [ 0, %16 ]
%22 = tail call signext i8 (...) @getchar()
%23 = add nuw i64 %21, 1
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %21
store i8 %22, i8* %24
%25 = icmp eq i8 %22, 10
br i1 %25, label %26, label %20
26: ; preds = %20
%27 = and i64 %21, 4294967295
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %27
store i8 0, i8* %28
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%31 = load i32, i32* %3
%32 = call i32 @ins_string(i8* %5, i8* %6, i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %5)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %3)
%37 = load i32, i32* %4
%38 = load i32, i32* %3
%39 = call i32 @delnchars(i8* %5, i32 %37, i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* %5)
ret i32 0
}