; LLVM IR from siconos/siconos :: externals/sort/test (benchmark)

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

; Function Attrs: nounwind uwtable
define dso_local void @sorter_merge_sort(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %11 = load i64, ptr %4, align 8, !tbaa !9
  %12 = udiv i64 %11, 2
  store i64 %12, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %13 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %13, ptr %9, align 8, !tbaa !9
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = icmp ule i64 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %2
  store i32 1, ptr %10, align 4
  br label %105

17:                                               ; preds = %2
  %18 = load i64, ptr %4, align 8, !tbaa !9
  %19 = icmp ult i64 %18, 16
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i64, ptr %4, align 8, !tbaa !9
  call void @sorter_binary_insertion_sort(ptr noundef %21, i64 noundef %22)
  store i32 1, ptr %10, align 4
  br label %105

23:                                               ; preds = %17
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  call void @sorter_merge_sort(ptr noundef %24, i64 noundef %25)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i64, ptr %6, align 8, !tbaa !9
  %28 = getelementptr inbounds i64, ptr %26, i64 %27
  %29 = load i64, ptr %4, align 8, !tbaa !9
  %30 = load i64, ptr %6, align 8, !tbaa !9
  %31 = sub i64 %29, %30
  call void @sorter_merge_sort(ptr noundef %28, i64 noundef %31)
  %32 = load i64, ptr %4, align 8, !tbaa !9
  %33 = mul i64 %32, 8
  %34 = call noalias ptr @malloc(i64 noundef %33) #6
  store ptr %34, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %96, %23
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %4, align 8, !tbaa !9
  %38 = icmp ne i64 %36, %37
  br i1 %38, label %39, label %99

39:                                               ; preds = %35
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = load i64, ptr %6, align 8, !tbaa !9
  %42 = icmp ult i64 %40, %41
  br i1 %42, label %43, label %87

43:                                               ; preds = %39
  %44 = load i64, ptr %9, align 8, !tbaa !9
  %45 = load i64, ptr %4, align 8, !tbaa !9
  %46 = icmp ult i64 %44, %45
  br i1 %46, label %47, label %77

47:                                               ; preds = %43
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = load i64, ptr %8, align 8, !tbaa !9
  %50 = getelementptr inbounds i64, ptr %48, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = getelementptr inbounds i64, ptr %52, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = sub nsw i64 %51, %55
  %57 = icmp sle i64 %56, 0
  br i1 %57, label %58, label %67

58:                                               ; preds = %47
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = load i64, ptr %8, align 8, !tbaa !9
  %61 = add i64 %60, 1
  store i64 %61, ptr %8, align 8, !tbaa !9
  %62 = getelementptr inbounds i64, ptr %59, i64 %60
  %63 = load i64, ptr %62, align 8, !tbaa !9
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = load i64, ptr %7, align 8, !tbaa !9
  %66 = getelementptr inbounds i64, ptr %64, i64 %65
  store i64 %63, ptr %66, align 8, !tbaa !9
  br label %76

67:                                               ; preds = %47
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = add i64 %69, 1
  store i64 %70, ptr %9, align 8, !tbaa !9
  %71 = getelementptr inbounds i64, ptr %68, i64 %69
  %72 = load i64, ptr %71, align 8, !tbaa !9
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = load i64, ptr %7, align 8, !tbaa !9
  %75 = getelementptr inbounds i64, ptr %73, i64 %74
  store i64 %72, ptr %75, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %67, %58
  br label %86

77:                                               ; preds = %43
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = load i64, ptr %8, align 8, !tbaa !9
  %80 = add i64 %79, 1
  store i64 %80, ptr %8, align 8, !tbaa !9
  %81 = getelementptr inbounds i64, ptr %78, i64 %79
  %82 = load i64, ptr %81, align 8, !tbaa !9
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = load i64, ptr %7, align 8, !tbaa !9
  %85 = getelementptr inbounds i64, ptr %83, i64 %84
  store i64 %82, ptr %85, align 8, !tbaa !9
  br label %86

86:                                               ; preds = %77, %76
  br label %96

87:                                               ; preds = %39
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = load i64, ptr %9, align 8, !tbaa !9
  %90 = add i64 %89, 1
  store i64 %90, ptr %9, align 8, !tbaa !9
  %91 = getelementptr inbounds i64, ptr %88, i64 %89
  %92 = load i64, ptr %91, align 8, !tbaa !9
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = load i64, ptr %7, align 8, !tbaa !9
  %95 = getelementptr inbounds i64, ptr %93, i64 %94
  store i64 %92, ptr %95, align 8, !tbaa !9
  br label %96

96:                                               ; preds = %87, %86
  %97 = load i64, ptr %7, align 8, !tbaa !9
  %98 = add i64 %97, 1
  store i64 %98, ptr %7, align 8, !tbaa !9
  br label %35, !llvm.loop !11

99:                                               ; preds = %35
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = load ptr, ptr %5, align 8, !tbaa !5
  %102 = load i64, ptr %4, align 8, !tbaa !9
  %103 = mul i64 %102, 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %100, ptr align 8 %101, i64 %103, i1 false)
  %104 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %104) #5
  store i32 0, ptr %10, align 4
  br label %105

