; 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: nounwind uwtable
declare dso_local void @local_scan(ptr noundef) #0

; 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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @init(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ss_sort(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %4
  br label %12

12:                                               ; preds = %11
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %47, %12
  %14 = load i32, ptr %9, align 4, !tbaa !9
  %15 = icmp slt i32 %14, 32
  br i1 %15, label %16, label %50

16:                                               ; preds = %13
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @init(ptr noundef %17)
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %20, label %24

20:                                               ; preds = %16
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  call void @hist(ptr noundef %21, ptr noundef %22, i32 noundef %23)
  br label %28

24:                                               ; preds = %16
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load i32, ptr %9, align 4, !tbaa !9
  call void @hist(ptr noundef %25, ptr noundef %26, i32 noundef %27)
  br label %28

28:                                               ; preds = %24, %20
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  call void @local_scan(ptr noundef %29)
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  call void @sum_scan(ptr noundef %30, ptr noundef %31)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  call void @last_step_scan(ptr noundef %32, ptr noundef %33)
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %41

36:                                               ; preds = %28
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !9
  call void @update(ptr noundef %37, ptr noundef %38, ptr noundef %39, i32 noundef %40)
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %46

41:                                               ; preds = %28
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !9
  call void @update(ptr noundef %42, ptr noundef %43, ptr noundef %44, i32 noundef %45)
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %46

46:                                               ; preds = %41, %36
  br label %47

47:                                               ; preds = %46
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = add nsw i32 %48, 2
  store i32 %49, ptr %9, align 4, !tbaa !9
  br label %13, !llvm.loop !11

50:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  ret void
}

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 = { 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: nounwind uwtable
declare dso_local void @local_scan(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @sum_scan(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @last_step_scan(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @init(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @ss_sort(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  br label %5

5:                                                ; preds = %4, %9
  %.025 = phi i32 [ 0, %4 ], [ %.1, %9 ]
  %.02324 = phi i32 [ 0, %4 ], [ %10, %9 ]
  tail call void @init(ptr noundef %2)
  %6 = icmp eq i32 %.025, 0
  %. = select i1 %6, ptr %0, ptr %1
  tail call void @hist(ptr noundef %2, ptr noundef %., i32 noundef %.02324)
  tail call void @local_scan(ptr noundef %2)
  tail call void @sum_scan(ptr noundef %3, ptr noundef %2)
  tail call void @last_step_scan(ptr noundef %2, ptr noundef %3)
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @update(ptr noundef %1, ptr noundef %2, ptr noundef %0, i32 noundef %.02324)
  br label %9

8:                                                ; preds = %5
  tail call void @update(ptr noundef %0, ptr noundef %2, ptr noundef %1, i32 noundef %.02324)
  br label %9

9:                                                ; preds = %7, %8
  %.1 = phi i32 [ 1, %7 ], [ 0, %8 ]
  %10 = add nuw nsw i32 %.02324, 2
  %11 = icmp ult i32 %.02324, 30
  br i1 %11, label %5, label %12, !llvm.loop !5

12:                                               ; preds = %9
  ret void
}

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

!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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass