; LLVM IR from jermp/2i_bench :: external/CRoaring/tests (array_container_unit)

; 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"

%struct.array_container_s = type { i32, i32, ptr }

@.str.1 = external hidden unnamed_addr constant [95 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [25 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

declare ptr @array_container_create() #1

declare void @_assert_true(i64 noundef, ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @array_container_add(ptr noundef, i16 noundef zeroext) #2

declare void @array_container_free(ptr noundef) #1

; 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 @capacity_test() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %4 = call ptr @array_container_create()
  store ptr %4, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %20, %0
  %6 = load i32, ptr %2, align 4, !tbaa !9
  %7 = icmp ult i32 %6, 4096
  br i1 %7, label %9, label %8

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

9:                                                ; preds = %5
  %10 = load ptr, ptr %1, align 8, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = trunc i32 %11 to i16
  %13 = call zeroext i1 @array_container_add(ptr noundef %10, i16 noundef zeroext %12)
  %14 = load ptr, ptr %1, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.array_container_s, ptr %14, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = icmp sle i32 %16, 4096
  %18 = zext i1 %17 to i32
  %19 = sext i32 %18 to i64
  call void @_assert_true(i64 noundef %19, ptr noundef @.str.18, ptr noundef @.str.1, i32 noundef 181)
  br label %20

20:                                               ; preds = %9
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = add i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !9
  br label %5, !llvm.loop !13

23:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 4096, ptr %3, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %39, %23
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = icmp ult i32 %25, 65536
  br i1 %26, label %28, label %27

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

28:                                               ; preds = %24
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = trunc i32 %30 to i16
  %32 = call zeroext i1 @array_container_add(ptr noundef %29, i16 noundef zeroext %31)
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.array_container_s, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !11
  %36 = icmp sle i32 %35, 65536
  %37 = zext i1 %36 to i32
  %38 = sext i32 %37 to i64
  call void @_assert_true(i64 noundef %38, ptr noundef @.str.19, ptr noundef @.str.1, i32 noundef 185)
  br label %39

39:                                               ; preds = %28
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = add i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !9
  br label %24, !llvm.loop !15

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 #2 = { inlinehint 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 #3 = { 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 #4 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4}
!12 = !{!"array_container_s", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 [95 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [25 x i8], align 1

declare ptr @array_container_create() local_unnamed_addr #0

declare void @_assert_true(i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @array_container_add(ptr noundef, i16 noundef zeroext) local_unnamed_addr #1

declare void @array_container_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @capacity_test() local_unnamed_addr #2 {
  %1 = tail call ptr @array_container_create() #3
  %2 = getelementptr inbounds i8, ptr %1, i64 4
  br label %3

3:                                                ; preds = %0, %3
  %.01011 = phi i32 [ 0, %0 ], [ %9, %3 ]
  %4 = trunc nuw nsw i32 %.01011 to i16
  %5 = tail call zeroext i1 @array_container_add(ptr noundef %1, i16 noundef zeroext %4)
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = icmp slt i32 %6, 4097
  %8 = zext i1 %7 to i64
  tail call void @_assert_true(i64 noundef %8, ptr noundef nonnull @.str.18, ptr noundef nonnull @.str.1, i32 noundef 181) #3
  %9 = add nuw nsw i32 %.01011, 1
  %exitcond.not = icmp eq i32 %9, 4096
  br i1 %exitcond.not, label %.preheader, label %3, !llvm.loop !11

10:                                               ; preds = %.preheader
  tail call void @array_container_free(ptr noundef nonnull %1) #3
  ret void

.preheader:                                       ; preds = %3, %.preheader
  %.012 = phi i32 [ %16, %.preheader ], [ 4096, %3 ]
  %11 = trunc nuw i32 %.012 to i16
  %12 = tail call zeroext i1 @array_container_add(ptr noundef nonnull %1, i16 noundef zeroext %11)
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 65537
  %15 = zext i1 %14 to i64
  tail call void @_assert_true(i64 noundef %15, ptr noundef nonnull @.str.19, ptr noundef nonnull @.str.1, i32 noundef 185) #3
  %16 = add nuw nsw i32 %.012, 1
  %exitcond13.not = icmp eq i32 %16, 65536
  br i1 %exitcond13.not, label %10, label %.preheader, !llvm.loop !13
}

attributes #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 #1 = { inlinehint 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 #2 = { 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 #3 = { 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, !7, i64 4}
!6 = !{!"array_container_s", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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