#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 */
scalar_t__ Sub(char *, char *, unsigned int);
int /*<<< orphan*/ __fpurge(int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ realloc(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main() {
  char *str = (char *)malloc(200 * sizeof(char));
  char *sub = (char *)malloc(200 * sizeof(char));
  unsigned int i, j;
  printf("inserisci la stringa: ");
  scanf("%s", str);
  str = (char *)realloc(str, (strlen(str) + 1) * sizeof(char));
  printf("inserisci la sotto stringa: ");
  scanf("%s", sub);
  sub = (char *)realloc(sub, (strlen(sub) + 1) * sizeof(char));
  for (i = 0; i < strlen(str); i++)
    if (Sub(str, sub, i)) {
      for (j = 0; i + j + strlen(sub) <= strlen(str); j++)
        str[i + j] = str[i + j + strlen(sub)];
      i--;
    }
  str = (char *)realloc(str, (strlen(str) + 1) * sizeof(char));
  printf("\n%s", str);
  __fpurge(stdin);
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jae    1312 <main+0x192>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <Sub@plt>
cmp    $0x0,%rax
je     12ff <main+0x17f>
movl   $0x0,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
ja     12f6 <main+0x176>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%ecx
mov    %eax,%edx
mov    -0x48(%rbp),%rax
add    %edx,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    -0x20(%rbp),%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    127d <main+0xfd>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    1304 <main+0x184>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1240 <main+0xc0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x58(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
call   1030 <__fpurge@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe54(%rip),%rdi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe78(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
call   1080 <realloc@plt>
mov    %rax,%r13
lea    0xe32(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1090 <scanf@plt>
mov    %rbp,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbp,%rdi
call   1080 <realloc@plt>
mov    %rax,%r12
mov    %r13,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jne    1285 <main+0x105>
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r13,%rdi
call   1080 <realloc@plt>
lea    0xe01(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
call   1030 <__fpurge@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffff,%r14d
add    $0x1,%r14d
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r14d
jae    1219 <main+0x99>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   10a0 <Sub@plt>
test   %rax,%rax
je     1274 <main+0xf4>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
add    %r14d,%r15d
mov    %r13,%rdi
call   1040 <strlen@plt>
cmp    %eax,%r15d
ja     1270 <main+0xf0>
mov    %r14d,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
movzbl 0x0(%r13,%rax,1),%eax
mov    %ebx,%ecx
mov    %al,0x0(%r13,%rcx,1)
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
call   1040 <strlen@plt>
lea    (%rbx,%rbp,1),%ecx
add    $0x1,%ecx
mov    %ebx,%edx
add    $0x1,%edx
mov    %edx,%ebx
cmp    %eax,%ecx
jbe    12c0 <main+0x140>
jmp    1270 <main+0xf0>

LLVM IR (-O0):
@.str = [23 x i8] c"inserisci la stringa: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"inserisci la sotto stringa: \00"
@.str.3 = [4 x i8] c"\0A%s\00"
@stdin = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i64 @malloc(i32 200)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %2
%8 = call i64 @malloc(i32 200)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i8*, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = mul i64 %17, 1
%19 = trunc i64 %18 to i32
%20 = call i64 @realloc(i8* %13, i32 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %2
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%23 = load i8*, i8** %3
%24 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %3
%26 = load i8*, i8** %3
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = mul i64 %29, 1
%31 = trunc i64 %30 to i32
%32 = call i64 @realloc(i8* %25, i32 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %3
store i32 0, i32* %4
br label %34
34: ; preds = %80, %0
%35 = load i32, i32* %4
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
%38 = icmp ult i32 %35, %37
br i1 %38, label %39, label %83
39: ; preds = %34
%40 = load i8*, i8** %2
%41 = load i8*, i8** %3
%42 = load i32, i32* %4
%43 = call i64 @Sub(i8* %40, i8* %41, i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %79
45: ; preds = %39
store i32 0, i32* %5
br label %46
46: ; preds = %73, %45
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = add i32 %47, %48
%50 = load i8*, i8** %3
%51 = call i32 @strlen(i8* %50)
%52 = add i32 %49, %51
%53 = load i8*, i8** %2
%54 = call i32 @strlen(i8* %53)
%55 = icmp ule i32 %52, %54
br i1 %55, label %56, label %76
56: ; preds = %46
%57 = load i8*, i8** %2
%58 = load i32, i32* %4
%59 = load i32, i32* %5
%60 = add i32 %58, %59
%61 = load i8*, i8** %3
%62 = call i32 @strlen(i8* %61)
%63 = add i32 %60, %62
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %57, i64 %64
%66 = load i8, i8* %65
%67 = load i8*, i8** %2
%68 = load i32, i32* %4
%69 = load i32, i32* %5
%70 = add i32 %68, %69
%71 = zext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %67, i64 %71
store i8 %66, i8* %72
br label %73
73: ; preds = %56
%74 = load i32, i32* %5
%75 = add i32 %74, 1
store i32 %75, i32* %5
br label %46
76: ; preds = %46
%77 = load i32, i32* %4
%78 = add i32 %77, -1
store i32 %78, i32* %4
br label %79
79: ; preds = %76, %39
br label %80
80: ; preds = %79
%81 = load i32, i32* %4
%82 = add i32 %81, 1
store i32 %82, i32* %4
br label %34
83: ; preds = %34
%84 = load i8*, i8** %2
%85 = load i8*, i8** %2
%86 = call i32 @strlen(i8* %85)
%87 = add nsw i32 %86, 1
%88 = sext i32 %87 to i64
%89 = mul i64 %88, 1
%90 = trunc i64 %89 to i32
%91 = call i64 @realloc(i8* %84, i32 %90)
%92 = inttoptr i64 %91 to i8*
store i8* %92, i8** %2
%93 = load i8*, i8** %2
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %93)
%95 = load i32, i32* @stdin
%96 = call i32 @__fpurge(i32 %95)
%97 = call i32 (...) @getchar()
%98 = load i32, i32* %1
ret i32 %98
}

LLVM IR (-O2):
@.str = [23 x i8] c"inserisci la stringa: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [29 x i8] c"inserisci la sotto stringa: \00"
@.str.3 = [4 x i8] c"\0A%s\00"
@stdin = global i32 0
define i32 @main() {
%1 = tail call i64 @malloc(i32 200)
%2 = inttoptr i64 %1 to i8*
%3 = tail call i64 @malloc(i32 200)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%7 = tail call i32 @strlen(i8* %2)
%8 = add nsw i32 %7, 1
%9 = tail call i64 @realloc(i8* %2, i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%13 = tail call i32 @strlen(i8* %4)
%14 = add nsw i32 %13, 1
%15 = tail call i64 @realloc(i8* %4, i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @strlen(i8* %10)
%18 = icmp eq i32 %17, 0
br i1 %18, label %51, label %19
19: ; preds = %0, %46
%20 = phi i32 [ %48, %46 ], [ 0, %0 ]
%21 = tail call i64 @Sub(i8* %10, i8* %16, i32 %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %46, label %23
23: ; preds = %19
%24 = tail call i32 @strlen(i8* %16)
%25 = add i32 %20, %24
%26 = tail call i32 @strlen(i8* %10)
%27 = icmp ugt i32 %25, %26
br i1 %27, label %44, label %28
28: ; preds = %23, %28
%29 = phi i32 [ %39, %28 ], [ %20, %23 ]
%30 = phi i32 [ %38, %28 ], [ 0, %23 ]
%31 = tail call i32 @strlen(i8* %16)
%32 = add i32 %31, %29
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %10, i64 %33
%35 = load i8, i8* %34
%36 = zext i32 %29 to i64
%37 = getelementptr inbounds i8, i8* %10, i64 %36
store i8 %35, i8* %37
%38 = add i32 %30, 1
%39 = add i32 %38, %20
%40 = tail call i32 @strlen(i8* %16)
%41 = add i32 %39, %40
%42 = tail call i32 @strlen(i8* %10)
%43 = icmp ugt i32 %41, %42
br i1 %43, label %44, label %28
44: ; preds = %28, %23
%45 = add i32 %20, -1
br label %46
46: ; preds = %19, %44
%47 = phi i32 [ %45, %44 ], [ %20, %19 ]
%48 = add i32 %47, 1
%49 = tail call i32 @strlen(i8* %10)
%50 = icmp ult i32 %48, %49
br i1 %50, label %19, label %51
51: ; preds = %46, %0
%52 = tail call i32 @strlen(i8* %10)
%53 = add nsw i32 %52, 1
%54 = tail call i64 @realloc(i8* %10, i32 %53)
%55 = inttoptr i64 %54 to i8*
%56 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %55)
%57 = load i32, i32* @stdin
%58 = tail call i32 @__fpurge(i32 %57)
%59 = tail call i32 (...) @getchar()
ret i32 0
}