; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/other/CarFueling.ll (Z11car_fuelingxxxxPx)

; 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: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z11car_fuelingxxxxPx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  store i64 0, ptr %12, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %54, %5
  %15 = load i64, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %10, align 8, !tbaa !5
  %17 = icmp sle i64 %15, %16
  br i1 %17, label %18, label %55

18:                                               ; preds = %14
  %19 = load i64, ptr %7, align 8, !tbaa !5
  store i64 %19, ptr %9, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %39, %18
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = load i64, ptr %10, align 8, !tbaa !5
  %23 = icmp sle i64 %21, %22
  br i1 %23, label %24, label %37

24:                                               ; preds = %20
  %25 = load ptr, ptr %11, align 8, !tbaa !9
  %26 = load i64, ptr %7, align 8, !tbaa !5
  %27 = add nsw i64 %26, 1
  %28 = getelementptr inbounds i64, ptr %25, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !9
  %31 = load i64, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds i64, ptr %30, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = sub nsw i64 %29, %33
  %35 = load i64, ptr %8, align 8, !tbaa !5
  %36 = icmp sle i64 %34, %35
  br label %37

37:                                               ; preds = %24, %20
  %38 = phi i1 [ false, %20 ], [ %36, %24 ]
  br i1 %38, label %39, label %42

39:                                               ; preds = %37
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = add nsw i64 %40, 1
  store i64 %41, ptr %7, align 8, !tbaa !5
  br label %20, !llvm.loop !11

42:                                               ; preds = %37
  %43 = load i64, ptr %7, align 8, !tbaa !5
  %44 = load i64, ptr %9, align 8, !tbaa !5
  %45 = icmp eq i64 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %63

47:                                               ; preds = %42
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %10, align 8, !tbaa !5
  %50 = icmp sle i64 %48, %49
  br i1 %50, label %51, label %54

51:                                               ; preds = %47
  %52 = load i64, ptr %12, align 8, !tbaa !5
  %53 = add nsw i64 %52, 1
  store i64 %53, ptr %12, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %51, %47
  br label %14, !llvm.loop !13

55:                                               ; preds = %14
  %56 = load i64, ptr %7, align 8, !tbaa !5
  %57 = load i64, ptr %9, align 8, !tbaa !5
  %58 = icmp ne i64 %56, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %55
  %60 = load i64, ptr %12, align 8, !tbaa !5
  %61 = trunc i64 %60 to i32
  store i32 %61, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %63

62:                                               ; preds = %55
  unreachable

63:                                               ; preds = %59, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %64 = load i32, ptr %6, align 4
  ret i32 %64
}

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { mustprogress 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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(argmem: read, inaccessiblemem: write) uwtable
define dso_local noundef i32 @_Z11car_fuelingxxxxPx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, ptr nocapture noundef readonly %4) local_unnamed_addr #0 {
  %.not29 = icmp sgt i64 %0, %3
  br i1 %.not29, label %._crit_edge, label %.preheader

6:                                                ; preds = %.critedge
  %7 = zext i1 %.not24.not to i32
  %spec.select = add i32 %.031, %7
  %.not = icmp sgt i64 %.121, %3
  br i1 %.not, label %._crit_edge, label %.preheader, !llvm.loop !5

.preheader:                                       ; preds = %5, %6
  %.031 = phi i32 [ %spec.select, %6 ], [ 0, %5 ]
  %.02030 = phi i64 [ %.121, %6 ], [ %0, %5 ]
  %8 = getelementptr inbounds i64, ptr %4, i64 %.02030
  br label %9

9:                                                ; preds = %.preheader, %10
  %.121 = phi i64 [ %11, %10 ], [ %.02030, %.preheader ]
  %.not24.not = icmp sle i64 %.121, %3
  br i1 %.not24.not, label %10, label %.critedge

10:                                               ; preds = %9
  %11 = add nsw i64 %.121, 1
  %12 = getelementptr inbounds i64, ptr %4, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !7
  %14 = load i64, ptr %8, align 8, !tbaa !7
  %15 = sub nsw i64 %13, %14
  %.not25 = icmp sgt i64 %15, %1
  br i1 %.not25, label %.critedge, label %9, !llvm.loop !11

.critedge:                                        ; preds = %9, %10
  %16 = icmp eq i64 %.121, %.02030
  br i1 %16, label %.loopexit, label %6

._crit_edge:                                      ; preds = %6, %5
  %.022.lcssa = phi i64 [ %2, %5 ], [ %.02030, %6 ]
  %.020.lcssa = phi i64 [ %0, %5 ], [ %.121, %6 ]
  %.0.lcssa = phi i32 [ 0, %5 ], [ %spec.select, %6 ]
  %17 = icmp ne i64 %.020.lcssa, %.022.lcssa
  tail call void @llvm.assume(i1 %17)
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %._crit_edge
  %.019 = phi i32 [ %.0.lcssa, %._crit_edge ], [ -1, %.critedge ]
  ret i32 %.019
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write)
declare void @llvm.assume(i1 noundef) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(argmem: read, inaccessiblemem: write) 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(inaccessiblemem: write) }

!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 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


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