; LLVM IR from hutusi/rethink-c :: test (test_arraylist)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__const.test_arraylist_index_of.entries = external hidden unnamed_addr constant [10 x i32], align 16
@.str.19 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.test_arraylist_index_of = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare ptr @arraylist_new(ptr noundef, i32 noundef) #2

declare i32 @arraylist_append(ptr noundef, ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare void @arraylist_free(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @test_arraylist_index_of() #4 {
  %1 = alloca [10 x i32], align 16
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 40, ptr %1) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %1, ptr align 16 @__const.test_arraylist_index_of.entries, i64 40, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 10, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = call ptr @arraylist_new(ptr noundef null, i32 noundef %6)
  store ptr %7, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %19, %0
  %9 = load i32, ptr %4, align 4, !tbaa !5
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %22

13:                                               ; preds = %8
  %14 = load ptr, ptr %3, align 8, !tbaa !9
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10 x i32], ptr %1, i64 0, i64 %16
  %18 = call i32 @arraylist_append(ptr noundef %14, ptr noundef %17)
  br label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %4, align 4, !tbaa !5
  br label %8, !llvm.loop !11

22:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %39, %22
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %42

28:                                               ; preds = %23
  %29 = load ptr, ptr %3, align 8, !tbaa !9
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10 x i32], ptr %1, i64 0, i64 %31
  %33 = call i32 @arraylist_index_of(ptr noundef %29, ptr noundef @int_compare, ptr noundef %32)
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = icmp eq i32 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %28
  br label %38

37:                                               ; preds = %28
  call void @__assert_fail(ptr noundef @.str.19, ptr noundef @.str.1, i32 noundef 61, ptr noundef @__PRETTY_FUNCTION__.test_arraylist_index_of) #6
  unreachable

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !5
  br label %23, !llvm.loop !13

42:                                               ; preds = %27
  %43 = load ptr, ptr %3, align 8, !tbaa !9
  call void @arraylist_free(ptr noundef %43)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %1) #5
  ret void
}

declare i32 @arraylist_index_of(ptr noundef, ptr noundef, ptr noundef) #2

declare i32 @int_compare(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { noreturn nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }
attributes #6 = { noreturn nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@.str.1 = external hidden unnamed_addr constant [72 x i8], align 1
@__const.test_arraylist_index_of.entries = external hidden unnamed_addr constant [10 x i32], align 16
@.str.19 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.test_arraylist_index_of = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare ptr @arraylist_new(ptr noundef, i32 noundef) local_unnamed_addr #2

declare i32 @arraylist_append(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @arraylist_free(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
define dso_local void @test_arraylist_index_of() local_unnamed_addr #4 {
.preheader.preheader:
  %0 = alloca [10 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr noundef nonnull align 16 dereferenceable(40) @__const.test_arraylist_index_of.entries, i64 40, i1 false)
  %1 = tail call ptr @arraylist_new(ptr noundef null, i32 noundef 10) #5
  %2 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %0) #5
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %3) #5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %5) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 12
  %8 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %7) #5
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %9) #5
  %11 = getelementptr inbounds i8, ptr %0, i64 20
  %12 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %11) #5
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %13) #5
  %15 = getelementptr inbounds i8, ptr %0, i64 28
  %16 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %15) #5
  %17 = getelementptr inbounds i8, ptr %0, i64 32
  %18 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %17) #5
  %19 = getelementptr inbounds i8, ptr %0, i64 36
  %20 = call i32 @arraylist_append(ptr noundef %1, ptr noundef nonnull %19) #5
  %21 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %0) #5
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %.preheader.1, label %42

.preheader.1:                                     ; preds = %.preheader.preheader
  %23 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %3) #5
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %.preheader.2, label %42

.preheader.2:                                     ; preds = %.preheader.1
  %25 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %5) #5
  %26 = icmp eq i32 %25, 2
  br i1 %26, label %.preheader.3, label %42

.preheader.3:                                     ; preds = %.preheader.2
  %27 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %7) #5
  %28 = icmp eq i32 %27, 3
  br i1 %28, label %.preheader.4, label %42

.preheader.4:                                     ; preds = %.preheader.3
  %29 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %9) #5
  %30 = icmp eq i32 %29, 4
  br i1 %30, label %.preheader.5, label %42

.preheader.5:                                     ; preds = %.preheader.4
  %31 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %11) #5
  %32 = icmp eq i32 %31, 5
  br i1 %32, label %.preheader.6, label %42

.preheader.6:                                     ; preds = %.preheader.5
  %33 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %13) #5
  %34 = icmp eq i32 %33, 6
  br i1 %34, label %.preheader.7, label %42

.preheader.7:                                     ; preds = %.preheader.6
  %35 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %15) #5
  %36 = icmp eq i32 %35, 7
  br i1 %36, label %.preheader.8, label %42

.preheader.8:                                     ; preds = %.preheader.7
  %37 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %17) #5
  %38 = icmp eq i32 %37, 8
  br i1 %38, label %.preheader.9, label %42

.preheader.9:                                     ; preds = %.preheader.8
  %39 = call i32 @arraylist_index_of(ptr noundef %1, ptr noundef nonnull @int_compare, ptr noundef nonnull %19) #5
  %40 = icmp eq i32 %39, 9
  br i1 %40, label %41, label %42

41:                                               ; preds = %.preheader.9
  call void @arraylist_free(ptr noundef %1) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %0) #5
  ret void

42:                                               ; preds = %.preheader.9, %.preheader.8, %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  call void @__assert_fail(ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.1, i32 noundef 61, ptr noundef nonnull @__PRETTY_FUNCTION__.test_arraylist_index_of) #6
  unreachable
}

declare i32 @arraylist_index_of(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @int_compare(ptr noundef, ptr noundef) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { noreturn nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { nounwind }
attributes #6 = { noreturn nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass