#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*/ assert(int /*<<< orphan*/);
int len(char *);
char *malloc(int);
int /*<<< orphan*/ memmove(char *, char *, int);
char *ncpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, char *);
char *realloc(char *, int);
char *rm(char *str, int start, int end) {
  int wlen = end - start;
  char *word = malloc((wlen + 1) * sizeof(char));
  word = ncpy(word, (str + start), wlen);
  printf("\nremoving word %s", word);
  int slen = len(str);
  char *before = str + start;
  char *after = str + end;
  memmove(before, after, (len(after) + 1) * sizeof(char));
  int newsize = (slen - wlen <= 0) ? 1 : slen - wlen;
  char *temp = realloc(str, newsize);
  assert(temp != NULL);
  str = temp;
  return str;
}


x86 assembly (clang, -O0):
<rm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
call   1090 <ncpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe38(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <len@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <len@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edx
call   1080 <memmove@plt>
mov    -0x24(%rbp),%eax
sub    -0x14(%rbp),%eax
cmp    $0x0,%eax
jg     1244 <rm+0xd4>
mov    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    124d <rm+0xdd>
mov    -0x24(%rbp),%eax
sub    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x3c(%rbp),%esi
call   1070 <realloc@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rm>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r14
mov    %edx,%r12d
sub    %esi,%r12d
lea    0x1(%r12),%edi
call   1060 <malloc@plt>
movslq %ebp,%r13
add    %r14,%r13
mov    %rax,%rdi
mov    %r13,%rsi
mov    %r12d,%edx
call   1090 <ncpy@plt>
lea    0xe52(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <len@plt>
mov    %eax,%ebx
movslq %r15d,%rbp
add    %r14,%rbp
mov    %rbp,%rdi
call   1030 <len@plt>
lea    0x1(%rax),%edx
mov    %r13,%rdi
mov    %rbp,%rsi
call   1080 <memmove@plt>
sub    %r12d,%ebx
test   %ebx,%ebx
mov    $0x1,%esi
cmovg  %ebx,%esi
mov    %r14,%rdi
call   1070 <realloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"\0Aremoving word %s\00"
define i8* @rm(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%14 = load i32, i32* %6
%15 = load i32, i32* %5
%16 = sub nsw i32 %14, %15
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 1
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = load i8*, i8** %4
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %7
%29 = call i8* @ncpy(i8* %23, i8* %27, i32 %28)
store i8* %29, i8** %8
%30 = load i8*, i8** %8
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = load i8*, i8** %4
%33 = call i32 @len(i8* %32)
store i32 %33, i32* %9
%34 = load i8*, i8** %4
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8* %37, i8** %10
%38 = load i8*, i8** %4
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8* %41, i8** %11
%42 = load i8*, i8** %10
%43 = load i8*, i8** %11
%44 = load i8*, i8** %11
%45 = call i32 @len(i8* %44)
%46 = add nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = mul i64 %47, 1
%49 = trunc i64 %48 to i32
%50 = call i32 @memmove(i8* %42, i8* %43, i32 %49)
%51 = load i32, i32* %9
%52 = load i32, i32* %7
%53 = sub nsw i32 %51, %52
%54 = icmp sle i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %3
br label %60
56: ; preds = %3
%57 = load i32, i32* %9
%58 = load i32, i32* %7
%59 = sub nsw i32 %57, %58
br label %60
60: ; preds = %56, %55
%61 = phi i32 [ 1, %55 ], [ %59, %56 ]
store i32 %61, i32* %12
%62 = load i8*, i8** %4
%63 = load i32, i32* %12
%64 = call i8* @realloc(i8* %62, i32 %63)
store i8* %64, i8** %13
%65 = load i8*, i8** %13
%66 = icmp ne i8* %65, null
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = load i8*, i8** %13
store i8* %69, i8** %4
%70 = load i8*, i8** %4
ret i8* %70
}

LLVM IR (-O2):
@.str = [18 x i8] c"\0Aremoving word %s\00"
define i8* @rm(i8* %0, i32 %1, i32 %2) {
%4 = sub nsw i32 %2, %1
%5 = add nsw i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = tail call i8* @ncpy(i8* %6, i8* %8, i32 %4)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @len(i8* %0)
%12 = sext i32 %2 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = tail call i32 @len(i8* %13)
%15 = add nsw i32 %14, 1
%16 = tail call i32 @memmove(i8* %8, i8* %13, i32 %15)
%17 = sub nsw i32 %11, %4
%18 = icmp sgt i32 %17, 1
%19 = select i1 %18, i32 %17, i32 1
%20 = tail call i8* @realloc(i8* %0, i32 %19)
%21 = icmp ne i8* %20, null
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
ret i8* %20
}