#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 clxns_count(void *);
int /*<<< orphan*/ clxns_free(void *, int /*<<< orphan*/);
int /*<<< orphan*/ clxns_iter_free(void *);
char *clxns_iter_get_next(void *);
scalar_t__ clxns_iter_move_next(void *);
void *clxns_iter_new(void *);
void *resize_array(int /*<<< orphan*/);
int /*<<< orphan*/ resize_array_add(void *, char *);
int /*<<< orphan*/ resize_array_replace(void *, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
char *ra_replace() {
  void *array = resize_array(0);
  resize_array_add(array, "stringx");
  resize_array_add(array, "string1");
  resize_array_add(array, "string2");
  resize_array_add(array, "stringx");
  resize_array_add(array, "string4");
  resize_array_add(array, "stringx");
  resize_array_replace(array, 0, "string0");
  resize_array_replace(array, 3, "string3");
  resize_array_replace(array, 5, "string5");
  int s = clxns_count(array);
  do {
    if (!(s == 6))
      return "Wrong number of items in array after replace";
  } while (0);
  char buf[8];
  int i = 0;
  void *iter = clxns_iter_new(array);
  while (clxns_iter_move_next(iter)) {
    char *res = clxns_iter_get_next(iter);
    sprintf(buf, "string%d", i++);
    do {
      if (!(!strcmp(res, buf)))
        return "Incorrect data in iter after replace";
    } while (0);
  }
  do {
    if (!(i == 6))
      return "Incorrect iter count after replace";
  } while (0);
  clxns_iter_free(iter);
  clxns_free(array, 0);
  return 0;
}


x86 assembly (clang, -O0):
<ra_replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %edi,%edi
call   1060 <resize_array@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   10d0 <resize_array_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe2a(%rip),%rsi
call   10d0 <resize_array_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   10d0 <resize_array_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   10d0 <resize_array_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   10d0 <resize_array_add@plt>
mov    -0x10(%rbp),%rdi
lea    0xde2(%rip),%rsi
call   10d0 <resize_array_add@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    0xdf0(%rip),%rdx
call   10b0 <resize_array_replace@plt>
mov    -0x10(%rbp),%rdi
mov    $0x3,%esi
lea    0xde3(%rip),%rdx
call   10b0 <resize_array_replace@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
lea    0xdd6(%rip),%rdx
call   10b0 <resize_array_replace@plt>
mov    -0x10(%rbp),%rdi
call   1080 <clxns_count@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x6,-0x14(%rbp)
je     1285 <ra_replace+0xd5>
lea    0xdbc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1349 <ra_replace+0x199>
jmp    128a <ra_replace+0xda>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <clxns_iter_new@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <clxns_iter_move_next@plt>
cmp    $0x0,%rax
je     1309 <ra_replace+0x159>
mov    -0x28(%rbp),%rdi
call   10a0 <clxns_iter_get_next@plt>
mov    %rax,-0x30(%rbp)
lea    -0x1c(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
lea    0xd91(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12ff <ra_replace+0x14f>
lea    0xd78(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1349 <ra_replace+0x199>
jmp    1304 <ra_replace+0x154>
jmp    129e <ra_replace+0xee>
jmp    130e <ra_replace+0x15e>
cmpl   $0x6,-0x20(%rbp)
je     1328 <ra_replace+0x178>
lea    0xd74(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1349 <ra_replace+0x199>
jmp    132d <ra_replace+0x17d>
mov    -0x28(%rbp),%rdi
call   1040 <clxns_iter_free@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1090 <clxns_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ra_replace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
xor    %edi,%edi
call   1060 <resize_array@plt>
mov    %rax,%r14
lea    0xe32(%rip),%rbp
mov    %rax,%rdi
mov    %rbp,%rsi
call   10d0 <resize_array_add@plt>
lea    0xe28(%rip),%rsi
mov    %r14,%rdi
call   10d0 <resize_array_add@plt>
lea    0xe21(%rip),%rsi
mov    %r14,%rdi
call   10d0 <resize_array_add@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10d0 <resize_array_add@plt>
lea    0xe0f(%rip),%rsi
mov    %r14,%rdi
call   10d0 <resize_array_add@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   10d0 <resize_array_add@plt>
lea    0xdfd(%rip),%rdx
mov    %r14,%rdi
xor    %esi,%esi
call   10b0 <resize_array_replace@plt>
lea    0xdf4(%rip),%rdx
mov    %r14,%rdi
mov    $0x3,%esi
call   10b0 <resize_array_replace@plt>
lea    0xde8(%rip),%rdx
mov    %r14,%rdi
mov    $0x5,%esi
call   10b0 <resize_array_replace@plt>
mov    %r14,%rdi
call   1080 <clxns_count@plt>
cmp    $0x6,%eax
jne    12b8 <ra_replace+0x108>
mov    %r14,%rdi
call   1030 <clxns_iter_new@plt>
mov    %rax,%r12
mov    %rsp,%rbp
mov    %r12,%rdi
call   1050 <clxns_iter_move_next@plt>
test   %rax,%rax
je     12c1 <ra_replace+0x111>
mov    %r12,%rdi
call   10a0 <clxns_iter_get_next@plt>
mov    %rax,%r15
lea    0x1(%rbx),%r13d
mov    %rbp,%rdi
lea    0xdcf(%rip),%rsi
mov    %ebx,%edx
call   10c0 <sprintf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
mov    %r13d,%ebx
test   %eax,%eax
je     1270 <ra_replace+0xc0>
lea    0xdb8(%rip),%rbx
jmp    12e3 <ra_replace+0x133>
lea    0xd79(%rip),%rbx
jmp    12e3 <ra_replace+0x133>
cmp    $0x6,%ebx
jne    12dc <ra_replace+0x12c>
mov    %r12,%rdi
call   1040 <clxns_iter_free@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1090 <clxns_free@plt>
jmp    12e3 <ra_replace+0x133>
lea    0xdb0(%rip),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"stringx\00"
@.str.1 = [8 x i8] c"string1\00"
@.str.2 = [8 x i8] c"string2\00"
@.str.3 = [8 x i8] c"string4\00"
@.str.4 = [8 x i8] c"string0\00"
@.str.5 = [8 x i8] c"string3\00"
@.str.6 = [8 x i8] c"string5\00"
@.str.7 = [45 x i8] c"Wrong number of items in array after replace\00"
@.str.8 = [9 x i8] c"string%d\00"
@.str.9 = [37 x i8] c"Incorrect data in iter after replace\00"
@.str.10 = [35 x i8] c"Incorrect iter count after replace\00"
define i8* @ra_replace() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [8 x i8]
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = call i8* @resize_array(i32 0)
store i8* %8, i8** %2
%9 = load i8*, i8** %2
%10 = call i32 @resize_array_add(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%11 = load i8*, i8** %2
%12 = call i32 @resize_array_add(i8* %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%13 = load i8*, i8** %2
%14 = call i32 @resize_array_add(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %2
%16 = call i32 @resize_array_add(i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %2
%18 = call i32 @resize_array_add(i8* %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = call i32 @resize_array_add(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%21 = load i8*, i8** %2
%22 = call i32 @resize_array_replace(i8* %21, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%23 = load i8*, i8** %2
%24 = call i32 @resize_array_replace(i8* %23, i32 3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%25 = load i8*, i8** %2
%26 = call i32 @resize_array_replace(i8* %25, i32 5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%27 = load i8*, i8** %2
%28 = call i32 @clxns_count(i8* %27)
store i32 %28, i32* %3
br label %29
29: ; preds = %0
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, 6
br i1 %31, label %33, label %32
32: ; preds = %29
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), i8** %1
br label %67
33: ; preds = %29
br label %34
34: ; preds = %33
store i32 0, i32* %5
%35 = load i8*, i8** %2
%36 = call i8* @clxns_iter_new(i8* %35)
store i8* %36, i8** %6
br label %37
37: ; preds = %55, %34
%38 = load i8*, i8** %6
%39 = call i64 @clxns_iter_move_next(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %56
41: ; preds = %37
%42 = load i8*, i8** %6
%43 = call i8* @clxns_iter_get_next(i8* %42)
store i8* %43, i8** %7
%44 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
%47 = call i32 @sprintf(i8* %44, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %45)
br label %48
48: ; preds = %41
%49 = load i8*, i8** %7
%50 = getelementptr inbounds [8 x i8], [8 x i8]* %4, i64 0, i64 0
%51 = call i32 @strcmp(i8* %49, i8* %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %48
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), i8** %1
br label %67
54: ; preds = %48
br label %55
55: ; preds = %54
br label %37
56: ; preds = %37
br label %57
57: ; preds = %56
%58 = load i32, i32* %5
%59 = icmp eq i32 %58, 6
br i1 %59, label %61, label %60
60: ; preds = %57
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), i8** %1
br label %67
61: ; preds = %57
br label %62
62: ; preds = %61
%63 = load i8*, i8** %6
%64 = call i32 @clxns_iter_free(i8* %63)
%65 = load i8*, i8** %2
%66 = call i32 @clxns_free(i8* %65, i32 0)
store i8* null, i8** %1
br label %67
67: ; preds = %62, %60, %53, %32
%68 = load i8*, i8** %1
ret i8* %68
}

LLVM IR (-O2):
@.str = [8 x i8] c"stringx\00"
@.str.1 = [8 x i8] c"string1\00"
@.str.2 = [8 x i8] c"string2\00"
@.str.3 = [8 x i8] c"string4\00"
@.str.4 = [8 x i8] c"string0\00"
@.str.5 = [8 x i8] c"string3\00"
@.str.6 = [8 x i8] c"string5\00"
@.str.7 = [45 x i8] c"Wrong number of items in array after replace\00"
@.str.8 = [9 x i8] c"string%d\00"
@.str.9 = [37 x i8] c"Incorrect data in iter after replace\00"
@.str.10 = [35 x i8] c"Incorrect iter count after replace\00"
define i8* @ra_replace() {
%1 = alloca [8 x i8]
%2 = tail call i8* @resize_array(i32 0)
%3 = tail call i32 @resize_array_add(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @resize_array_add(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @resize_array_add(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @resize_array_add(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @resize_array_add(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @resize_array_add(i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @resize_array_replace(i8* %2, i32 0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%10 = tail call i32 @resize_array_replace(i8* %2, i32 3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%11 = tail call i32 @resize_array_replace(i8* %2, i32 5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%12 = tail call i32 @clxns_count(i8* %2)
%13 = icmp eq i32 %12, 6
br i1 %13, label %14, label %34
14: ; preds = %0
%15 = getelementptr inbounds [8 x i8], [8 x i8]* %1, i64 0, i64 0
%16 = tail call i8* @clxns_iter_new(i8* %2)
br label %17
17: ; preds = %21, %14
%18 = phi i32 [ 0, %14 ], [ %23, %21 ]
%19 = tail call i64 @clxns_iter_move_next(i8* %16)
%20 = icmp eq i64 %19, 0
br i1 %20, label %27, label %21
21: ; preds = %17
%22 = tail call i8* @clxns_iter_get_next(i8* %16)
%23 = add nuw nsw i32 %18, 1
%24 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 %18)
%25 = call i32 @strcmp(i8* dereferenceable(1) %22, i8* %15)
%26 = icmp eq i32 %25, 0
br i1 %26, label %17, label %32
27: ; preds = %17
%28 = icmp eq i32 %18, 6
br i1 %28, label %29, label %32
29: ; preds = %27
%30 = tail call i32 @clxns_iter_free(i8* %16)
%31 = tail call i32 @clxns_free(i8* %2, i32 0)
br label %32
32: ; preds = %21, %27, %29
%33 = phi i8* [ null, %29 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.10, i64 0, i64 0), %27 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.9, i64 0, i64 0), %21 ]
br label %34
34: ; preds = %0, %32
%35 = phi i8* [ %33, %32 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.7, i64 0, i64 0), %0 ]
ret i8* %35
}