#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_returns_index(void) {
  struct Dynamic_Array *da = dynamic_array_create(2, 2);
  do {
    if (!(has_item(da, 5) == -1))
      return "has_item does not detect item 5";
  } while (0);
  append_item(da, 5);
  do {
    if (!(has_item(da, 5) == 0))
      return "has_item returns index of item 5";
  } while (0);
  free_dynamic_array(da);
  return 0;
}


x86 assembly (clang, -O0):
<test_has_item_returns_index>:
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_returns_index+0x3f>
lea    0xe8a(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <test_has_item_returns_index+0x8f>
jmp    1184 <test_has_item_returns_index+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_returns_index+0x79>
lea    0xe70(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11cf <test_has_item_returns_index+0x8f>
jmp    11be <test_has_item_returns_index+0x7e>
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_returns_index>:
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_returns_index+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_returns_index+0x55>
lea    0xe8d(%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 = [32 x i8] c"has_item does not detect item 5\00"
@.str.1 = [33 x i8] c"has_item returns index of item 5\00"
define i8* @test_has_item_returns_index() {
%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 ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8** %1
br label %22
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 ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8** %1
br label %22
18: ; preds = %13
br label %19
19: ; preds = %18
%20 = load %struct.Dynamic_Array*, %struct.Dynamic_Array** %2
%21 = call i32 @free_dynamic_array(%struct.Dynamic_Array* %20)
store i8* null, i8** %1
br label %22
22: ; preds = %19, %17, %8
%23 = load i8*, i8** %1
ret i8* %23
}

LLVM IR (-O2):
%struct.Dynamic_Array = type { i32 }
@.str = [32 x i8] c"has_item does not detect item 5\00"
@.str.1 = [33 x i8] c"has_item returns index of item 5\00"
define i8* @test_has_item_returns_index() {
%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 %10
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 %10
8: ; preds = %4
%9 = tail call i32 @free_dynamic_array(%struct.Dynamic_Array* %1)
br label %10
10: ; preds = %4, %0, %8
%11 = phi i8* [ null, %8 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), %0 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %4 ]
ret i8* %11
}