; LLVM IR from attractivechaos/klib :: khmm (hmm_pre_backward)

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

@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.hmm_pre_backward = external hidden unnamed_addr constant [35 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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, 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 @hmm_pre_backward(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %1
  br label %13

12:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 197, ptr noundef @__PRETTY_FUNCTION__.hmm_pre_backward) #4
  unreachable

13:                                               ; preds = %11
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.hmm_par_t, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  store i32 %16, ptr %3, align 4, !tbaa !12
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.hmm_par_t, ptr %17, i32 0, i32 1
  %19 = load i32, ptr %18, align 4, !tbaa !13
  store i32 %19, ptr %4, align 4, !tbaa !12
  store i32 0, ptr %5, align 4, !tbaa !12
  br label %20

20:                                               ; preds = %83, %13
  %21 = load i32, ptr %5, align 4, !tbaa !12
  %22 = load i32, ptr %3, align 4, !tbaa !12
  %23 = icmp sle i32 %21, %22
  br i1 %23, label %24, label %86

24:                                               ; preds = %20
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %25

25:                                               ; preds = %79, %24
  %26 = load i32, ptr %6, align 4, !tbaa !12
  %27 = load i32, ptr %4, align 4, !tbaa !12
  %28 = icmp ne i32 %26, %27
  br i1 %28, label %29, label %82

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.hmm_par_t, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i32, ptr %5, align 4, !tbaa !12
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.hmm_par_t, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !13
  %37 = mul nsw i32 %33, %36
  %38 = load i32, ptr %6, align 4, !tbaa !12
  %39 = add nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %32, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %8, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !12
  br label %43

43:                                               ; preds = %75, %29
  %44 = load i32, ptr %7, align 4, !tbaa !12
  %45 = load i32, ptr %4, align 4, !tbaa !12
  %46 = icmp ne i32 %44, %45
  br i1 %46, label %47, label %78

47:                                               ; preds = %43
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.hmm_par_t, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = load i32, ptr %5, align 4, !tbaa !12
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds ptr, ptr %50, i64 %52
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !12
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds double, ptr %54, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !16
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.hmm_par_t, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !18
  %62 = load i32, ptr %6, align 4, !tbaa !12
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds ptr, ptr %61, i64 %63
  %65 = load ptr, ptr %64, align 8, !tbaa !5
  %66 = load i32, ptr %7, align 4, !tbaa !12
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds double, ptr %65, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !16
  %70 = fmul double %58, %69
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = load i32, ptr %7, align 4, !tbaa !12
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds double, ptr %71, i64 %73
  store double %70, ptr %74, align 8, !tbaa !16
  br label %75

75:                                               ; preds = %47
  %76 = load i32, ptr %7, align 4, !tbaa !12
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %7, align 4, !tbaa !12
  br label %43, !llvm.loop !19

78:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %6, align 4, !tbaa !12
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %6, align 4, !tbaa !12
  br label %25, !llvm.loop !21

82:                                               ; preds = %25
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %5, align 4, !tbaa !12
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %5, align 4, !tbaa !12
  br label %20, !llvm.loop !22

86:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 }
attributes #4 = { noreturn 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 4}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !7, i64 0}
!18 = !{!10, !6, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}
!22 = distinct !{!22, !20}


; 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 [61 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.hmm_pre_backward = external hidden unnamed_addr constant [35 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @hmm_pre_backward(ptr noundef readonly %0) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %2, label %3

2:                                                ; preds = %1
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 197, ptr noundef nonnull @__PRETTY_FUNCTION__.hmm_pre_backward) #2
  unreachable

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = load i32, ptr %5, align 4, !tbaa !11
  %.not2736 = icmp slt i32 %4, 0
  %.not2832 = icmp eq i32 %6, 0
  %or.cond = select i1 %.not2736, i1 true, i1 %.not2832
  br i1 %or.cond, label %._crit_edge38, label %.preheader.lr.ph.split

.preheader.lr.ph.split:                           ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = load ptr, ptr %8, align 8, !tbaa !13
  %12 = load ptr, ptr %7, align 8, !tbaa !14
  %13 = zext i32 %6 to i64
  %14 = sext i32 %6 to i64
  %15 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %15 to i64
  %min.iters.check = icmp ult i32 %6, 4
  %n.vec = and i64 %13, 4294967292
  %cmp.n = icmp eq i64 %n.vec, %13
  %xtraiter = and i64 %13, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph.split, %._crit_edge35.split
  %indvars.iv44 = phi i64 [ 0, %.preheader.lr.ph.split ], [ %indvars.iv.next45, %._crit_edge35.split ]
  %16 = mul nsw i64 %indvars.iv44, %14
  %17 = getelementptr inbounds ptr, ptr %11, i64 %indvars.iv44
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = ptrtoint ptr %18 to i64
  %invariant.gep = getelementptr ptr, ptr %10, i64 %16
  br label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %._crit_edge
  %indvars.iv41 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next42, %._crit_edge ]
  %gep = getelementptr ptr, ptr %invariant.gep, i64 %indvars.iv41
  %20 = load ptr, ptr %gep, align 8, !tbaa !15
  %21 = getelementptr inbounds ptr, ptr %12, i64 %indvars.iv41
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %23 = ptrtoint ptr %22 to i64
  %24 = ptrtoint ptr %20 to i64
  %25 = sub i64 %24, %19
  %diff.check = icmp ult i64 %25, 32
  %26 = sub i64 %24, %23
  %diff.check47 = icmp ult i64 %26, 32
  %conflict.rdx = or i1 %diff.check, %diff.check47
  br i1 %conflict.rdx, label %scalar.ph.preheader, label %vector.body

vector.body:                                      ; preds = %vector.memcheck, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %vector.memcheck ]
  %27 = getelementptr inbounds double, ptr %18, i64 %index
  %28 = getelementptr inbounds i8, ptr %27, i64 16
  %wide.load = load <2 x double>, ptr %27, align 8, !tbaa !16
  %wide.load48 = load <2 x double>, ptr %28, align 8, !tbaa !16
  %29 = getelementptr inbounds double, ptr %22, i64 %index
  %30 = getelementptr inbounds i8, ptr %29, i64 16
  %wide.load49 = load <2 x double>, ptr %29, align 8, !tbaa !16
  %wide.load50 = load <2 x double>, ptr %30, align 8, !tbaa !16
  %31 = fmul <2 x double> %wide.load, %wide.load49
  %32 = fmul <2 x double> %wide.load48, %wide.load50
  %33 = getelementptr inbounds double, ptr %20, i64 %index
  %34 = getelementptr inbounds i8, ptr %33, i64 16
  store <2 x double> %31, ptr %33, align 8, !tbaa !16
  store <2 x double> %32, ptr %34, align 8, !tbaa !16
  %index.next = add nuw i64 %index, 4
  %35 = icmp eq i64 %index.next, %n.vec
  br i1 %35, label %middle.block, label %vector.body, !llvm.loop !18

middle.block:                                     ; preds = %vector.body
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %36 = getelementptr inbounds double, ptr %18, i64 %indvars.iv.prol
  %37 = load double, ptr %36, align 8, !tbaa !16
  %38 = getelementptr inbounds double, ptr %22, i64 %indvars.iv.prol
  %39 = load double, ptr %38, align 8, !tbaa !16
  %40 = fmul double %37, %39
  %41 = getelementptr inbounds double, ptr %20, i64 %indvars.iv.prol
  store double %40, ptr %41, align 8, !tbaa !16
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !22

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %42 = sub nsw i64 %indvars.iv.ph, %13
  %43 = icmp ugt i64 %42, -4
  br i1 %43, label %._crit_edge, label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %44 = getelementptr inbounds double, ptr %18, i64 %indvars.iv
  %45 = load double, ptr %44, align 8, !tbaa !16
  %46 = getelementptr inbounds double, ptr %22, i64 %indvars.iv
  %47 = load double, ptr %46, align 8, !tbaa !16
  %48 = fmul double %45, %47
  %49 = getelementptr inbounds double, ptr %20, i64 %indvars.iv
  store double %48, ptr %49, align 8, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %50 = getelementptr inbounds double, ptr %18, i64 %indvars.iv.next
  %51 = load double, ptr %50, align 8, !tbaa !16
  %52 = getelementptr inbounds double, ptr %22, i64 %indvars.iv.next
  %53 = load double, ptr %52, align 8, !tbaa !16
  %54 = fmul double %51, %53
  %55 = getelementptr inbounds double, ptr %20, i64 %indvars.iv.next
  store double %54, ptr %55, align 8, !tbaa !16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %56 = getelementptr inbounds double, ptr %18, i64 %indvars.iv.next.1
  %57 = load double, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds double, ptr %22, i64 %indvars.iv.next.1
  %59 = load double, ptr %58, align 8, !tbaa !16
  %60 = fmul double %57, %59
  %61 = getelementptr inbounds double, ptr %20, i64 %indvars.iv.next.1
  store double %60, ptr %61, align 8, !tbaa !16
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %62 = getelementptr inbounds double, ptr %18, i64 %indvars.iv.next.2
  %63 = load double, ptr %62, align 8, !tbaa !16
  %64 = getelementptr inbounds double, ptr %22, i64 %indvars.iv.next.2
  %65 = load double, ptr %64, align 8, !tbaa !16
  %66 = fmul double %63, %65
  %67 = getelementptr inbounds double, ptr %20, i64 %indvars.iv.next.2
  store double %66, ptr %67, align 8, !tbaa !16
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %.not29.3 = icmp eq i64 %indvars.iv.next.3, %13
  br i1 %.not29.3, label %._crit_edge, label %scalar.ph, !llvm.loop !24

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %.not28 = icmp eq i64 %indvars.iv.next42, %13
  br i1 %.not28, label %._crit_edge35.split, label %.lr.ph, !llvm.loop !25

._crit_edge35.split:                              ; preds = %._crit_edge
  %indvars.iv.next45 = add nuw nsw i64 %indvars.iv44, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next45, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge38, label %.preheader, !llvm.loop !26

._crit_edge38:                                    ; preds = %._crit_edge35.split, %3
  ret void
}

attributes #0 = { noreturn nounwind "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 = { 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 = { noreturn 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 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 24}
!13 = !{!6, !10, i64 16}
!14 = !{!6, !10, i64 8}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !19, !20, !21}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!"llvm.loop.isvectorized", i32 1}
!21 = !{!"llvm.loop.unroll.runtime.disable"}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.unroll.disable"}
!24 = distinct !{!24, !19, !20}
!25 = distinct !{!25, !19}
!26 = distinct !{!26, !19}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass