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

23:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %62

24:                                               ; preds = %3
  %25 = load i16, ptr %6, align 2, !tbaa !9
  %26 = zext i16 %25 to i32
  %27 = srem i32 %26, 8
  %28 = mul nsw i32 %27, 1
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %10, align 1, !tbaa !11
  %30 = load i8, ptr %10, align 1, !tbaa !11
  %31 = zext i8 %30 to i32
  %32 = shl i32 1, %31
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %9, align 1, !tbaa !11
  %34 = load i8, ptr %7, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = load i8, ptr %10, align 1, !tbaa !11
  %37 = zext i8 %36 to i32
  %38 = shl i32 %35, %37
  %39 = trunc i32 %38 to i8
  store i8 %39, ptr %7, align 1, !tbaa !11
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.sml_bit_array, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load i16, ptr %8, align 2, !tbaa !9
  %44 = zext i16 %43 to i64
  %45 = getelementptr inbounds i8, ptr %42, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = load i8, ptr %9, align 1, !tbaa !11
  %49 = zext i8 %48 to i32
  %50 = xor i32 %49, -1
  %51 = and i32 %47, %50
  %52 = load i8, ptr %7, align 1, !tbaa !11
  %53 = zext i8 %52 to i32
  %54 = or i32 %51, %53
  %55 = trunc i32 %54 to i8
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.sml_bit_array, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !14
  %59 = load i16, ptr %8, align 2, !tbaa !9
  %60 = zext i16 %59 to i64
  %61 = getelementptr inbounds i8, ptr %58, i64 %60
  store i8 %55, ptr %61, align 1, !tbaa !11
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %62

62:                                               ; preds = %24, %23
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #2
  %63 = load i1, ptr %4, align 1
  ret i1 %63
}

; 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

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 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"sml_bit_array", !10, i64 0, !6, i64 8}
!14 = !{!13, !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(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @sml_bit_array_set(ptr nocapture noundef readonly %0, i16 noundef zeroext %1, i8 noundef zeroext %2) local_unnamed_addr #0 {
  %4 = lshr i16 %1, 3
  %5 = load i16, ptr %0, align 8, !tbaa !5
  %.not = icmp ult i16 %4, %5
  br i1 %.not, label %6, label %20

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

20:                                               ; preds = %3, %6
  ret i1 %.not
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, 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