; LLVM IR from Discngine/fpocket :: src/qhull/src/libqhullcpp/QhullPoints.ll (ZNK8orgQhull11QhullPoints3midEii)

; 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"

%"class.orgQhull::QhullPoints" = type <{ ptr, ptr, ptr, i32, [4 x i8] }>

; 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: mustprogress uwtable
declare dso_local noundef i32 @_ZNK8orgQhull11QhullPoints5countEv(ptr noundef nonnull align 8 dereferenceable(28)) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK8orgQhull11QhullPoints3midEii(ptr dead_on_unwind noalias writable sret(%"class.orgQhull::QhullPoints") align 8 %0, ptr noundef nonnull align 8 dereferenceable(28) %1, i32 noundef %2, i32 noundef %3) #1 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %10 = load ptr, ptr %6, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %11 = call noundef i32 @_ZNK8orgQhull11QhullPoints5countEv(ptr noundef nonnull align 8 dereferenceable(28) %10)
  store i32 %11, ptr %9, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %18, label %14

14:                                               ; preds = %4
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = icmp sge i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %14, %4
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %39

19:                                               ; preds = %14
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %28, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !9
  %25 = add nsw i32 %23, %24
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = icmp sge i32 %25, %26
  br i1 %27, label %28, label %32

28:                                               ; preds = %22, %19
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load i32, ptr %9, align 4, !tbaa !9
  %31 = sub nsw i32 %30, %29
  store i32 %31, ptr %9, align 4, !tbaa !9
  br label %38

32:                                               ; preds = %22
  %33 = load i32, ptr %7, align 4, !tbaa !9
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = add nsw i32 %33, %34
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = sub nsw i32 %36, %35
  store i32 %37, ptr %9, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %32, %28
  br label %39

39:                                               ; preds = %38, %18
  %40 = getelementptr inbounds %"class.orgQhull::QhullPoints", ptr %10, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %"class.orgQhull::QhullPoints", ptr %10, i32 0, i32 3
  %43 = load i32, ptr %42, align 8, !tbaa !13
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = getelementptr inbounds %"class.orgQhull::QhullPoints", ptr %10, i32 0, i32 3
  %46 = load i32, ptr %45, align 8, !tbaa !13
  %47 = mul nsw i32 %44, %46
  %48 = getelementptr inbounds %"class.orgQhull::QhullPoints", ptr %10, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !14
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = getelementptr inbounds %"class.orgQhull::QhullPoints", ptr %10, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !13
  %53 = mul nsw i32 %50, %52
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %49, i64 %54
  call void @_ZN8orgQhull11QhullPointsC1EPNS_7QhullQhEiiPd(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef %41, i32 noundef %43, i32 noundef %47, ptr noundef %55)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

declare void @_ZN8orgQhull11QhullPointsC1EPNS_7QhullQhEiiPd(ptr, ptr, i32, i32, ptr)

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTSN8orgQhull11QhullPointsE", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 24}
!14 = !{!12, !6, i64 0}


; 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"

%"class.orgQhull::QhullPoints" = type <{ ptr, ptr, ptr, i32, [4 x i8] }>

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_ZNK8orgQhull11QhullPoints5countEv(ptr noundef nonnull align 8 dereferenceable(28)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZNK8orgQhull11QhullPoints3midEii(ptr dead_on_unwind noalias writable sret(%"class.orgQhull::QhullPoints") align 8 %0, ptr noundef nonnull align 8 dereferenceable(28) %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 align 2 {
  %5 = tail call noundef i32 @_ZNK8orgQhull11QhullPoints5countEv(ptr noundef nonnull align 8 dereferenceable(28) %1)
  %6 = icmp sgt i32 %2, -1
  %.not = icmp sgt i32 %5, %2
  %or.cond = and i1 %6, %.not
  br i1 %or.cond, label %7, label %15

7:                                                ; preds = %4
  %8 = icmp slt i32 %3, 0
  br i1 %8, label %11, label %9

9:                                                ; preds = %7
  %10 = add nuw nsw i32 %3, %2
  %.not18 = icmp slt i32 %10, %5
  br i1 %.not18, label %13, label %11

11:                                               ; preds = %9, %7
  %12 = sub nsw i32 %5, %2
  br label %15

13:                                               ; preds = %9
  %14 = sub nsw i32 %5, %10
  br label %15

15:                                               ; preds = %4, %11, %13
  %.0 = phi i32 [ %12, %11 ], [ %14, %13 ], [ 0, %4 ]
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %1, i64 24
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = mul nsw i32 %19, %.0
  %21 = load ptr, ptr %1, align 8, !tbaa !12
  %22 = mul nsw i32 %19, %2
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds double, ptr %21, i64 %23
  tail call void @_ZN8orgQhull11QhullPointsC1EPNS_7QhullQhEiiPd(ptr noundef nonnull align 8 dereferenceable(28) %0, ptr noundef %17, i32 noundef %19, i32 noundef %20, ptr noundef %24)
  ret void
}

declare void @_ZN8orgQhull11QhullPointsC1EPNS_7QhullQhEiiPd(ptr, ptr, i32, i32, ptr) local_unnamed_addr

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

!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 16}
!6 = !{!"_ZTSN8orgQhull11QhullPointsE", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 24}
!12 = !{!6, !7, i64 0}


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