; LLVM IR from h-ssiqueira/Sort_Algorithms :: src/networksConcurrent (bitonicSort)

; 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
define dso_local void @bitonicMerge(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 1
  br i1 %13, label %14, label %75

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = sdiv i32 %15, 2
  store i32 %16, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i64, ptr %17, i64 %19
  store ptr %20, ptr %11, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %61, %14
  %22 = load ptr, ptr %11, align 8, !tbaa !5
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i64, ptr %23, i64 %25
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i64, ptr %26, i64 %28
  %30 = icmp ult ptr %22, %29
  br i1 %30, label %32, label %31

31:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %64

32:                                               ; preds = %21
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load ptr, ptr %11, align 8, !tbaa !5
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i64, ptr %36, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !11
  %41 = icmp sgt i64 %35, %40
  %42 = zext i1 %41 to i32
  %43 = icmp eq i32 %33, %42
  br i1 %43, label %44, label %60

44:                                               ; preds = %32
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load i64, ptr %45, align 8, !tbaa !11
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr %10, align 4, !tbaa !9
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds i64, ptr %48, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %52, ptr %53, align 8, !tbaa !11
  %54 = load i32, ptr %10, align 4, !tbaa !9
  %55 = sext i32 %54 to i64
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i64, ptr %56, i64 %58
  store i64 %55, ptr %59, align 8, !tbaa !11
  br label %60

60:                                               ; preds = %44, %32
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %11, align 8, !tbaa !5
  %63 = getelementptr inbounds i64, ptr %62, i32 1
  store ptr %63, ptr %11, align 8, !tbaa !5
  br label %21, !llvm.loop !13

64:                                               ; preds = %31
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %8, align 4, !tbaa !9
  call void @bitonicMerge(ptr noundef %65, i32 noundef %66, i32 noundef %67, i32 noundef %68)
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = load i32, ptr %9, align 4, !tbaa !9
  %72 = add nsw i32 %70, %71
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr %8, align 4, !tbaa !9
  call void @bitonicMerge(ptr noundef %69, i32 noundef %72, i32 noundef %73, i32 noundef %74)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %75

75:                                               ; preds = %64, %4
  ret void
}

; 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 = { 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 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @bitonicMerge(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  br label %tailrecurse45

tailrecurse45:                                    ; preds = %.lr.ph36, %4
  %.tr46 = phi i32 [ %1, %4 ], [ %.tr2933, %.lr.ph36 ]
  %.tr47 = phi i32 [ %2, %4 ], [ %6, %.lr.ph36 ]
  %5 = icmp sgt i32 %.tr47, 1
  br i1 %5, label %.lr.ph36, label %tailrecurse._crit_edge

.lr.ph36:                                         ; preds = %tailrecurse45, %tailrecurse
  %.tr3034 = phi i32 [ %6, %tailrecurse ], [ %.tr47, %tailrecurse45 ]
  %.tr2933 = phi i32 [ %11, %tailrecurse ], [ %.tr46, %tailrecurse45 ]
  %6 = lshr i32 %.tr3034, 1
  %7 = sext i32 %.tr2933 to i64
  %8 = getelementptr inbounds i64, ptr %0, i64 %7
  %9 = zext nneg i32 %6 to i64
  %10 = getelementptr inbounds i64, ptr %8, i64 %9
  %.not = icmp ult i32 %.tr3034, 2
  br i1 %.not, label %tailrecurse45, label %.lr.ph

tailrecurse:                                      ; preds = %21
  tail call void @bitonicMerge(ptr noundef %0, i32 noundef %.tr2933, i32 noundef %6, i32 noundef %3)
  %11 = add nsw i32 %6, %.tr2933
  %12 = icmp ugt i32 %.tr3034, 3
  br i1 %12, label %.lr.ph36, label %tailrecurse._crit_edge

.lr.ph:                                           ; preds = %.lr.ph36, %21
  %.032 = phi ptr [ %22, %21 ], [ %8, %.lr.ph36 ]
  %13 = load i64, ptr %.032, align 8, !tbaa !5
  %14 = getelementptr inbounds i64, ptr %.032, i64 %9
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = icmp sgt i64 %13, %15
  %17 = zext i1 %16 to i32
  %18 = icmp eq i32 %17, %3
  br i1 %18, label %19, label %21

19:                                               ; preds = %.lr.ph
  store i64 %15, ptr %.032, align 8, !tbaa !5
  %sext = shl i64 %13, 32
  %20 = ashr exact i64 %sext, 32
  store i64 %20, ptr %14, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %.lr.ph, %19
  %22 = getelementptr inbounds i8, ptr %.032, i64 8
  %23 = icmp ult ptr %22, %10
  br i1 %23, label %.lr.ph, label %tailrecurse, !llvm.loop !9

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %tailrecurse45
  ret void
}

attributes #0 = { nofree nosync nounwind memory(readwrite, 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 = !{!"long", !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,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass