; LLVM IR from HRI-EU/Rcs :: src/RcsCore (ViaPointSequence)

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

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

; Function Attrs: nounwind
declare i64 @lround(double noundef) #1

declare zeroext i1 @Math_isBitSet(i32 noundef, i32 noundef) #2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN3Rcs16ViaPointSequence26computeNumberOfConstraintsEPK6_MatNd(ptr noundef %0) #3 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 0, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !9
  br label %6

6:                                                ; preds = %47, %1
  %7 = load i64, ptr %4, align 8, !tbaa !9
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._MatNd, ptr %8, i32 0, i32 1
  %10 = load i32, ptr %9, align 8, !tbaa !11
  %11 = zext i32 %10 to i64
  %12 = icmp ult i64 %7, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %50

14:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._MatNd, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !15
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._MatNd, ptr %19, i32 0, i32 2
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %22 = zext i32 %21 to i64
  %23 = mul i64 %18, %22
  %24 = add i64 %23, 4
  %25 = getelementptr inbounds double, ptr %17, i64 %24
  %26 = load double, ptr %25, align 8, !tbaa !17
  %27 = call i64 @lround(double noundef %26) #4
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr %5, align 4, !tbaa !19
  %29 = load i32, ptr %5, align 4, !tbaa !19
  %30 = call zeroext i1 @Math_isBitSet(i32 noundef %29, i32 noundef 0)
  br i1 %30, label %31, label %34

31:                                               ; preds = %14
  %32 = load i64, ptr %3, align 8, !tbaa !9
  %33 = add i64 %32, 1
  store i64 %33, ptr %3, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %31, %14
  %35 = load i32, ptr %5, align 4, !tbaa !19
  %36 = call zeroext i1 @Math_isBitSet(i32 noundef %35, i32 noundef 1)
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load i64, ptr %3, align 8, !tbaa !9
  %39 = add i64 %38, 1
  store i64 %39, ptr %3, align 8, !tbaa !9
  br label %40

40:                                               ; preds = %37, %34
  %41 = load i32, ptr %5, align 4, !tbaa !19
  %42 = call zeroext i1 @Math_isBitSet(i32 noundef %41, i32 noundef 2)
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load i64, ptr %3, align 8, !tbaa !9
  %45 = add i64 %44, 1
  store i64 %45, ptr %3, align 8, !tbaa !9
  br label %46

46:                                               ; preds = %43, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %47

47:                                               ; preds = %46
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = add i64 %48, 1
  store i64 %49, ptr %4, align 8, !tbaa !9
  br label %6, !llvm.loop !20

50:                                               ; preds = %13
  %51 = load i64, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret i64 %51
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = { mustprogress 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 #4 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 8}
!12 = !{!"_ZTS6_MatNd", !6, i64 0, !13, i64 8, !13, i64 12, !13, i64 16, !14, i64 20}
!13 = !{!"int", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !6, i64 0}
!16 = !{!12, !13, i64 12}
!17 = !{!18, !18, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!13, !13, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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
declare i64 @lround(double noundef) local_unnamed_addr #0

declare zeroext i1 @Math_isBitSet(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN3Rcs16ViaPointSequence26computeNumberOfConstraintsEPK6_MatNd(ptr nocapture noundef readonly %0) local_unnamed_addr #2 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i32 %3, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  br label %5

._crit_edge:                                      ; preds = %5, %1
  %.0.lcssa = phi i64 [ 0, %1 ], [ %.3, %5 ]
  ret i64 %.0.lcssa

5:                                                ; preds = %.lr.ph, %5
  %.014 = phi i64 [ 0, %.lr.ph ], [ %.3, %5 ]
  %.01213 = phi i64 [ 0, %.lr.ph ], [ %21, %5 ]
  %6 = load ptr, ptr %0, align 8, !tbaa !12
  %7 = load i32, ptr %4, align 4, !tbaa !13
  %8 = zext i32 %7 to i64
  %9 = mul nuw i64 %.01213, %8
  %10 = getelementptr double, ptr %6, i64 %9
  %11 = getelementptr i8, ptr %10, i64 32
  %12 = load double, ptr %11, align 8, !tbaa !14
  %13 = tail call i64 @lround(double noundef %12) #3
  %14 = trunc i64 %13 to i32
  %15 = tail call zeroext i1 @Math_isBitSet(i32 noundef %14, i32 noundef 0)
  %16 = zext i1 %15 to i64
  %spec.select = add i64 %.014, %16
  %17 = tail call zeroext i1 @Math_isBitSet(i32 noundef %14, i32 noundef 1)
  %18 = zext i1 %17 to i64
  %.2 = add i64 %spec.select, %18
  %19 = tail call zeroext i1 @Math_isBitSet(i32 noundef %14, i32 noundef 2)
  %20 = zext i1 %19 to i64
  %.3 = add i64 %.2, %20
  %21 = add nuw nsw i64 %.01213, 1
  %22 = load i32, ptr %2, align 8, !tbaa !5
  %23 = zext i32 %22 to i64
  %24 = icmp ult i64 %21, %23
  br i1 %24, label %5, label %._crit_edge, !llvm.loop !16
}

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

!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 = !{!"_ZTS6_MatNd", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16, !11, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"bool", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 12}
!14 = !{!15, !15, i64 0}
!15 = !{!"double", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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