#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 */
struct Dynamic_Array {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ append_item(struct Dynamic_Array *, int);
struct Dynamic_Array *dynamic_array_create(int, int);
int /*<<< orphan*/ free_dynamic_array(struct Dynamic_Array *);
int has_item(struct Dynamic_Array *, int);
int /*<<< orphan*/ remove_item(struct Dynamic_Array *, int);
char *test_remove_item_exists(void) {
  struct Dynamic_Array *da = dynamic_array_create(2, 2);
  do {
    if (!(has_item(da, 5) == -1))
      return "item not present in the array";
  } while (0);
  append_item(da, 5);
  do {
    if (!(has_item(da, 5) == 0))
      return "item exists in the array";
  } while (0);
  remove_item(da, 5);
  do {
    if (!(has_item(da, 5) == -1))
      return "item was removed from the array";
  } while (0);
  free_dynamic_array(da);
  return 0;
}


x86 assembly (clang, -O0):
<test_remove_item_exists>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x2,%esi
mov    %esi,%edi
call   1030 <dynamic_array_create@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1060 <has_item@plt>
cmp    $0xffffffff,%eax
je     118f <test_remove_item_exists+0x3f>
lea    0xe7a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <test_remove_item_exists+0xc9>
jmp    1194 <test_remove_item_exists+0x44>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1070 <append_item@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1060 <has_item@plt>
cmp    $0x0,%eax
je     11c9 <test_remove_item_exists+0x79>
lea    0xe5e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <test_remove_item_exists+0xc9>
jmp    11ce <test_remove_item_exists+0x7e>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1050 <remove_item@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1060 <has_item@plt>
cmp    $0xffffffff,%eax
je     1203 <test_remove_item_exists+0xb3>
lea    0xe3d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1219 <test_remove_item_exists+0xc9>
jmp    1208 <test_remove_item_exists+0xb8>
mov    -0x10(%rbp),%rdi
call   1040 <free_dynamic_array@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_remove_item_exists>:
push   %rbx
mov    $0x2,%edi
mov    $0x2,%esi
call   1030 <dynamic_array_create@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x5,%esi
call   1060 <has_item@plt>
cmp    $0xffffffff,%eax
je     117e <test_remove_item_exists+0x2e>
lea    0xe84(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x5,%esi
call   1070 <append_item@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1060 <has_item@plt>
test   %eax,%eax
je     11a5 <test_remove_item_exists+0x55>
lea    0xe7b(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <remove_item@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1060 <has_item@plt>
cmp    $0xffffffff,%eax
je     11cd <test_remove_item_exists+0x7d>
lea    0xe6c(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <free_dynamic_array@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.Dynamic_Array = type { i32 }
@.str = [30 x i8] c"item not present in the array\00"
@.str.1 = [25 x i8] c"item exists in the array\00"
@.str.2 = [32 x i8] c"item was removed from the array\00"
define i8* @test_remove_item_exists() {
%1 = alloca i8*
%2 = alloca %struct.Dynamic_Array*
%3 = call %struct.Dynamic_Array* @dynamic_array_create(i32 2, i32 2)
store %struct.Dynamic_Array* %3, %struct.Dynamic_Array** %2
br label %4
4: ; preds = %0
%5 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%6 = call i32 @has_item(%struct.Dynamic_Array* %5, i32 5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %9, label %8
8: ; preds = %4
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8** %1
br label %31
9: ; preds = %4
br label %10
10: ; preds = %9
%11 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%12 = call i32 @append_item(%struct.Dynamic_Array* %11, i32 5)
br label %13
13: ; preds = %10
%14 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%15 = call i32 @has_item(%struct.Dynamic_Array* %14, i32 5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %31
18: ; preds = %13
br label %19
19: ; preds = %18
%20 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%21 = call i32 @remove_item(%struct.Dynamic_Array* %20, i32 5)
br label %22
22: ; preds = %19
%23 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%24 = call i32 @has_item(%struct.Dynamic_Array* %23, i32 5)
%25 = icmp eq i32 %24, -1
br i1 %25, label %27, label %26
26: ; preds = %22
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %31
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%30 = call i32 @free_dynamic_array(%struct.Dynamic_Array* %29)
store i8* null, i8** %1
br label %31
31: ; preds = %28, %26, %17, %8
%32 = load i8*, i8** %1
ret i8* %32
}

LLVM IR (-O2):
%struct.Dynamic_Array = type { i32 }
@.str = [30 x i8] c"item not present in the array\00"
@.str.1 = [25 x i8] c"item exists in the array\00"
@.str.2 = [32 x i8] c"item was removed from the array\00"
define i8* @test_remove_item_exists() {
%1 = tail call %struct.Dynamic_Array* @dynamic_array_create(i32 2, i32 2)
%2 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 5)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %14
4: ; preds = %0
%5 = tail call i32 @append_item(%struct.Dynamic_Array* %1, i32 5)
%6 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %4
%9 = tail call i32 @remove_item(%struct.Dynamic_Array* %1, i32 5)
%10 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 5)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = tail call i32 @free_dynamic_array(%struct.Dynamic_Array* %1)
br label %14
14: ; preds = %8, %4, %0, %12
%15 = phi i8* [ null, %12 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), %8 ]
ret i8* %15
}