#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 list {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct list *list_create();
int /*<<< orphan*/ list_destroy(struct list *);
int list_indexof(struct list *, char *);
int /*<<< orphan*/ list_insert(struct list *, char *);
void test_indexof() {
  int i;
  char ref[4] = {'a', 'b', 'c', 'd'};
  struct list *l = list_create();
  assert(list_indexof(l, &ref[2]) == -1);
  for (i = 0; i < 4; i++)
    list_insert(l, &ref[i]);
  for (i = 0; i < 4; i++)
    assert(list_indexof(l, &ref[i]) == i);
  list_destroy(l);
}


x86 assembly (clang, -O0):
<test_indexof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0xea2(%rip),%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <list_create@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
add    $0x2,%rsi
call   1060 <list_indexof@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    11c0 <test_indexof+0x70>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
lea    -0x8(%rbp),%rsi
add    %rax,%rsi
call   1070 <list_insert@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1194 <test_indexof+0x44>
movl   $0x0,-0x4(%rbp)
cmpl   $0x4,-0x4(%rbp)
jge    1203 <test_indexof+0xb3>
mov    -0x10(%rbp),%rdi
movslq -0x4(%rbp),%rax
lea    -0x8(%rbp),%rsi
add    %rax,%rsi
call   1060 <list_indexof@plt>
cmp    -0x4(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <test_indexof+0x77>
mov    -0x10(%rbp),%rdi
call   1040 <list_destroy@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_indexof>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
movl   $0x64636261,0xc(%rsp)
64
xor    %eax,%eax
call   1030 <list_create@plt>
mov    %rax,%rbx
lea    0xe(%rsp),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <list_indexof@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
sete   %dil
call   1050 <assert@plt>
lea    0xc(%rsp),%r13
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <list_insert@plt>
lea    0xd(%rsp),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1070 <list_insert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <list_insert@plt>
lea    0xf(%rsp),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <list_insert@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <list_indexof@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <list_indexof@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <list_indexof@plt>
xor    %edi,%edi
cmp    $0x2,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <list_indexof@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <list_destroy@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.list = type { i32 }
@__const.test_indexof.ref = [4 x i8] c"abcd"
define void @test_indexof() {
%1 = alloca i32
%2 = alloca [4 x i8]
%3 = alloca %struct.list*
%4 = bitcast [4 x i8]* %2 to i8*
%5 = call %struct.list* (...) @list_create()
store %struct.list* %5, %struct.list** %3
%6 = load %struct.list*, %struct.list** %3
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%8 = call i32 @list_indexof(%struct.list* %6, i8* %7)
%9 = icmp eq i32 %8, -1
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
store i32 0, i32* %1
br label %12
12: ; preds = %21, %0
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load %struct.list*, %struct.list** %3
%17 = load i32, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %18
%20 = call i32 @list_insert(%struct.list* %16, i8* %19)
br label %21
21: ; preds = %15
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %12
24: ; preds = %12
store i32 0, i32* %1
br label %25
25: ; preds = %38, %24
%26 = load i32, i32* %1
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %41
28: ; preds = %25
%29 = load %struct.list*, %struct.list** %3
%30 = load i32, i32* %1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 %31
%33 = call i32 @list_indexof(%struct.list* %29, i8* %32)
%34 = load i32, i32* %1
%35 = icmp eq i32 %33, %34
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
br label %38
38: ; preds = %28
%39 = load i32, i32* %1
%40 = add nsw i32 %39, 1
store i32 %40, i32* %1
br label %25
41: ; preds = %25
%42 = load %struct.list*, %struct.list** %3
%43 = call i32 @list_destroy(%struct.list* %42)
ret void
}

LLVM IR (-O2):
%struct.list = type { i32 }
define void @test_indexof() {
%1 = alloca i32
%2 = bitcast i32* %1 to [4 x i8]*
%3 = bitcast i32* %1 to i8*
store i32 1684234849, i32* %1
%4 = tail call %struct.list* (...) @list_create()
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 2
%6 = call i32 @list_indexof(%struct.list* %4, i8* %5)
%7 = icmp eq i32 %6, -1
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = bitcast i32* %1 to i8*
%11 = call i32 @list_insert(%struct.list* %4, i8* %10)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 1
%13 = call i32 @list_insert(%struct.list* %4, i8* %12)
%14 = call i32 @list_insert(%struct.list* %4, i8* %5)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
%16 = call i32 @list_insert(%struct.list* %4, i8* %15)
%17 = call i32 @list_indexof(%struct.list* %4, i8* %10)
%18 = icmp eq i32 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 @assert(i32 %19)
%21 = call i32 @list_indexof(%struct.list* %4, i8* %12)
%22 = icmp eq i32 %21, 1
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i32 @list_indexof(%struct.list* %4, i8* %5)
%26 = icmp eq i32 %25, 2
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = call i32 @list_indexof(%struct.list* %4, i8* %15)
%30 = icmp eq i32 %29, 3
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @list_destroy(%struct.list* %4)
ret void
}