#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);
int /*<<< orphan*/ clxns_iter_free(void *);
char *clxns_iter_get_next(void *);
scalar_t__ clxns_iter_move_next(void *);
void *clxns_iter_new(void *);
scalar_t__ malloc(int);
void *populate(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
scalar_t__ strcmp(char *, char *);
char *ra_add_adjust() {
  int num_entries = 30;
  void *array = populate(4, num_entries);
  int s = clxns_count(array);
  do {
    if (!(s == num_entries))
      return "Wrong number of items in array";
  } while (0);
  int i = 0;
  void *iter = clxns_iter_new(array);
  while (clxns_iter_move_next(iter)) {
    char *res = clxns_iter_get_next(iter);
    char *buf = (char *)malloc(9);
    sprintf(buf, "string%d", i++);
    do {
      if (!(strcmp(res, buf) == 0))
        return "Incorrect data in iter";
    } while (0);
  }
  do {
    if (!(i == 30))
      return "Incorrect iter count";
  } while (0);
  clxns_iter_free(iter);
  clxns_free(array, 1);
  return 0;
}


x86 assembly (clang, -O0):
<ra_add_adjust>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x1e,-0xc(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x4,%edi
call   1060 <populate@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <clxns_count@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11e8 <ra_add_adjust+0x48>
lea    0xe21(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12be <ra_add_adjust+0x11e>
jmp    11ed <ra_add_adjust+0x4d>
movl   $0x0,-0x20(%rbp)
mov    -0x18(%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     127b <ra_add_adjust+0xdb>
mov    -0x28(%rbp),%rdi
call   10b0 <clxns_iter_get_next@plt>
mov    %rax,-0x30(%rbp)
mov    $0x9,%edi
call   1090 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
lea    0xdda(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1271 <ra_add_adjust+0xd1>
lea    0xdc0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12be <ra_add_adjust+0x11e>
jmp    1276 <ra_add_adjust+0xd6>
jmp    1201 <ra_add_adjust+0x61>
jmp    1280 <ra_add_adjust+0xe0>
cmpl   $0x1e,-0x20(%rbp)
je     129a <ra_add_adjust+0xfa>
lea    0xdae(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12be <ra_add_adjust+0x11e>
jmp    129f <ra_add_adjust+0xff>
mov    -0x28(%rbp),%rdi
call   1040 <clxns_iter_free@plt>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
call   10a0 <clxns_free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ra_add_adjust>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x4,%edi
mov    $0x1e,%esi
call   1060 <populate@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <clxns_count@plt>
cmp    $0x1e,%eax
jne    1242 <ra_add_adjust+0xa2>
mov    %rbx,(%rsp)
mov    %rbx,%rdi
call   1030 <clxns_iter_new@plt>
mov    %rax,%r13
xor    %ebx,%ebx
lea    0xe3d(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1050 <clxns_iter_move_next@plt>
test   %rax,%rax
je     124b <ra_add_adjust+0xab>
mov    %r13,%rdi
call   10b0 <clxns_iter_get_next@plt>
mov    %rax,%rbp
mov    $0x9,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
lea    0x1(%rbx),%r15d
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   10c0 <sprintf@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
mov    %r15d,%ebx
test   %rax,%rax
je     11f0 <ra_add_adjust+0x50>
lea    0xde8(%rip),%rax
jmp    1271 <ra_add_adjust+0xd1>
lea    0xdb7(%rip),%rax
jmp    1271 <ra_add_adjust+0xd1>
cmp    $0x1e,%ebx
jne    126a <ra_add_adjust+0xca>
mov    %r13,%rdi
call   1040 <clxns_iter_free@plt>
mov    (%rsp),%rdi
mov    $0x1,%esi
call   10a0 <clxns_free@plt>
xor    %eax,%eax
jmp    1271 <ra_add_adjust+0xd1>
lea    0xdce(%rip),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [31 x i8] c"Wrong number of items in array\00"
@.str.1 = [9 x i8] c"string%d\00"
@.str.2 = [23 x i8] c"Incorrect data in iter\00"
@.str.3 = [21 x i8] c"Incorrect iter count\00"
define i8* @ra_add_adjust() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i32 30, i32* %2
%9 = load i32, i32* %2
%10 = call i8* @populate(i32 4, i32 %9)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @clxns_count(i8* %11)
store i32 %12, i32* %4
br label %13
13: ; preds = %0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp eq i32 %14, %15
br i1 %16, label %18, label %17
17: ; preds = %13
store i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8** %1
br label %54
18: ; preds = %13
br label %19
19: ; preds = %18
store i32 0, i32* %5
%20 = load i8*, i8** %3
%21 = call i8* @clxns_iter_new(i8* %20)
store i8* %21, i8** %6
br label %22
22: ; preds = %42, %19
%23 = load i8*, i8** %6
%24 = call i64 @clxns_iter_move_next(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %43
26: ; preds = %22
%27 = load i8*, i8** %6
%28 = call i8* @clxns_iter_get_next(i8* %27)
store i8* %28, i8** %7
%29 = call i64 @malloc(i32 9)
%30 = inttoptr i64 %29 to i8*
store i8* %30, i8** %8
%31 = load i8*, i8** %8
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
%34 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %35
35: ; preds = %26
%36 = load i8*, i8** %7
%37 = load i8*, i8** %8
%38 = call i64 @strcmp(i8* %36, i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %35
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %54
41: ; preds = %35
br label %42
42: ; preds = %41
br label %22
43: ; preds = %22
br label %44
44: ; preds = %43
%45 = load i32, i32* %5
%46 = icmp eq i32 %45, 30
br i1 %46, label %48, label %47
47: ; preds = %44
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %54
48: ; preds = %44
br label %49
49: ; preds = %48
%50 = load i8*, i8** %6
%51 = call i32 @clxns_iter_free(i8* %50)
%52 = load i8*, i8** %3
%53 = call i32 @clxns_free(i8* %52, i32 1)
store i8* null, i8** %1
br label %54
54: ; preds = %49, %47, %40, %17
%55 = load i8*, i8** %1
ret i8* %55
}

LLVM IR (-O2):
@.str = [31 x i8] c"Wrong number of items in array\00"
@.str.1 = [9 x i8] c"string%d\00"
@.str.2 = [23 x i8] c"Incorrect data in iter\00"
@.str.3 = [21 x i8] c"Incorrect iter count\00"
define i8* @ra_add_adjust() {
%1 = tail call i8* @populate(i32 4, i32 30)
%2 = tail call i32 @clxns_count(i8* %1)
%3 = icmp eq i32 %2, 30
br i1 %3, label %4, label %23
4: ; preds = %0
%5 = tail call i8* @clxns_iter_new(i8* %1)
br label %6
6: ; preds = %10, %4
%7 = phi i32 [ 0, %4 ], [ %14, %10 ]
%8 = tail call i64 @clxns_iter_move_next(i8* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %6
%11 = tail call i8* @clxns_iter_get_next(i8* %5)
%12 = tail call i64 @malloc(i32 9)
%13 = inttoptr i64 %12 to i8*
%14 = add nuw nsw i32 %7, 1
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %13, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%16 = tail call i64 @strcmp(i8* %11, i8* %13)
%17 = icmp eq i64 %16, 0
br i1 %17, label %6, label %23
18: ; preds = %6
%19 = icmp eq i32 %7, 30
br i1 %19, label %20, label %23
20: ; preds = %18
%21 = tail call i32 @clxns_iter_free(i8* %5)
%22 = tail call i32 @clxns_free(i8* %1, i32 1)
br label %23
23: ; preds = %10, %20, %18, %0
%24 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), %0 ], [ null, %20 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), %18 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %10 ]
ret i8* %24
}