; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; 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 zeroext i8 @sml_bit_array_get(ptr noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca i8, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  %9 = 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
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %10 = load i16, ptr %5, align 2, !tbaa !9
  %11 = zext i16 %10 to i32
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.sml_bit_array, ptr %12, i32 0, i32 0
  %14 = load i16, ptr %13, align 8, !tbaa !11
  %15 = zext i16 %14 to i32
  %16 = icmp sge i32 %11, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i8 0, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %48

18:                                               ; preds = %2
  %19 = load i16, ptr %5, align 2, !tbaa !9
  %20 = zext i16 %19 to i32
  %21 = sdiv i32 %20, 8
  %22 = trunc i32 %21 to i16
  store i16 %22, ptr %6, align 2, !tbaa !9
  %23 = load i16, ptr %5, align 2, !tbaa !9
  %24 = zext i16 %23 to i32
  %25 = srem i32 %24, 8
  %26 = mul nsw i32 %25, 1
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %8, align 1, !tbaa !13
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.sml_bit_array, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  %31 = load i16, ptr %6, align 2, !tbaa !9
  %32 = zext i16 %31 to i64
  %33 = getelementptr inbounds i8, ptr %30, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !13
  store i8 %34, ptr %7, align 1, !tbaa !13
  %35 = load i8, ptr %7, align 1, !tbaa !13
  %36 = zext i8 %35 to i32
  %37 = load i8, ptr %8, align 1, !tbaa !13
  %38 = zext i8 %37 to i32
  %39 = shl i32 1, %38
  %40 = and i32 %36, %39
  %41 = trunc i32 %40 to i8
  store i8 %41, ptr %7, align 1, !tbaa !13
  %42 = load i8, ptr %7, align 1, !tbaa !13
  %43 = zext i8 %42 to i32
  %44 = load i8, ptr %8, align 1, !tbaa !13
  %45 = zext i8 %44 to i32
  %46 = ashr i32 %43, %45
  %47 = trunc i32 %46 to i8
  store i8 %47, ptr %3, align 1
  store i32 1, ptr %9, align 4
  br label %48

48:                                               ; preds = %18, %17
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #2
  %49 = load i8, ptr %3, align 1
  ret i8 %49
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 }

!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 = !{!7, !7, i64 0}
!14 = !{!12, !6, i64 8}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local zeroext range(i8 0, -127) i8 @sml_bit_array_get(ptr nocapture noundef readonly %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 %4, label %17

4:                                                ; preds = %2
  %5 = lshr i16 %1, 3
  %6 = and i16 %1, 7
  %7 = trunc nuw nsw i16 %6 to i8
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !11
  %10 = zext nneg i16 %5 to i64
  %11 = getelementptr inbounds i8, ptr %9, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !12
  %13 = shl nuw nsw i16 1, %6
  %14 = trunc nuw i16 %13 to i8
  %15 = and i8 %12, %14
  %16 = lshr i8 %15, %7
  br label %17

17:                                               ; preds = %2, %4
  %.0 = phi i8 [ %16, %4 ], [ 0, %2 ]
  ret i8 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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 = !{!6, !10, i64 8}
!12 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass