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

; 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

; 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) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @stable_binary_insertion_sort(ptr noundef, i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local void @stable_merge_sort(ptr noundef %0, i64 noundef %1) #4 {
  %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 %107

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 @stable_binary_insertion_sort(ptr noundef %21, i64 noundef %22)
  store i32 1, ptr %10, align 4
  br label %107

23:                                               ; preds = %17
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i64, ptr %6, align 8, !tbaa !9
  call void @stable_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 ptr, 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 @stable_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 = %98, %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 %101

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 %89

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 %79

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

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

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

78:                                               ; preds = %69, %60
  br label %88

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

88:                                               ; preds = %79, %78
  br label %98

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

98:                                               ; preds = %89, %88
  %99 = load i64, ptr %7, align 8, !tbaa !9
  %100 = add i64 %99, 1
  store i64 %100, ptr %7, align 8, !tbaa !9
  br label %35, !llvm.loop !13

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

107:                                              ; preds = %101, %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
  %108 = load i32, ptr %10, align 4
  switch i32 %108, label %110 [
    i32 0, label %109
    i32 1, label %109
  ]

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

110:                                              ; preds = %107
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #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 = !{!12, !12, i64 0}
!12 = !{!"int", !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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; 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) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @stable_binary_insertion_sort(ptr noundef, i64 noundef) local_unnamed_addr #3

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

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

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

8:                                                ; preds = %5
  tail call void @stable_merge_sort(ptr noundef %0, i64 noundef %3)
  %9 = getelementptr inbounds ptr, ptr %0, i64 %3
  %10 = sub i64 %1, %3
  tail call void @stable_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, %39
  %.050 = phi i64 [ %3, %8 ], [ %.1, %39 ]
  %.04349 = phi i64 [ 0, %8 ], [ %.144, %39 ]
  %.04548 = phi i64 [ 0, %8 ], [ %40, %39 ]
  %14 = icmp ult i64 %.04349, %3
  br i1 %14, label %15, label %34

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

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

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

27:                                               ; preds = %17
  %28 = add nuw i64 %.050, 1
  store ptr %22, ptr %24, align 8, !tbaa !5
  br label %39

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

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

39:                                               ; preds = %29, %27, %25, %34
  %.144 = phi i64 [ %26, %25 ], [ %.04349, %27 ], [ %30, %29 ], [ %.04349, %34 ]
  %.1 = phi i64 [ %.050, %25 ], [ %28, %27 ], [ %.050, %29 ], [ %35, %34 ]
  %40 = add nuw i64 %.04548, 1
  %.not = icmp eq i64 %40, %1
  br i1 %.not, label %41, label %13, !llvm.loop !11

41:                                               ; preds = %39
  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 %42

42:                                               ; preds = %2, %41, %7
  ret void
}

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


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