; LLVM IR from solettaproject/soletta-machine-learning :: sml/sml_fuzzy/src (sml_bit_array)

; 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.sml_bit_array = type { i16, ptr }

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sml_bit_array_set(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @sml_bit_array_get(ptr noundef, i16 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @sml_bit_array_size_set(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @sml_bit_array_remove(ptr noundef %0, i16 noundef zeroext %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #2
  %8 = load i16, ptr %5, align 2, !tbaa !9
  %9 = zext i16 %8 to i32
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.sml_bit_array, ptr %10, i32 0, i32 0
  %12 = load i16, ptr %11, align 8, !tbaa !11
  %13 = zext i16 %12 to i32
  %14 = icmp sge i32 %9, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 -22, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

16:                                               ; preds = %2
  %17 = load i16, ptr %5, align 2, !tbaa !9
  store i16 %17, ptr %6, align 2, !tbaa !9
  br label %18

18:                                               ; preds = %37, %16
  %19 = load i16, ptr %6, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sml_bit_array, ptr %21, i32 0, i32 0
  %23 = load i16, ptr %22, align 8, !tbaa !11
  %24 = zext i16 %23 to i32
  %25 = sub nsw i32 %24, 1
  %26 = icmp slt i32 %20, %25
  br i1 %26, label %27, label %40

27:                                               ; preds = %18
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i16, ptr %6, align 2, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i16, ptr %6, align 2, !tbaa !9
  %32 = zext i16 %31 to i32
  %33 = add nsw i32 %32, 1
  %34 = trunc i32 %33 to i16
  %35 = call zeroext i8 @sml_bit_array_get(ptr noundef %30, i16 noundef zeroext %34)
  %36 = call zeroext i1 @sml_bit_array_set(ptr noundef %28, i16 noundef zeroext %29, i8 noundef zeroext %35)
  br label %37

37:                                               ; preds = %27
  %38 = load i16, ptr %6, align 2, !tbaa !9
  %39 = add i16 %38, 1
  store i16 %39, ptr %6, align 2, !tbaa !9
  br label %18, !llvm.loop !13

40:                                               ; preds = %18
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.sml_bit_array, ptr %42, i32 0, i32 0
  %44 = load i16, ptr %43, align 8, !tbaa !11
  %45 = zext i16 %44 to i32
  %46 = sub nsw i32 %45, 1
  %47 = trunc i32 %46 to i16
  %48 = call i32 @sml_bit_array_size_set(ptr noundef %41, i16 noundef zeroext %47, i8 noundef zeroext 0)
  store i32 %48, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %49

49:                                               ; preds = %40, %15
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"short", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"sml_bit_array", !10, i64 0, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @sml_bit_array_set(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @sml_bit_array_get(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @sml_bit_array_size_set(ptr noundef, i16 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @sml_bit_array_remove(ptr noundef %0, i16 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = load i16, ptr %0, align 8, !tbaa !5
  %.not = icmp ugt i16 %3, %1
  br i1 %.not, label %.preheader, label %18

.preheader:                                       ; preds = %2
  %4 = zext i16 %1 to i32
  %5 = zext i16 %3 to i32
  %6 = add nsw i32 %5, -1
  %7 = icmp ugt i32 %6, %4
  br i1 %7, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.015 = phi i16 [ %8, %.lr.ph ], [ %1, %.preheader ]
  %8 = add nuw i16 %.015, 1
  %9 = tail call zeroext i8 @sml_bit_array_get(ptr noundef nonnull %0, i16 noundef zeroext %8)
  %10 = tail call zeroext i1 @sml_bit_array_set(ptr noundef nonnull %0, i16 noundef zeroext %.015, i8 noundef zeroext %9)
  %11 = zext i16 %8 to i32
  %12 = load i16, ptr %0, align 8, !tbaa !5
  %13 = zext i16 %12 to i32
  %14 = add nsw i32 %13, -1
  %15 = icmp sgt i32 %14, %11
  br i1 %15, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.lcssa = phi i32 [ %6, %.preheader ], [ %14, %.lr.ph ]
  %16 = trunc i32 %.lcssa to i16
  %17 = tail call i32 @sml_bit_array_size_set(ptr noundef nonnull %0, i16 noundef zeroext %16, i8 noundef zeroext 0)
  br label %18

18:                                               ; preds = %2, %._crit_edge
  %.012 = phi i32 [ %17, %._crit_edge ], [ -22, %2 ]
  ret i32 %.012
}

attributes #0 = { 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" }

!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 0}
!6 = !{!"sml_bit_array", !7, i64 0, !10, i64 8}
!7 = !{!"short", !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"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass