; 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 void @sml_bit_array_clear(ptr noundef) #0

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

16:                                               ; preds = %3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  call void @sml_bit_array_clear(ptr noundef %17)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %66

18:                                               ; preds = %3
  %19 = load i16, ptr %6, align 2, !tbaa !9
  %20 = call zeroext i16 @_calc_data_size(i16 noundef zeroext %19)
  store i16 %20, ptr %9, align 2, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.sml_bit_array, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !12
  %24 = load i16, ptr %9, align 2, !tbaa !9
  %25 = zext i16 %24 to i64
  %26 = call ptr @realloc(ptr noundef %23, i64 noundef %25) #5
  store ptr %26, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = icmp eq ptr %27, null
  br i1 %28, label %29, label %33

29:                                               ; preds = %18
  %30 = call ptr @__errno_location() #6
  %31 = load i32, ptr %30, align 4, !tbaa !14
  %32 = sub nsw i32 0, %31
  store i32 %32, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %66

33:                                               ; preds = %18
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.sml_bit_array, ptr %35, i32 0, i32 1
  store ptr %34, ptr %36, align 8, !tbaa !12
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.sml_bit_array, ptr %37, i32 0, i32 0
  %39 = load i16, ptr %38, align 8, !tbaa !16
  store i16 %39, ptr %10, align 2, !tbaa !9
  %40 = load i16, ptr %6, align 2, !tbaa !9
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.sml_bit_array, ptr %41, i32 0, i32 0
  store i16 %40, ptr %42, align 8, !tbaa !16
  %43 = load i16, ptr %6, align 2, !tbaa !9
  %44 = zext i16 %43 to i32
  %45 = load i16, ptr %10, align 2, !tbaa !9
  %46 = zext i16 %45 to i32
  %47 = icmp sgt i32 %44, %46
  br i1 %47, label %48, label %65

48:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  %49 = load i16, ptr %10, align 2, !tbaa !9
  store i16 %49, ptr %12, align 2, !tbaa !9
  br label %50

50:                                               ; preds = %61, %48
  %51 = load i16, ptr %12, align 2, !tbaa !9
  %52 = zext i16 %51 to i32
  %53 = load i16, ptr %6, align 2, !tbaa !9
  %54 = zext i16 %53 to i32
  %55 = icmp slt i32 %52, %54
  br i1 %55, label %56, label %64

56:                                               ; preds = %50
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  %58 = load i16, ptr %12, align 2, !tbaa !9
  %59 = load i8, ptr %7, align 1, !tbaa !11
  %60 = call zeroext i1 @sml_bit_array_set(ptr noundef %57, i16 noundef zeroext %58, i8 noundef zeroext %59)
  br label %61

61:                                               ; preds = %56
  %62 = load i16, ptr %12, align 2, !tbaa !9
  %63 = add i16 %62, 1
  store i16 %63, ptr %12, align 2, !tbaa !9
  br label %50, !llvm.loop !17

64:                                               ; preds = %50
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  br label %65

65:                                               ; preds = %64, %33
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %66

66:                                               ; preds = %65, %29, %16
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %67 = load i32, ptr %4, align 4
  ret i32 %67
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @_calc_data_size(i16 noundef zeroext) #0

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

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 allocsize(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 #3 = { nounwind willreturn memory(none) "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 }
attributes #5 = { nounwind allocsize(1) }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 8}
!13 = !{!"sml_bit_array", !10, i64 0, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!13, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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 void @sml_bit_array_clear(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2147483647, -2147483648) i32 @sml_bit_array_size_set(ptr noundef %0, i16 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = icmp eq i16 %1, 0
  br i1 %4, label %5, label %6

5:                                                ; preds = %3
  tail call void @sml_bit_array_clear(ptr noundef %0)
  br label %.loopexit

6:                                                ; preds = %3
  %7 = tail call zeroext i16 @_calc_data_size(i16 noundef zeroext %1)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !5
  %10 = zext i16 %7 to i64
  %11 = tail call ptr @realloc(ptr noundef %9, i64 noundef %10) #3
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %17

13:                                               ; preds = %6
  %14 = tail call ptr @__errno_location() #4
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = sub nsw i32 0, %15
  br label %.loopexit

17:                                               ; preds = %6
  store ptr %11, ptr %8, align 8, !tbaa !5
  %18 = load i16, ptr %0, align 8, !tbaa !13
  store i16 %1, ptr %0, align 8, !tbaa !13
  %19 = icmp ult i16 %18, %1
  br i1 %19, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %17, %.preheader
  %.023 = phi i16 [ %21, %.preheader ], [ %18, %17 ]
  %20 = tail call zeroext i1 @sml_bit_array_set(ptr noundef nonnull %0, i16 noundef zeroext %.023, i8 noundef zeroext %2)
  %21 = add nuw i16 %.023, 1
  %exitcond.not = icmp eq i16 %21, %1
  br i1 %exitcond.not, label %.loopexit, label %.preheader, !llvm.loop !14

.loopexit:                                        ; preds = %.preheader, %17, %13, %5
  %.020 = phi i32 [ 0, %5 ], [ %16, %13 ], [ 0, %17 ], [ 0, %.preheader ]
  ret i32 %.020
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i16 @_calc_data_size(i16 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #2

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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 allocsize(1) }
attributes #4 = { nounwind willreturn memory(none) }

!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, !10, i64 8}
!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 = !{!12, !12, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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