105:                                              ; preds = %99, %20, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  %106 = load i32, ptr %10, align 4
  switch i32 %106, label %108 [
    i32 0, label %107
    i32 1, label %107
  ]

107:                                              ; preds = %105, %105
  ret void

108:                                              ; preds = %105
  unreachable
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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 allocsize(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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!"long", !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 @sorter_binary_insertion_sort(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @sorter_merge_sort(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = lshr i64 %1, 1
  %4 = icmp ult i64 %1, 2
  br i1 %4, label %40, label %5

5:                                                ; preds = %2
  %6 = icmp ult i64 %1, 16
  br i1 %6, label %7, label %8

7:                                                ; preds = %5
  tail call void @sorter_binary_insertion_sort(ptr noundef %0, i64 noundef %1)
  br label %40

8:                                                ; preds = %5
  tail call void @sorter_merge_sort(ptr noundef %0, i64 noundef %3)
  %9 = getelementptr inbounds i64, ptr %0, i64 %3
  %10 = sub i64 %1, %3
  tail call void @sorter_merge_sort(ptr noundef %9, i64 noundef %10)
  %11 = shl i64 %1, 3
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #4
  br label %13

13:                                               ; preds = %8, %37
  %.050 = phi i64 [ %3, %8 ], [ %.1, %37 ]
  %.04349 = phi i64 [ 0, %8 ], [ %.144, %37 ]
  %.04548 = phi i64 [ 0, %8 ], [ %38, %37 ]
  %14 = icmp ult i64 %.04349, %3
  br i1 %14, label %15, label %32

15:                                               ; preds = %13
  %16 = icmp ult i64 %.050, %1
  br i1 %16, label %17, label %27

17:                                               ; preds = %15
  %18 = getelementptr inbounds i64, ptr %0, i64 %.04349
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = getelementptr inbounds i64, ptr %0, i64 %.050
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %.not47 = icmp sgt i64 %19, %21
  %22 = getelementptr inbounds i64, ptr %12, i64 %.04548
  br i1 %.not47, label %25, label %23

23:                                               ; preds = %17
  %24 = add nuw nsw i64 %.04349, 1
  store i64 %19, ptr %22, align 8, !tbaa !5
  br label %37

25:                                               ; preds = %17
  %26 = add nuw i64 %.050, 1
  store i64 %21, ptr %22, align 8, !tbaa !5
  br label %37

27:                                               ; preds = %15
  %28 = add nuw nsw i64 %.04349, 1
  %29 = getelementptr inbounds i64, ptr %0, i64 %.04349
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr %12, i64 %.04548
  store i64 %30, ptr %31, align 8, !tbaa !5
  br label %37

32:                                               ; preds = %13
  %33 = add i64 %.050, 1
  %34 = getelementptr inbounds i64, ptr %0, i64 %.050
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %12, i64 %.04548
  store i64 %35, ptr %36, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %27, %25, %23, %32
  %.144 = phi i64 [ %24, %23 ], [ %.04349, %25 ], [ %28, %27 ], [ %.04349, %32 ]
  %.1 = phi i64 [ %.050, %23 ], [ %26, %25 ], [ %.050, %27 ], [ %33, %32 ]
  %38 = add nuw i64 %.04548, 1
  %.not = icmp eq i64 %38, %1
  br i1 %.not, label %39, label %13, !llvm.loop !9

39:                                               ; preds = %37
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %0, ptr nonnull align 8 %12, i64 %11, i1 false)
  tail call void @free(ptr noundef nonnull %12) #5
  br label %40

40:                                               ; preds = %2, %39, %7
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #4 = { nounwind allocsize(0) }
attributes #5 = { 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 = !{!"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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass