; LLVM IR from DimitrisJim/leetcode_solutions :: C/Algorithms (812)

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

; Function Attrs: nounwind uwtable
define dso_local double @largestTriangleArea(ptr noundef %0, i32 noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca double, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca double, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store double -1.000000e+00, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = sub nsw i32 %16, 3
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sub nsw i32 %19, 3
  %21 = add nsw i32 %20, 2
  store i32 %21, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %22 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %22, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %75, %3
  %24 = load i32, ptr %11, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %78

28:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %29 = load i32, ptr %11, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %13, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %71, %28
  %32 = load i32, ptr %13, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %74

36:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %37 = load i32, ptr %13, align 4, !tbaa !9
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %14, align 4, !tbaa !9
  br label %39

39:                                               ; preds = %67, %36
  %40 = load i32, ptr %14, align 4, !tbaa !9
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 8, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %70

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds ptr, ptr %45, i64 %47
  %49 = load ptr, ptr %48, align 8, !tbaa !5
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %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 ptr, ptr %4, align 8, !tbaa !5
  %56 = load i32, ptr %14, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds ptr, ptr %55, i64 %57
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  %60 = call double @shoelace(ptr noundef %49, ptr noundef %54, ptr noundef %59)
  store double %60, ptr %15, align 8, !tbaa !11
  %61 = load double, ptr %15, align 8, !tbaa !11
  %62 = load double, ptr %7, align 8, !tbaa !11
  %63 = fcmp ogt double %61, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %44
  %65 = load double, ptr %15, align 8, !tbaa !11
  store double %65, ptr %7, align 8, !tbaa !11
  br label %66

66:                                               ; preds = %64, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %14, align 4, !tbaa !9
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %14, align 4, !tbaa !9
  br label %39, !llvm.loop !13

70:                                               ; preds = %43
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %13, align 4, !tbaa !9
  br label %31, !llvm.loop !15

74:                                               ; preds = %35
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %11, align 4, !tbaa !9
  br label %23, !llvm.loop !16

78:                                               ; preds = %27
  %79 = load double, ptr %7, align 8, !tbaa !11
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret double %79
}

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

; Function Attrs: inlinehint nounwind uwtable
declare double @shoelace(ptr noundef, ptr noundef, ptr noundef) #2

; 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 = { inlinehint 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 }

!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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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 uwtable
define dso_local double @largestTriangleArea(ptr nocapture noundef readonly %0, i32 noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  %4 = icmp sgt i32 %1, 2
  br i1 %4, label %.lr.ph36.preheader, label %._crit_edge

.lr.ph36.preheader:                               ; preds = %3
  %5 = add nsw i32 %1, -1
  %6 = add nsw i32 %1, -2
  %wide.trip.count51 = zext nneg i32 %6 to i64
  %wide.trip.count = zext i32 %5 to i64
  br label %.lr.ph32

.loopexit27:                                      ; preds = %.loopexit
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count51
  br i1 %exitcond52.not, label %._crit_edge, label %.lr.ph32, !llvm.loop !5

._crit_edge:                                      ; preds = %.loopexit27, %3
  %.0.lcssa = phi double [ -1.000000e+00, %3 ], [ %.2.lcssa, %.loopexit27 ]
  ret double %.0.lcssa

.lr.ph32:                                         ; preds = %.loopexit27, %.lr.ph36.preheader
  %indvars.iv48 = phi i64 [ 0, %.lr.ph36.preheader ], [ %indvars.iv.next49, %.loopexit27 ]
  %indvars.iv43 = phi i64 [ 1, %.lr.ph36.preheader ], [ %indvars.iv.next44, %.loopexit27 ]
  %indvars.iv = phi i64 [ 2, %.lr.ph36.preheader ], [ %indvars.iv.next, %.loopexit27 ]
  %.035 = phi double [ -1.000000e+00, %.lr.ph36.preheader ], [ %.2.lcssa, %.loopexit27 ]
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %7 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv48
  br label %8

.loopexit:                                        ; preds = %12, %8
  %.2.lcssa = phi double [ %.131, %8 ], [ %.3, %12 ]
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next46, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit27, label %8, !llvm.loop !7

8:                                                ; preds = %.lr.ph32, %.loopexit
  %indvars.iv45 = phi i64 [ %indvars.iv43, %.lr.ph32 ], [ %indvars.iv.next46, %.loopexit ]
  %indvars.iv38 = phi i64 [ %indvars.iv, %.lr.ph32 ], [ %indvars.iv.next39, %.loopexit ]
  %.131 = phi double [ %.035, %.lr.ph32 ], [ %.2.lcssa, %.loopexit ]
  %indvars.iv.next46 = add nuw nsw i64 %indvars.iv45, 1
  %9 = trunc nuw i64 %indvars.iv.next46 to i32
  %10 = icmp slt i32 %9, %1
  br i1 %10, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %8
  %11 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv45
  br label %12

12:                                               ; preds = %.lr.ph, %12
  %indvars.iv40 = phi i64 [ %indvars.iv38, %.lr.ph ], [ %indvars.iv.next41, %12 ]
  %.229 = phi double [ %.131, %.lr.ph ], [ %.3, %12 ]
  %13 = load ptr, ptr %7, align 8, !tbaa !8
  %14 = load ptr, ptr %11, align 8, !tbaa !8
  %15 = getelementptr inbounds ptr, ptr %0, i64 %indvars.iv40
  %16 = load ptr, ptr %15, align 8, !tbaa !8
  %17 = tail call double @shoelace(ptr noundef %13, ptr noundef %14, ptr noundef %16)
  %18 = fcmp ogt double %17, %.229
  %.3 = select i1 %18, double %17, double %.229
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %19 = trunc nuw i64 %indvars.iv.next41 to i32
  %20 = icmp slt i32 %19, %1
  br i1 %20, label %12, label %.loopexit, !llvm.loop !12
}

; Function Attrs: inlinehint nounwind uwtable
declare double @shoelace(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { inlinehint 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = distinct !{!12, !6}


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