; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/DP Level 1/RENT/rent.ll (Z9partitionii)

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

@start = external dso_local global [10000 x i32], align 16
@finish = external dso_local global [10000 x i32], align 16
@price = external dso_local global [10000 x i32], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z9partitionii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %10 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %10, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  store i32 %14, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %9, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %101, %2
  %26 = load i32, ptr %9, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp sle i32 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %104

30:                                               ; preds = %25
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp sgt i32 %31, %35
  br i1 %36, label %37, label %100

37:                                               ; preds = %30
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %43
  store i32 %41, ptr %44, align 4, !tbaa !5
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %51
  store i32 %49, ptr %52, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %56
  store i32 %53, ptr %57, align 4, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %63
  store i32 %61, ptr %64, align 4, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = load i32, ptr %9, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %71
  store i32 %69, ptr %72, align 4, !tbaa !5
  %73 = load i32, ptr %7, align 4, !tbaa !5
  %74 = load i32, ptr %5, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %76
  store i32 %73, ptr %77, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = load i32, ptr %5, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %83
  store i32 %81, ptr %84, align 4, !tbaa !5
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = load i32, ptr %9, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  %93 = load i32, ptr %8, align 4, !tbaa !5
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %96
  store i32 %93, ptr %97, align 4, !tbaa !5
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %5, align 4, !tbaa !5
  br label %100

100:                                              ; preds = %37, %30
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %9, align 4, !tbaa !5
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %9, align 4, !tbaa !5
  br label %25, !llvm.loop !9

104:                                              ; preds = %29
  %105 = load i32, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %105
}

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

@start = external dso_local local_unnamed_addr global [10000 x i32], align 16
@finish = external dso_local local_unnamed_addr global [10000 x i32], align 16
@price = external dso_local local_unnamed_addr global [10000 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z9partitionii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %3
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %3
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not.not34 = icmp slt i32 %0, %1
  br i1 %.not.not34, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = sext i32 %1 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %30, %2
  %.030.lcssa = phi i32 [ %0, %2 ], [ %.1, %30 ]
  ret i32 %.030.lcssa

.lr.ph:                                           ; preds = %.lr.ph.preheader, %30
  %indvars.iv = phi i64 [ %3, %.lr.ph.preheader ], [ %indvars.iv.next, %30 ]
  %.03035 = phi i32 [ %0, %.lr.ph.preheader ], [ %.1, %30 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %10 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %indvars.iv.next
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp sgt i32 %5, %11
  br i1 %12, label %13, label %30

13:                                               ; preds = %.lr.ph
  %14 = sext i32 %.03035 to i64
  %15 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %14
  store i32 %11, ptr %15, align 4, !tbaa !5
  %16 = add nsw i32 %.03035, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10000 x i32], ptr @finish, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  store i32 %19, ptr %10, align 4, !tbaa !5
  store i32 %5, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %14
  store i32 %21, ptr %22, align 4, !tbaa !5
  %23 = getelementptr inbounds [10000 x i32], ptr @start, i64 0, i64 %17
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr %20, align 4, !tbaa !5
  store i32 %7, ptr %23, align 4, !tbaa !5
  %25 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %indvars.iv.next
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %14
  store i32 %26, ptr %27, align 4, !tbaa !5
  %28 = getelementptr inbounds [10000 x i32], ptr @price, i64 0, i64 %17
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %25, align 4, !tbaa !5
  store i32 %9, ptr %28, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph, %13
  %.1 = phi i32 [ %16, %13 ], [ %.03035, %.lr.ph ]
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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