; LLVM IR from aferikoglou/GenHLSOptimizer :: dataset/machsuite-sort-radix (sort)

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

9:                                                ; preds = %2
  br label %10

10:                                               ; preds = %9
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %34, %10
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 128
  br i1 %13, label %14, label %37

14:                                               ; preds = %11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = mul nsw i32 %15, 16
  %17 = sub nsw i32 %16, 1
  store i32 %17, ptr %6, align 4, !tbaa !9
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sub nsw i32 %19, 1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %18, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %24, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = add nsw i32 %23, %28
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i32, ptr %30, i64 %32
  store i32 %29, ptr %33, align 4, !tbaa !9
  br label %34

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

37:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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"}


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local void @sum_scan(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  store i32 0, ptr %0, align 4, !tbaa !5
  %invariant.gep = getelementptr i8, ptr %1, i64 -4
  br label %3

3:                                                ; preds = %13, %2
  %store_forwarded = phi i32 [ 0, %2 ], [ %16, %13 ]
  %indvars.iv = phi i64 [ 1, %2 ], [ %indvars.iv.next.3, %13 ]
  %4 = getelementptr i32, ptr %0, i64 %indvars.iv
  %gep.idx = shl i64 %indvars.iv, 6
  %gep = getelementptr i8, ptr %invariant.gep, i64 %gep.idx
  %5 = load i32, ptr %gep, align 4, !tbaa !5
  %6 = add nsw i32 %5, %store_forwarded
  store i32 %6, ptr %4, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = getelementptr i32, ptr %0, i64 %indvars.iv.next
  %gep.idx.1 = shl i64 %indvars.iv.next, 6
  %gep.1 = getelementptr i8, ptr %invariant.gep, i64 %gep.idx.1
  %8 = load i32, ptr %gep.1, align 4, !tbaa !5
  %9 = add nsw i32 %8, %6
  store i32 %9, ptr %7, align 4, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %10 = getelementptr i32, ptr %0, i64 %indvars.iv.next.1
  %gep.idx.2 = shl i64 %indvars.iv.next.1, 6
  %gep.2 = getelementptr i8, ptr %invariant.gep, i64 %gep.idx.2
  %11 = load i32, ptr %gep.2, align 4, !tbaa !5
  %12 = add nsw i32 %11, %9
  store i32 %12, ptr %10, align 4, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 128
  br i1 %exitcond.not.2, label %17, label %13, !llvm.loop !9

13:                                               ; preds = %3
  %14 = getelementptr i32, ptr %0, i64 %indvars.iv.next.2
  %gep.idx.3 = shl i64 %indvars.iv.next.2, 6
  %gep.3 = getelementptr i8, ptr %invariant.gep, i64 %gep.idx.3
  %15 = load i32, ptr %gep.3, align 4, !tbaa !5
  %16 = add nsw i32 %15, %12
  store i32 %16, ptr %14, align 4, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  br label %3

17:                                               ; preds = %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass