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

%struct.sorter_temp_storage_t = type { i64, ptr }
%struct.sorter_tim_sort_run_t = type { i64, i64 }

; 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_tim_sort(ptr noundef %0, i64 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca %struct.sorter_temp_storage_t, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [128 x %struct.sorter_tim_sort_run_t], align 16
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = 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) #3
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 2048, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !9
  %12 = load i64, ptr %4, align 8, !tbaa !9
  %13 = icmp ule i64 %12, 1
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i32 1, ptr %11, align 4
  br label %82

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

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !9
  call void @sorter_binary_insertion_sort(ptr noundef %19, i64 noundef %20)
  store i32 1, ptr %11, align 4
  br label %82

21:                                               ; preds = %15
  %22 = load i64, ptr %4, align 8, !tbaa !9
  %23 = call i32 @compute_minrun(i64 noundef %22)
  %24 = sext i32 %23 to i64
  store i64 %24, ptr %5, align 8, !tbaa !9
  store ptr %6, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.sorter_temp_storage_t, ptr %25, i32 0, i32 0
  store i64 0, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.sorter_temp_storage_t, ptr %27, i32 0, i32 1
  store ptr null, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i64, ptr %4, align 8, !tbaa !9
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds [128 x %struct.sorter_tim_sort_run_t], ptr %8, i64 0, i64 0
  %34 = call i32 @sorter_push_next(ptr noundef %29, i64 noundef %30, ptr noundef %31, i64 noundef %32, ptr noundef %33, ptr noundef %9, ptr noundef %10)
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %37, label %36

36:                                               ; preds = %21
  store i32 1, ptr %11, align 4
  br label %82

37:                                               ; preds = %21
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i64, ptr %4, align 8, !tbaa !9
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = getelementptr inbounds [128 x %struct.sorter_tim_sort_run_t], ptr %8, i64 0, i64 0
  %43 = call i32 @sorter_push_next(ptr noundef %38, i64 noundef %39, ptr noundef %40, i64 noundef %41, ptr noundef %42, ptr noundef %9, ptr noundef %10)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %37
  store i32 1, ptr %11, align 4
  br label %82

46:                                               ; preds = %37
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i64, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds [128 x %struct.sorter_tim_sort_run_t], ptr %8, i64 0, i64 0
  %52 = call i32 @sorter_push_next(ptr noundef %47, i64 noundef %48, ptr noundef %49, i64 noundef %50, ptr noundef %51, ptr noundef %9, ptr noundef %10)
  %53 = icmp ne i32 %52, 0
  br i1 %53, label %55, label %54

54:                                               ; preds = %46
  store i32 1, ptr %11, align 4
  br label %82

55:                                               ; preds = %46
  br label %56

56:                                               ; preds = %81, %63, %55
  br label %57

57:                                               ; preds = %56
  %58 = getelementptr inbounds [128 x %struct.sorter_tim_sort_run_t], ptr %8, i64 0, i64 0
  %59 = load i64, ptr %9, align 8, !tbaa !9
  %60 = trunc i64 %59 to i32
  %61 = call i32 @sorter_check_invariant(ptr noundef %58, i32 noundef %60)
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %72, label %63

63:                                               ; preds = %57
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds [128 x %struct.sorter_tim_sort_run_t], ptr %8, i64 0, i64 0
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = trunc i64 %66 to i32
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i64, ptr %4, align 8, !tbaa !9
  %70 = call i32 @sorter_tim_sort_collapse(ptr noundef %64, ptr noundef %65, i32 noundef %67, ptr noundef %68, i64 noundef %69)
  %71 = sext i32 %70 to i64
  store i64 %71, ptr %9, align 8, !tbaa !9
  br label %56

72:                                               ; preds = %57
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = load i64, ptr %4, align 8, !tbaa !9
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load i64, ptr %5, align 8, !tbaa !9
  %77 = getelementptr inbounds [128 x %struct.sorter_tim_sort_run_t], ptr %8, i64 0, i64 0
  %78 = call i32 @sorter_push_next(ptr noundef %73, i64 noundef %74, ptr noundef %75, i64 noundef %76, ptr noundef %77, ptr noundef %9, ptr noundef %10)
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %81, label %80

80:                                               ; preds = %72
  store i32 1, ptr %11, align 4
  br label %82

81:                                               ; preds = %72
  br label %56

82:                                               ; preds = %80, %54, %45, %36, %18, %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 2048, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @compute_minrun(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @sorter_push_next(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @sorter_check_invariant(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @sorter_tim_sort_collapse(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 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 = { inlinehint 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 #3 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}


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

%struct.sorter_temp_storage_t = type { i64, ptr }
%struct.sorter_tim_sort_run_t = type { i64, i64 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress 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) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @sorter_tim_sort(ptr noundef %0, i64 noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.sorter_temp_storage_t, align 8
  %4 = alloca [128 x %struct.sorter_tim_sort_run_t], align 16
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 2048, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  %7 = icmp ult i64 %1, 2
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %2
  %9 = icmp ult i64 %1, 64
  br i1 %9, label %10, label %11

10:                                               ; preds = %8
  tail call void @sorter_binary_insertion_sort(ptr noundef %0, i64 noundef %1)
  br label %.loopexit

11:                                               ; preds = %8
  %12 = tail call i32 @compute_minrun(i64 noundef %1)
  %13 = sext i32 %12 to i64
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %3, i8 0, i64 16, i1 false)
  %14 = call i32 @sorter_push_next(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %3, i64 noundef %13, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %.not = icmp eq i32 %14, 0
  br i1 %.not, label %.loopexit, label %15

15:                                               ; preds = %11
  %16 = call i32 @sorter_push_next(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %3, i64 noundef %13, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %.not25 = icmp eq i32 %16, 0
  br i1 %.not25, label %.loopexit, label %17

17:                                               ; preds = %15
  %18 = call i32 @sorter_push_next(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %3, i64 noundef %13, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %.not26 = icmp eq i32 %18, 0
  br i1 %.not26, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %17, %.preheader.backedge
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = trunc i64 %19 to i32
  %21 = call i32 @sorter_check_invariant(ptr noundef nonnull %4, i32 noundef %20)
  %.not27 = icmp eq i32 %21, 0
  br i1 %.not27, label %22, label %27

22:                                               ; preds = %.preheader
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = trunc i64 %23 to i32
  %25 = call i32 @sorter_tim_sort_collapse(ptr noundef %0, ptr noundef nonnull %4, i32 noundef %24, ptr noundef nonnull %3, i64 noundef %1)
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %5, align 8, !tbaa !5
  br label %.preheader.backedge

.preheader.backedge:                              ; preds = %22, %27
  br label %.preheader

27:                                               ; preds = %.preheader
  %28 = call i32 @sorter_push_next(ptr noundef %0, i64 noundef %1, ptr noundef nonnull %3, i64 noundef %13, ptr noundef nonnull %4, ptr noundef nonnull %5, ptr noundef nonnull %6)
  %.not28 = icmp eq i32 %28, 0
  br i1 %.not28, label %.loopexit, label %.preheader.backedge

.loopexit:                                        ; preds = %27, %17, %15, %11, %2, %10
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 2048, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @compute_minrun(i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @sorter_push_next(ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @sorter_check_invariant(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @sorter_tim_sort_collapse(ptr noundef, ptr noundef, i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { mustprogress 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 = { inlinehint 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass