#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*/ CU_ASSERT(int);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ substr_replace(char **, int *, int *, int, int, char *,
                                  int /*<<< orphan*/);
void test_substr_replace_lenchange(void) {
  char *source = strdup("hello world test");
  int len = strlen(source);
  int size = len + 1;
  CU_ASSERT(len == 16);
  substr_replace(&source, &len, &size, 5, len, "", 0);
  CU_ASSERT(len == 5);
}


x86 assembly (clang, -O0):
<test_substr_replace_lenchange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x10,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <CU_ASSERT@plt>
mov    -0xc(%rbp),%r8d
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x5,%ecx
lea    0xe76(%rip),%r9
xor    %eax,%eax
movl   $0x0,(%rsp)
call   1030 <substr_replace@plt>
cmpl   $0x5,-0xc(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <CU_ASSERT@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_substr_replace_lenchange>:
push   %rbx
sub    $0x20,%rsp
lea    0xeb4(%rip),%rdi
call   1060 <strdup@plt>
mov    %rax,0x18(%rsp)
mov    %rax,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %eax,0x10(%rsp)
lea    0x1(%rbx),%eax
mov    %eax,0x14(%rsp)
xor    %edi,%edi
cmp    $0x10,%ebx
sete   %dil
call   1050 <CU_ASSERT@plt>
movl   $0x0,(%rsp)
lea    0xe89(%rip),%r9
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    $0x5,%ecx
mov    %ebx,%r8d
call   1030 <substr_replace@plt>
xor    %edi,%edi
cmpl   $0x5,0x10(%rsp)
sete   %dil
call   1050 <CU_ASSERT@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"hello world test\00"
@.str.1 = [1 x i8] zeroinitializer
define void @test_substr_replace_lenchange() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = call i8* @strdup(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = add nsw i32 %7, 1
store i32 %8, i32* %3
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 16
%11 = zext i1 %10 to i32
%12 = call i32 @CU_ASSERT(i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @substr_replace(i8** %1, i32* %2, i32* %3, i32 5, i32 %13, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 0)
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 5
%17 = zext i1 %16 to i32
%18 = call i32 @CU_ASSERT(i32 %17)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"hello world test\00"
@.str.1 = [1 x i8] zeroinitializer
define void @test_substr_replace_lenchange() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i8** %1 to i8*
%5 = tail call dereferenceable_or_null(17) i8* @strdup(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = bitcast i32* %2 to i8*
%7 = tail call i32 @strlen(i8* %5)
store i32 %7, i32* %2
%8 = bitcast i32* %3 to i8*
%9 = add nsw i32 %7, 1
store i32 %9, i32* %3
%10 = icmp eq i32 %7, 16
%11 = zext i1 %10 to i32
%12 = tail call i32 @CU_ASSERT(i32 %11)
%13 = call i32 @substr_replace(i8** %1, i32* %2, i32* %3, i32 5, i32 %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i32 0)
%14 = load i32, i32* %2
%15 = icmp eq i32 %14, 5
%16 = zext i1 %15 to i32
%17 = call i32 @CU_ASSERT(i32 %16)
ret void
}