#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);
char *test_has_item_exists(void) {
  struct Dynamic_Array *da = dynamic_array_create(2, 2);
  do {
    if (!(has_item(da, 5) == -1))
      return "item 5 does not exist";
  } while (0);
  append_item(da, 5);
  do {
    if (!(has_item(da, 5) == 0))
      return "item 5 exist";
  } while (0);
  do {
    if (!(has_item(da, 15) == -1))
      return "item 15 does not exist";
  } while (0);
  append_item(da, 15);
  do {
    if (!(has_item(da, 15) == 1))
      return "item 15 exists";
  } while (0);
  do {
    if (!(has_item(da, 25) == -1))
      return "item 25 does not exist";
  } while (0);
  append_item(da, 25);
  do {
    if (!(has_item(da, 25) == 2))
      return "item 25 exists";
  } while (0);
  free_dynamic_array(da);
  return 0;
}


x86 assembly (clang, -O0):
<test_has_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   1050 <has_item@plt>
cmp    $0xffffffff,%eax
je     117f <test_has_item_exists+0x3f>
lea    0xe8a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <test_has_item_exists+0x165>
jmp    1184 <test_has_item_exists+0x44>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1060 <append_item@plt>
mov    -0x10(%rbp),%rdi
mov    $0x5,%esi
call   1050 <has_item@plt>
cmp    $0x0,%eax
je     11b9 <test_has_item_exists+0x79>
lea    0xe66(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <test_has_item_exists+0x165>
jmp    11be <test_has_item_exists+0x7e>
jmp    11c3 <test_has_item_exists+0x83>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
call   1050 <has_item@plt>
cmp    $0xffffffff,%eax
je     11ea <test_has_item_exists+0xaa>
lea    0xe42(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <test_has_item_exists+0x165>
jmp    11ef <test_has_item_exists+0xaf>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
call   1060 <append_item@plt>
mov    -0x10(%rbp),%rdi
mov    $0xf,%esi
call   1050 <has_item@plt>
cmp    $0x1,%eax
je     1224 <test_has_item_exists+0xe4>
lea    0xe1f(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <test_has_item_exists+0x165>
jmp    1229 <test_has_item_exists+0xe9>
jmp    122e <test_has_item_exists+0xee>
mov    -0x10(%rbp),%rdi
mov    $0x19,%esi
call   1050 <has_item@plt>
cmp    $0xffffffff,%eax
je     1255 <test_has_item_exists+0x115>
lea    0xdfd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <test_has_item_exists+0x165>
jmp    125a <test_has_item_exists+0x11a>
mov    -0x10(%rbp),%rdi
mov    $0x19,%esi
call   1060 <append_item@plt>
mov    -0x10(%rbp),%rdi
mov    $0x19,%esi
call   1050 <has_item@plt>
cmp    $0x2,%eax
je     128f <test_has_item_exists+0x14f>
lea    0xdda(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    12a5 <test_has_item_exists+0x165>
jmp    1294 <test_has_item_exists+0x154>
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_has_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   1050 <has_item@plt>
cmp    $0xffffffff,%eax
je     116e <test_has_item_exists+0x2e>
lea    0xe94(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x5,%esi
call   1060 <append_item@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <has_item@plt>
test   %eax,%eax
je     1195 <test_has_item_exists+0x55>
lea    0xe83(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0xf,%esi
call   1050 <has_item@plt>
cmp    $0xffffffff,%eax
je     11b0 <test_has_item_exists+0x70>
lea    0xe75(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0xf,%esi
call   1060 <append_item@plt>
mov    %rbx,%rdi
mov    $0xf,%esi
call   1050 <has_item@plt>
cmp    $0x1,%eax
jne    11ea <test_has_item_exists+0xaa>
mov    %rbx,%rdi
mov    $0x19,%esi
call   1050 <has_item@plt>
cmp    $0xffffffff,%eax
je     11f3 <test_has_item_exists+0xb3>
lea    0xe61(%rip),%rax
pop    %rbx
ret
lea    0xe49(%rip),%rax
pop    %rbx
ret
mov    %rbx,%rdi
mov    $0x19,%esi
call   1060 <append_item@plt>
mov    %rbx,%rdi
mov    $0x19,%esi
call   1050 <has_item@plt>
cmp    $0x2,%eax
jne    121e <test_has_item_exists+0xde>
mov    %rbx,%rdi
call   1040 <free_dynamic_array@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe3b(%rip),%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.Dynamic_Array = type { i32 }
@.str = [22 x i8] c"item 5 does not exist\00"
@.str.1 = [13 x i8] c"item 5 exist\00"
@.str.2 = [23 x i8] c"item 15 does not exist\00"
@.str.3 = [15 x i8] c"item 15 exists\00"
@.str.4 = [23 x i8] c"item 25 does not exist\00"
@.str.5 = [15 x i8] c"item 25 exists\00"
define i8* @test_has_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 ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8** %1
br label %54
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 ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %54
18: ; preds = %13
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19
%21 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%22 = call i32 @has_item(%struct.Dynamic_Array* %21, i32 15)
%23 = icmp eq i32 %22, -1
br i1 %23, label %25, label %24
24: ; preds = %20
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8** %1
br label %54
25: ; preds = %20
br label %26
26: ; preds = %25
%27 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%28 = call i32 @append_item(%struct.Dynamic_Array* %27, i32 15)
br label %29
29: ; preds = %26
%30 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%31 = call i32 @has_item(%struct.Dynamic_Array* %30, i32 15)
%32 = icmp eq i32 %31, 1
br i1 %32, label %34, label %33
33: ; preds = %29
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8** %1
br label %54
34: ; preds = %29
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
%37 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%38 = call i32 @has_item(%struct.Dynamic_Array* %37, i32 25)
%39 = icmp eq i32 %38, -1
br i1 %39, label %41, label %40
40: ; preds = %36
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8** %1
br label %54
41: ; preds = %36
br label %42
42: ; preds = %41
%43 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%44 = call i32 @append_item(%struct.Dynamic_Array* %43, i32 25)
br label %45
45: ; preds = %42
%46 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%47 = call i32 @has_item(%struct.Dynamic_Array* %46, i32 25)
%48 = icmp eq i32 %47, 2
br i1 %48, label %50, label %49
49: ; preds = %45
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8** %1
br label %54
50: ; preds = %45
br label %51
51: ; preds = %50
%52 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%53 = call i32 @free_dynamic_array(%struct.Dynamic_Array* %52)
store i8* null, i8** %1
br label %54
54: ; preds = %51, %49, %40, %33, %24, %17, %8
%55 = load i8*, i8** %1
ret i8* %55
}

LLVM IR (-O2):
%struct.Dynamic_Array = type { i32 }
@.str = [22 x i8] c"item 5 does not exist\00"
@.str.1 = [13 x i8] c"item 5 exist\00"
@.str.2 = [23 x i8] c"item 15 does not exist\00"
@.str.3 = [15 x i8] c"item 15 exists\00"
@.str.4 = [23 x i8] c"item 25 does not exist\00"
@.str.5 = [15 x i8] c"item 25 exists\00"
define i8* @test_has_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 %24
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 %24
8: ; preds = %4
%9 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 15)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %24
11: ; preds = %8
%12 = tail call i32 @append_item(%struct.Dynamic_Array* %1, i32 15)
%13 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 15)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 25)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = tail call i32 @append_item(%struct.Dynamic_Array* %1, i32 25)
%20 = tail call i32 @has_item(%struct.Dynamic_Array* %1, i32 25)
%21 = icmp eq i32 %20, 2
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = tail call i32 @free_dynamic_array(%struct.Dynamic_Array* %1)
br label %24
24: ; preds = %18, %15, %11, %8, %4, %0, %22
%25 = phi i8* [ null, %22 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %11 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), %15 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), %18 ]
ret i8* %25
}