; LLVM IR from 6leetcode/6leetcode :: questions/Algorithms/0679. 24 Game (c1)

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

@__const.judgePoint24.invalid = external hidden unnamed_addr constant [91 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @cmpfunc(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @judgePoint24(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [91 x i32], align 16
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 364, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.judgePoint24.invalid, i64 364, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 0, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  call void @qsort(ptr noundef %11, i64 noundef %13, i64 noundef 4, ptr noundef @cmpfunc)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %14

14:                                               ; preds = %33, %2
  %15 = load i32, ptr %8, align 4, !tbaa !9
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = icmp slt i32 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %36

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = load i32, ptr %8, align 4, !tbaa !9
  %26 = sub nsw i32 3, %25
  %27 = sitofp i32 %26 to double
  %28 = call double @pow(double noundef 1.000000e+01, double noundef %27) #5
  %29 = fptosi double %28 to i32
  %30 = mul nsw i32 %24, %29
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = add nsw i32 %31, %30
  store i32 %32, ptr %7, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %19
  %34 = load i32, ptr %8, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %8, align 4, !tbaa !9
  br label %14, !llvm.loop !11

36:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %51, %36
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = icmp ult i64 %39, 91
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 5, ptr %10, align 4
  br label %54

42:                                               ; preds = %37
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [91 x i32], ptr %6, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = icmp eq i32 %43, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %42
  store i1 false, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %54

50:                                               ; preds = %42
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %9, align 4, !tbaa !9
  br label %37, !llvm.loop !13

54:                                               ; preds = %49, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  %55 = load i32, ptr %10, align 4
  switch i32 %55, label %57 [
    i32 5, label %56
  ]

56:                                               ; preds = %54
  store i1 true, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %57

57:                                               ; preds = %56, %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 364, ptr %6) #5
  %58 = load i1, ptr %3, align 1
  ret i1 %58
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare double @pow(double noundef, double noundef) #4

; 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 "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 #5 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@__const.judgePoint24.invalid = external hidden unnamed_addr constant [91 x i32], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @cmpfunc(ptr noundef, ptr noundef) #0

; Function Attrs: nofree nounwind uwtable
define dso_local zeroext i1 @judgePoint24(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = sext i32 %1 to i64
  tail call void @qsort(ptr noundef %0, i64 noundef %3, i64 noundef 4, ptr noundef nonnull @cmpfunc) #4
  %4 = icmp sgt i32 %1, 0
  br i1 %4, label %.lr.ph.preheader, label %.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext nneg i32 %1 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %5 = icmp eq i32 %1, 1
  br i1 %5, label %.preheader.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph

.preheader.loopexit.unr-lcssa:                    ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa34.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.01619.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %34, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %.preheader.loopexit.unr-lcssa
  %6 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.unr
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = trunc i64 %indvars.iv.unr to i32
  %9 = sub i32 3, %8
  %10 = sitofp i32 %9 to double
  %11 = tail call double @pow(double noundef 1.000000e+01, double noundef %10) #4
  %12 = fptosi double %11 to i32
  %13 = mul nsw i32 %7, %12
  %14 = add nsw i32 %13, %.01619.unr
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph.epil, %.preheader.loopexit.unr-lcssa, %2
  %.016.lcssa = phi i32 [ 0, %2 ], [ %.lcssa34.ph, %.preheader.loopexit.unr-lcssa ], [ %14, %.lr.ph.epil ]
  %15 = load i32, ptr @__const.judgePoint24.invalid, align 16, !tbaa !5
  %16 = icmp eq i32 %.016.lcssa, %15
  br i1 %16, label %.critedge, label %.lr.ph30

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.01619 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %34, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %17 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = trunc i64 %indvars.iv to i32
  %20 = sub i32 3, %19
  %21 = sitofp i32 %20 to double
  %22 = tail call double @pow(double noundef 1.000000e+01, double noundef %21) #4
  %23 = fptosi double %22 to i32
  %24 = mul nsw i32 %18, %23
  %25 = add nsw i32 %24, %.01619
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %26 = getelementptr inbounds i32, ptr %0, i64 %indvars.iv.next
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = trunc i64 %indvars.iv.next to i32
  %29 = sub i32 3, %28
  %30 = sitofp i32 %29 to double
  %31 = tail call double @pow(double noundef 1.000000e+01, double noundef %30) #4
  %32 = fptosi double %31 to i32
  %33 = mul nsw i32 %27, %32
  %34 = add nsw i32 %33, %25
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

.lr.ph30:                                         ; preds = %.preheader, %.lr.ph30.3
  %indvars.iv2429 = phi i64 [ %indvars.iv.next25.3, %.lr.ph30.3 ], [ 0, %.preheader ]
  %indvars.iv.next25 = or disjoint i64 %indvars.iv2429, 1
  %35 = getelementptr inbounds [91 x i32], ptr @__const.judgePoint24.invalid, i64 0, i64 %indvars.iv.next25
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp eq i32 %.016.lcssa, %36
  br i1 %37, label %.critedge, label %.lr.ph30.1, !llvm.loop !11

.lr.ph30.1:                                       ; preds = %.lr.ph30
  %indvars.iv.next25.1 = or disjoint i64 %indvars.iv2429, 2
  %38 = getelementptr inbounds [91 x i32], ptr @__const.judgePoint24.invalid, i64 0, i64 %indvars.iv.next25.1
  %39 = load i32, ptr %38, align 8, !tbaa !5
  %40 = icmp eq i32 %.016.lcssa, %39
  br i1 %40, label %.critedge, label %.lr.ph30.2, !llvm.loop !11

.lr.ph30.2:                                       ; preds = %.lr.ph30.1
  %indvars.iv.next25.2 = or disjoint i64 %indvars.iv2429, 3
  %exitcond26.2 = icmp eq i64 %indvars.iv2429, 88
  br i1 %exitcond26.2, label %.critedge.loopexit.split.loop.exit39, label %41, !llvm.loop !11

41:                                               ; preds = %.lr.ph30.2
  %42 = getelementptr inbounds [91 x i32], ptr @__const.judgePoint24.invalid, i64 0, i64 %indvars.iv.next25.2
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = icmp eq i32 %.016.lcssa, %43
  br i1 %44, label %.critedge.loopexit.split.loop.exit37, label %.lr.ph30.3, !llvm.loop !11

.lr.ph30.3:                                       ; preds = %41
  %indvars.iv.next25.3 = add nuw nsw i64 %indvars.iv2429, 4
  %45 = getelementptr inbounds [91 x i32], ptr @__const.judgePoint24.invalid, i64 0, i64 %indvars.iv.next25.3
  %46 = load i32, ptr %45, align 16, !tbaa !5
  %47 = icmp eq i32 %.016.lcssa, %46
  br i1 %47, label %.critedge.loopexit.split.loop.exit, label %.lr.ph30, !llvm.loop !11

.critedge.loopexit.split.loop.exit:               ; preds = %.lr.ph30.3
  %48 = icmp ugt i64 %indvars.iv.next25.2, 89
  br label %.critedge

.critedge.loopexit.split.loop.exit37:             ; preds = %41
  %49 = icmp ugt i64 %indvars.iv.next25.1, 89
  br label %.critedge

.critedge.loopexit.split.loop.exit39:             ; preds = %.lr.ph30.2
  %50 = icmp ugt i64 %indvars.iv.next25.1, 89
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit.split.loop.exit, %.critedge.loopexit.split.loop.exit37, %.critedge.loopexit.split.loop.exit39, %.lr.ph30.1, %.lr.ph30, %.preheader
  %.lcssa = phi i1 [ false, %.preheader ], [ %48, %.critedge.loopexit.split.loop.exit ], [ %49, %.critedge.loopexit.split.loop.exit37 ], [ %50, %.critedge.loopexit.split.loop.exit39 ], [ false, %.lr.ph30.1 ], [ false, %.lr.ph30 ]
  ret i1 %.lcssa
}

; Function Attrs: nofree
declare void @qsort(ptr noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @pow(double noundef, double noundef) local_unnamed_addr #3

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 = { nofree 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 = { nofree "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 nofree nounwind willreturn memory(write) "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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