; LLVM IR from HarshCasper/NeoAlgo :: C/sort (oddevensort)

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

5:                                                ; preds = %71, %1
  %6 = load i32, ptr %3, align 4, !tbaa !9
  %7 = icmp ne i32 %6, 0
  %8 = xor i1 %7, true
  br i1 %8, label %9, label %72

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

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

13:                                               ; preds = %10
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr %14, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %19, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp sgt i32 %18, %24
  br i1 %25, label %26, label %36

26:                                               ; preds = %13
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr %27, i64 %29
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = load i32, ptr %4, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %31, i64 %34
  call void @swap(ptr noundef %30, ptr noundef %35)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %26, %13
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %4, align 4, !tbaa !9
  %39 = add nsw i32 %38, 2
  store i32 %39, ptr %4, align 4, !tbaa !9
  br label %10, !llvm.loop !11

40:                                               ; preds = %10
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %68, %40
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = icmp slt i32 %42, 6
  br i1 %43, label %44, label %71

44:                                               ; preds = %41
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i32, ptr %45, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %50, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp sgt i32 %49, %55
  br i1 %56, label %57, label %67

57:                                               ; preds = %44
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds i32, ptr %58, i64 %60
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %62, i64 %65
  call void @swap(ptr noundef %61, ptr noundef %66)
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %57, %44
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = add nsw i32 %69, 2
  store i32 %70, ptr %4, align 4, !tbaa !9
  br label %41, !llvm.loop !13

71:                                               ; preds = %41
  br label %5, !llvm.loop !14

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

; 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
declare dso_local void @swap(ptr noundef, ptr noundef) #1

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"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !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: nounwind uwtable
define dso_local void @oddeven_sort(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  br label %.preheader22

.preheader22:                                     ; preds = %1, %.loopexit
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp sgt i32 %10, %11
  br i1 %12, label %13, label %14

13:                                               ; preds = %.preheader22
  tail call void @swap(ptr noundef nonnull %2, ptr noundef nonnull %3)
  br label %14

14:                                               ; preds = %.preheader22, %13
  %.2 = phi i32 [ 0, %13 ], [ 1, %.preheader22 ]
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = icmp sgt i32 %15, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  tail call void @swap(ptr noundef nonnull %4, ptr noundef nonnull %5)
  br label %19

19:                                               ; preds = %18, %14
  %.2.1 = phi i32 [ 0, %18 ], [ %.2, %14 ]
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = icmp sgt i32 %20, %21
  br i1 %22, label %23, label %.preheader.preheader

23:                                               ; preds = %19
  tail call void @swap(ptr noundef nonnull %6, ptr noundef nonnull %7)
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %23, %19
  %.2.2 = phi i32 [ 0, %23 ], [ %.2.1, %19 ]
  %24 = load i32, ptr %0, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = icmp sgt i32 %24, %25
  br i1 %26, label %27, label %.preheader.1

27:                                               ; preds = %.preheader.preheader
  tail call void @swap(ptr noundef nonnull %0, ptr noundef nonnull %2)
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader, %27
  %.4 = phi i32 [ 0, %27 ], [ %.2.2, %.preheader.preheader ]
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = icmp sgt i32 %28, %29
  br i1 %30, label %31, label %.preheader.2

31:                                               ; preds = %.preheader.1
  tail call void @swap(ptr noundef nonnull %8, ptr noundef nonnull %4)
  br label %.preheader.2

.preheader.2:                                     ; preds = %31, %.preheader.1
  %.4.1 = phi i32 [ 0, %31 ], [ %.4, %.preheader.1 ]
  %32 = load i32, ptr %9, align 4, !tbaa !5
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = icmp sgt i32 %32, %33
  br i1 %34, label %35, label %.loopexit

35:                                               ; preds = %.preheader.2
  tail call void @swap(ptr noundef nonnull %9, ptr noundef nonnull %6)
  br label %.loopexit

.loopexit:                                        ; preds = %35, %.preheader.2
  %.4.2 = phi i32 [ 0, %35 ], [ %.4.1, %.preheader.2 ]
  %.not = icmp eq i32 %.4.2, 0
  br i1 %.not, label %.preheader22, label %36, !llvm.loop !9

36:                                               ; preds = %.loopexit
  ret void
}

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

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 = !{!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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass