#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 prima stringa: ");
  scanf("%s", str);
  str = (char *)realloc(str, (strlen(str) + 1) * sizeof(char));
  printf("Inserisci la seconda stringa: ");
  scanf("%s", sub);
  sub = (char *)realloc(sub, (strlen(sub) + 1) * sizeof(char));
  if (strlen(sub) > strlen(str))
    printf("ERRORE\n");
  else {
    for (i = 0; i < strlen(str); i++)
      if (Sub(str, sub, i)) {
        str[i] = '#';
        for (j = i + 1; j < strlen(str); j++)
          str[j] = str[j + strlen(sub) - 1];
      }
    str = (char *)realloc(str, sizeof(char) * (strlen(str) + 1));
  }
  printf("%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    0xe59(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%esi
call   1080 <realloc@plt>
mov    %rax,-0x10(%rbp)
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xe12(%rip),%rdi
call   1090 <scanf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%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,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
jle    126e <main+0xee>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    135e <main+0x1de>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
cmp    %ecx,%eax
jae    1335 <main+0x1b5>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   10a0 <Sub@plt>
cmp    $0x0,%rax
je     1322 <main+0x1a2>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
movb   $0x23,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
cmp    %ecx,%eax
jae    131d <main+0x19d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -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
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12bf <main+0x13f>
jmp    1322 <main+0x1a2>
jmp    1327 <main+0x1a7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1275 <main+0xf5>
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    0xcb4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2c71(%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   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0xc8,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe44(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe53(%rip),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
call   1090 <realloc@plt>
mov    %rax,%r15
lea    0xe2e(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
call   10a0 <scanf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r14,%rdi
call   1090 <realloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %r15,%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebx
jle    1241 <main+0xb1>
lea    0xe08(%rip),%rdi
call   1030 <puts@plt>
jmp    12f5 <main+0x165>
mov    %r15,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     12df <main+0x14f>
mov    $0x1,%ebp
xor    %ebx,%ebx
jmp    127d <main+0xed>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
mov    %rbx,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
add    $0x1,%rbp
mov    %r13,%rbx
cmp    %rax,%r13
jae    12df <main+0x14f>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   10b0 <Sub@plt>
test   %rax,%rax
je     1260 <main+0xd0>
movb   $0x23,(%r15,%rbx,1)
mov    %rbx,%r13
add    $0x1,%r13
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%eax
cmp    %rax,%r13
jae    1267 <main+0xd7>
mov    %rbp,(%rsp)
xchg   %ax,%ax
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %ebx,%eax
movzbl (%r15,%rax,1),%eax
mov    %al,(%r15,%rbp,1)
lea    0x1(%rbp),%r12
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebp,%ebx
mov    %r12,%rbp
cmp    %r12d,%eax
ja     12b0 <main+0x120>
mov    (%rsp),%rbp
jmp    1267 <main+0xd7>
mov    %r15,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%esi
mov    %r15,%rdi
call   1090 <realloc@plt>
mov    %rax,%r15
lea    0xd21(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
call   1040 <__fpurge@plt>
xor    %eax,%eax
call   1070 <getchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Inserisci la prima stringa: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [31 x i8] c"Inserisci la seconda stringa: \00"
@.str.3 = [8 x i8] c"ERRORE\0A\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 ([29 x i8], [29 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 ([31 x i8], [31 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
%34 = load i8*, i8** %3
%35 = call i32 @strlen(i8* %34)
%36 = load i8*, i8** %2
%37 = call i32 @strlen(i8* %36)
%38 = icmp sgt i32 %35, %37
br i1 %38, label %39, label %41
39: ; preds = %0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %97
41: ; preds = %0
store i32 0, i32* %4
br label %42
42: ; preds = %84, %41
%43 = load i32, i32* %4
%44 = load i8*, i8** %2
%45 = call i32 @strlen(i8* %44)
%46 = icmp ult i32 %43, %45
br i1 %46, label %47, label %87
47: ; preds = %42
%48 = load i8*, i8** %2
%49 = load i8*, i8** %3
%50 = load i32, i32* %4
%51 = call i64 @Sub(i8* %48, i8* %49, i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %83
53: ; preds = %47
%54 = load i8*, i8** %2
%55 = load i32, i32* %4
%56 = zext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 35, i8* %57
%58 = load i32, i32* %4
%59 = add i32 %58, 1
store i32 %59, i32* %5
br label %60
60: ; preds = %79, %53
%61 = load i32, i32* %5
%62 = load i8*, i8** %2
%63 = call i32 @strlen(i8* %62)
%64 = icmp ult i32 %61, %63
br i1 %64, label %65, label %82
65: ; preds = %60
%66 = load i8*, i8** %2
%67 = load i32, i32* %5
%68 = load i8*, i8** %3
%69 = call i32 @strlen(i8* %68)
%70 = add i32 %67, %69
%71 = sub i32 %70, 1
%72 = zext i32 %71 to i64
%73 = getelementptr inbounds i8, i8* %66, i64 %72
%74 = load i8, i8* %73
%75 = load i8*, i8** %2
%76 = load i32, i32* %5
%77 = zext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8 %74, i8* %78
br label %79
79: ; preds = %65
%80 = load i32, i32* %5
%81 = add i32 %80, 1
store i32 %81, i32* %5
br label %60
82: ; preds = %60
br label %83
83: ; preds = %82, %47
br label %84
84: ; preds = %83
%85 = load i32, i32* %4
%86 = add i32 %85, 1
store i32 %86, i32* %4
br label %42
87: ; preds = %42
%88 = load i8*, i8** %2
%89 = load i8*, i8** %2
%90 = call i32 @strlen(i8* %89)
%91 = add nsw i32 %90, 1
%92 = sext i32 %91 to i64
%93 = mul i64 1, %92
%94 = trunc i64 %93 to i32
%95 = call i64 @realloc(i8* %88, i32 %94)
%96 = inttoptr i64 %95 to i8*
store i8* %96, i8** %2
br label %97
97: ; preds = %87, %39
%98 = load i8*, i8** %2
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %98)
%100 = load i32, i32* @stdin
%101 = call i32 @__fpurge(i32 %100)
%102 = call i32 (...) @getchar()
%103 = load i32, i32* %1
ret i32 %103
}

LLVM IR (-O2):
@.str = [29 x i8] c"Inserisci la prima stringa: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [31 x i8] c"Inserisci la seconda stringa: \00"
@stdin = global i32 0
@str = [7 x i8] c"ERRORE\00"
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 ([29 x i8], [29 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 ([31 x i8], [31 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* %16)
%18 = tail call i32 @strlen(i8* %10)
%19 = icmp sgt i32 %17, %18
br i1 %19, label %23, label %20
20: ; preds = %0
%21 = tail call i32 @strlen(i8* %10)
%22 = icmp eq i32 %21, 0
br i1 %22, label %59, label %25
23: ; preds = %0
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
br label %64
25: ; preds = %20, %53
%26 = phi i64 [ %54, %53 ], [ 0, %20 ]
%27 = phi i64 [ %58, %53 ], [ 1, %20 ]
%28 = trunc i64 %26 to i32
%29 = tail call i64 @Sub(i8* %10, i8* %16, i32 %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %25
%32 = add nuw nsw i64 %26, 1
br label %53
33: ; preds = %25
%34 = getelementptr inbounds i8, i8* %10, i64 %26
store i8 35, i8* %34
%35 = add nuw nsw i64 %26, 1
%36 = tail call i32 @strlen(i8* %10)
%37 = zext i32 %36 to i64
%38 = icmp ult i64 %35, %37
br i1 %38, label %39, label %53
39: ; preds = %33, %39
%40 = phi i64 [ %48, %39 ], [ %27, %33 ]
%41 = phi i32 [ %52, %39 ], [ %28, %33 ]
%42 = tail call i32 @strlen(i8* %16)
%43 = add i32 %42, %41
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %10, i64 %44
%46 = load i8, i8* %45
%47 = getelementptr inbounds i8, i8* %10, i64 %40
store i8 %46, i8* %47
%48 = add nuw nsw i64 %40, 1
%49 = trunc i64 %48 to i32
%50 = tail call i32 @strlen(i8* %10)
%51 = icmp ugt i32 %50, %49
%52 = trunc i64 %40 to i32
br i1 %51, label %39, label %53
53: ; preds = %39, %31, %33
%54 = phi i64 [ %32, %31 ], [ %35, %33 ], [ %35, %39 ]
%55 = tail call i32 @strlen(i8* %10)
%56 = zext i32 %55 to i64
%57 = icmp ult i64 %54, %56
%58 = add nuw nsw i64 %27, 1
br i1 %57, label %25, label %59
59: ; preds = %53, %20
%60 = tail call i32 @strlen(i8* %10)
%61 = add nsw i32 %60, 1
%62 = tail call i64 @realloc(i8* %10, i32 %61)
%63 = inttoptr i64 %62 to i8*
br label %64
64: ; preds = %59, %23
%65 = phi i8* [ %10, %23 ], [ %63, %59 ]
%66 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%67 = load i32, i32* @stdin
%68 = tail call i32 @__fpurge(i32 %67)
%69 = tail call i32 (...) @getchar()
ret i32 0
}