; LLVM IR from siconos/siconos :: externals/SOL/lumod-c (commonlib)

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

%union.QSORTrec = type { %struct._QSORTrec1 }
%struct._QSORTrec1 = type { ptr, ptr }

; 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: 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: nounwind uwtable
define dso_local i32 @QS_finish(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %union.QSORTrec, 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 ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #3
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %9, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %59, %4
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp sle i32 %16, %17
  br i1 %18, label %19, label %62

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %union.QSORTrec, ptr %20, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %23, i64 16, i1 false), !tbaa.struct !11
  %24 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %24, ptr %10, align 4, !tbaa !9
  br label %25

25:                                               ; preds = %40, %19
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp sgt i32 %26, %27
  br i1 %28, label %29, label %38

29:                                               ; preds = %25
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !9
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds %union.QSORTrec, ptr %31, i64 %34
  %36 = call i32 %30(ptr noundef %35, ptr noundef %12)
  %37 = icmp sgt i32 %36, 0
  br label %38

38:                                               ; preds = %29, %25
  %39 = phi i1 [ false, %25 ], [ %37, %29 ]
  br i1 %39, label %40, label %54

40:                                               ; preds = %38
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %union.QSORTrec, ptr %41, i64 %43
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = sub nsw i32 %46, 1
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds %union.QSORTrec, ptr %45, i64 %48
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %49, i64 16, i1 false), !tbaa.struct !11
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr %10, align 4, !tbaa !9
  %52 = load i32, ptr %11, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %11, align 4, !tbaa !9
  br label %25, !llvm.loop !13

54:                                               ; preds = %38
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds %union.QSORTrec, ptr %55, i64 %57
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %58, ptr align 8 %12, i64 16, i1 false), !tbaa.struct !11
  br label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %9, align 4, !tbaa !9
  br label %15, !llvm.loop !15

62:                                               ; preds = %15
  %63 = load i32, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret i32 %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 16, !12}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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

%union.QSORTrec = type { %struct._QSORTrec1 }
%struct._QSORTrec1 = type { ptr, ptr }

; 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: 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: nounwind uwtable
define dso_local i32 @QS_finish(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3) local_unnamed_addr #2 {
  %5 = alloca %union.QSORTrec, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #3
  %.not.not29 = icmp slt i32 %1, %2
  br i1 %.not.not29, label %.lr.ph32.preheader, label %._crit_edge

.lr.ph32.preheader:                               ; preds = %4
  %6 = sext i32 %1 to i64
  %wide.trip.count = sext i32 %2 to i64
  br label %.lr.ph32

.lr.ph32:                                         ; preds = %.lr.ph32.preheader, %.critedge
  %indvars.iv39 = phi i64 [ %6, %.lr.ph32.preheader ], [ %indvars.iv.next40, %.critedge ]
  %indvars.iv36 = phi i32 [ 1, %.lr.ph32.preheader ], [ %indvars.iv.next37, %.critedge ]
  %indvars.iv.in = phi i64 [ %6, %.lr.ph32.preheader ], [ %indvars.iv, %.critedge ]
  %.030 = phi i32 [ 0, %.lr.ph32.preheader ], [ %.1.lcssa, %.critedge ]
  %indvars.iv = add nsw i64 %indvars.iv.in, 1
  %indvars.iv.next40 = add nsw i64 %indvars.iv39, 1
  %7 = getelementptr inbounds %union.QSORTrec, ptr %0, i64 %indvars.iv.next40
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(16) %7, i64 16, i1 false), !tbaa.struct !5
  %.not = icmp slt i64 %indvars.iv39, %6
  %8 = trunc nsw i64 %indvars.iv.next40 to i32
  br i1 %.not, label %.critedge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.lr.ph32
  %9 = add i32 %.030, %indvars.iv36
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %14
  %indvars.iv34 = phi i64 [ %indvars.iv, %.lr.ph.preheader ], [ %indvars.iv.next35, %14 ]
  %.123 = phi i32 [ %.030, %.lr.ph.preheader ], [ %15, %14 ]
  %10 = getelementptr %union.QSORTrec, ptr %0, i64 %indvars.iv34
  %11 = getelementptr i8, ptr %10, i64 -16
  %12 = call i32 %3(ptr noundef %11, ptr noundef nonnull %5) #3
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %.critedge.loopexit.split.loop.exit42

14:                                               ; preds = %.lr.ph
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef nonnull align 8 dereferenceable(16) %11, i64 16, i1 false), !tbaa.struct !5
  %indvars.iv.next35 = add nsw i64 %indvars.iv34, -1
  %15 = add nsw i32 %.123, 1
  %16 = icmp sgt i64 %indvars.iv.next35, %6
  br i1 %16, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge.loopexit.split.loop.exit42:             ; preds = %.lr.ph
  %17 = trunc nsw i64 %indvars.iv34 to i32
  br label %.critedge

.critedge:                                        ; preds = %14, %.critedge.loopexit.split.loop.exit42, %.lr.ph32
  %.020.lcssa = phi i32 [ %8, %.lr.ph32 ], [ %17, %.critedge.loopexit.split.loop.exit42 ], [ %1, %14 ]
  %.1.lcssa = phi i32 [ %.030, %.lr.ph32 ], [ %.123, %.critedge.loopexit.split.loop.exit42 ], [ %9, %14 ]
  %18 = sext i32 %.020.lcssa to i64
  %19 = getelementptr inbounds %union.QSORTrec, ptr %0, i64 %18
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr noundef nonnull align 8 dereferenceable(16) %5, i64 16, i1 false), !tbaa.struct !5
  %indvars.iv.next37 = add i32 %indvars.iv36, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next40, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph32, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %4
  %.0.lcssa = phi i32 [ 0, %4 ], [ %.1.lcssa, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #3
  ret i32 %.0.lcssa
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{i64 0, i64 16, !6}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass