; LLVM IR from siconos/siconos :: externals/lbl/metis4/myqsort.ll_ (ikeysort)

; 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.KeyValueType = type { i32, i32 }

@.str = external hidden unnamed_addr constant [23 x i8], align 1

; 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
define dso_local void @__ikeysort(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.KeyValueType, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp sle i32 %14, 1
  br i1 %15, label %16, label %17

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

17:                                               ; preds = %2
  %18 = load ptr, ptr %4, align 8, !tbaa !9
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds %struct.KeyValueType, ptr %18, i64 %20
  store ptr %21, ptr %11, align 8, !tbaa !9
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = icmp sge i32 %22, 1
  br i1 %23, label %24, label %29

24:                                               ; preds = %17
  %25 = load ptr, ptr %4, align 8, !tbaa !9
  %26 = load ptr, ptr %11, align 8, !tbaa !9
  call void @keyiqst(ptr noundef %25, ptr noundef %26)
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.KeyValueType, ptr %27, i64 1
  store ptr %28, ptr %8, align 8, !tbaa !9
  br label %31

29:                                               ; preds = %17
  %30 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %30, ptr %8, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %29, %24
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %32, ptr %7, align 8, !tbaa !9
  store ptr %32, ptr %6, align 8, !tbaa !9
  br label %33

33:                                               ; preds = %48, %31
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.KeyValueType, ptr %34, i32 1
  store ptr %35, ptr %7, align 8, !tbaa !9
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  %37 = icmp ult ptr %34, %36
  br i1 %37, label %38, label %49

38:                                               ; preds = %33
  %39 = load ptr, ptr %6, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.KeyValueType, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.KeyValueType, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = icmp sgt i32 %41, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %38
  %47 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %47, ptr %6, align 8, !tbaa !9
  br label %48

48:                                               ; preds = %46, %38
  br label %33, !llvm.loop !13

49:                                               ; preds = %33
  %50 = load ptr, ptr %6, align 8, !tbaa !9
  %51 = load ptr, ptr %4, align 8, !tbaa !9
  %52 = icmp ne ptr %50, %51
  br i1 %52, label %53, label %58

53:                                               ; preds = %49
  %54 = load ptr, ptr %4, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %54, i64 8, i1 false), !tbaa.struct !15
  %55 = load ptr, ptr %4, align 8, !tbaa !9
  %56 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %55, ptr align 4 %56, i64 8, i1 false), !tbaa.struct !15
  %57 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %57, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !15
  br label %58

58:                                               ; preds = %53, %49
  %59 = load ptr, ptr %4, align 8, !tbaa !9
  store ptr %59, ptr %9, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %105, %58
  %61 = load ptr, ptr %9, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.KeyValueType, ptr %61, i64 1
  store ptr %62, ptr %9, align 8, !tbaa !9
  store ptr %62, ptr %8, align 8, !tbaa !9
  %63 = load ptr, ptr %11, align 8, !tbaa !9
  %64 = icmp ult ptr %62, %63
  br i1 %64, label %65, label %106

65:                                               ; preds = %60
  br label %66

66:                                               ; preds = %75, %65
  %67 = load ptr, ptr %8, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.KeyValueType, ptr %67, i32 -1
  store ptr %68, ptr %8, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.KeyValueType, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.KeyValueType, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 4, !tbaa !11
  %74 = icmp sgt i32 %70, %73
  br i1 %74, label %75, label %76

75:                                               ; preds = %66
  br label %66, !llvm.loop !16

76:                                               ; preds = %66
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.KeyValueType, ptr %77, i64 1
  store ptr %78, ptr %8, align 8, !tbaa !9
  %79 = load ptr, ptr %9, align 8, !tbaa !9
  %80 = icmp ne ptr %78, %79
  br i1 %80, label %81, label %105

81:                                               ; preds = %76
  %82 = load ptr, ptr %9, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.KeyValueType, ptr %82, i64 1
  store ptr %83, ptr %7, align 8, !tbaa !9
  br label %84

84:                                               ; preds = %102, %81
  %85 = load ptr, ptr %7, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.KeyValueType, ptr %85, i32 -1
  store ptr %86, ptr %7, align 8, !tbaa !9
  %87 = load ptr, ptr %9, align 8, !tbaa !9
  %88 = icmp uge ptr %86, %87
  br i1 %88, label %89, label %104

89:                                               ; preds = %84
  %90 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %90, i64 8, i1 false), !tbaa.struct !15
  %91 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %91, ptr %6, align 8, !tbaa !9
  store ptr %91, ptr %5, align 8, !tbaa !9
  br label %92

92:                                               ; preds = %100, %89
  %93 = load ptr, ptr %6, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.KeyValueType, ptr %93, i64 -1
  store ptr %94, ptr %6, align 8, !tbaa !9
  %95 = load ptr, ptr %8, align 8, !tbaa !9
  %96 = icmp uge ptr %94, %95
  br i1 %96, label %97, label %102

97:                                               ; preds = %92
  %98 = load ptr, ptr %5, align 8, !tbaa !9
  %99 = load ptr, ptr %6, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %98, ptr align 4 %99, i64 8, i1 false), !tbaa.struct !15
  br label %100

100:                                              ; preds = %97
  %101 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %101, ptr %5, align 8, !tbaa !9
  br label %92, !llvm.loop !17

102:                                              ; preds = %92
  %103 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %103, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !15
  br label %84, !llvm.loop !18

104:                                              ; preds = %84
  br label %105

105:                                              ; preds = %104, %76
  br label %60, !llvm.loop !19

106:                                              ; preds = %60
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %130, %106
  %108 = load i32, ptr %13, align 4, !tbaa !5
  %109 = load i32, ptr %3, align 4, !tbaa !5
  %110 = sub nsw i32 %109, 1
  %111 = icmp slt i32 %108, %110
  br i1 %111, label %112, label %133

112:                                              ; preds = %107
  %113 = load ptr, ptr %4, align 8, !tbaa !9
  %114 = load i32, ptr %13, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds %struct.KeyValueType, ptr %113, i64 %115
  %117 = getelementptr inbounds %struct.KeyValueType, ptr %116, i32 0, i32 0
  %118 = load i32, ptr %117, align 4, !tbaa !11
  %119 = load ptr, ptr %4, align 8, !tbaa !9
  %120 = load i32, ptr %13, align 4, !tbaa !5
  %121 = add nsw i32 %120, 1
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds %struct.KeyValueType, ptr %119, i64 %122
  %124 = getelementptr inbounds %struct.KeyValueType, ptr %123, i32 0, i32 0
  %125 = load i32, ptr %124, align 4, !tbaa !11
  %126 = icmp sgt i32 %118, %125
  br i1 %126, label %127, label %129

127:                                              ; preds = %112
  %128 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %129

129:                                              ; preds = %127, %112
  br label %130

130:                                              ; preds = %129
  %131 = load i32, ptr %13, align 4, !tbaa !5
  %132 = add nsw i32 %131, 1
  store i32 %132, ptr %13, align 4, !tbaa !5
  br label %107, !llvm.loop !20

133:                                              ; preds = %107
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  store i32 0, ptr %12, align 4
  br label %134

134:                                              ; preds = %133, %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %135 = load i32, ptr %12, align 4
  switch i32 %135, label %137 [
    i32 0, label %136
    i32 1, label %136
  ]

136:                                              ; preds = %134, %134
  ret void

137:                                              ; preds = %134
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @keyiqst(ptr noundef, ptr 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

declare i32 @printf(ptr noundef, ...) #3

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

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"KeyValueType", !6, i64 0, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !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"

%struct.KeyValueType = type { i32, i32 }

@.str = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @__ikeysort(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp slt i32 %0, 2
  br i1 %3, label %.loopexit, label %4

4:                                                ; preds = %2
  %5 = zext nneg i32 %0 to i64
  %.idx = shl nuw nsw i64 %5, 3
  %6 = getelementptr inbounds i8, ptr %1, i64 %.idx
  tail call void @keyiqst(ptr noundef %1, ptr noundef nonnull %6)
  %invariant.gep = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = load i32, ptr %invariant.gep, align 4, !tbaa !5
  %.not = icmp sgt i32 %7, %8
  br i1 %.not, label %9, label %.preheader67.preheader

9:                                                ; preds = %4
  %10 = load <2 x i64>, ptr %1, align 4
  %11 = shufflevector <2 x i64> %10, <2 x i64> poison, <2 x i32> <i32 1, i32 0>
  store <2 x i64> %11, ptr %1, align 4
  br label %.preheader67.preheader

.preheader67.preheader:                           ; preds = %4, %9
  br label %.preheader67

.preheader67:                                     ; preds = %.preheader67.preheader, %.loopexit66
  %.ptr6076 = phi ptr [ %.ptr60, %.loopexit66 ], [ %invariant.gep, %.preheader67.preheader ]
  %.04575 = phi ptr [ %.ptr6076, %.loopexit66 ], [ %1, %.preheader67.preheader ]
  %12 = load i32, ptr %.ptr6076, align 4, !tbaa !5
  br label %14

.lr.ph78.preheader:                               ; preds = %.loopexit66
  %13 = tail call i32 @llvm.smax.i32(i32 %0, i32 2)
  %smax = add nsw i32 %13, -1
  %wide.trip.count = zext nneg i32 %smax to i64
  br label %.lr.ph78

14:                                               ; preds = %.preheader67, %14
  %.1.idx = phi i64 [ %.1.add, %14 ], [ 8, %.preheader67 ]
  %.1.add = add nsw i64 %.1.idx, -8
  %.ptr59 = getelementptr inbounds i8, ptr %.04575, i64 %.1.add
  %15 = load i32, ptr %.ptr59, align 4, !tbaa !5
  %16 = icmp sgt i32 %15, %12
  br i1 %16, label %14, label %17, !llvm.loop !10

17:                                               ; preds = %14
  %.1.ptr.le = getelementptr inbounds i8, ptr %.04575, i64 %.1.idx
  %.not58 = icmp eq i64 %.1.idx, 8
  br i1 %.not58, label %.loopexit66, label %.preheader65.preheader

.preheader65.preheader:                           ; preds = %17
  %.ptr62 = getelementptr inbounds i8, ptr %.04575, i64 8
  %18 = load i64, ptr %.ptr62, align 4
  %.not6471 = icmp sgt i64 %.1.idx, 0
  br i1 %.not6471, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader65.preheader, %.lr.ph
  %19 = phi ptr [ %21, %.lr.ph ], [ %.04575, %.preheader65.preheader ]
  %.04472 = phi ptr [ %19, %.lr.ph ], [ %.ptr62, %.preheader65.preheader ]
  %20 = load i64, ptr %19, align 4
  store i64 %20, ptr %.04472, align 4
  %21 = getelementptr inbounds i8, ptr %19, i64 -8
  %.not64 = icmp ult ptr %21, %.1.ptr.le
  br i1 %.not64, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %.preheader65.preheader
  %.044.lcssa = phi ptr [ %.ptr62, %.preheader65.preheader ], [ %19, %.lr.ph ]
  store i64 %18, ptr %.044.lcssa, align 4
  br label %.loopexit66

.loopexit66:                                      ; preds = %._crit_edge, %17
  %.ptr60 = getelementptr inbounds i8, ptr %.ptr6076, i64 8
  %22 = icmp ult ptr %.ptr60, %6
  br i1 %22, label %.preheader67, label %.lr.ph78.preheader, !llvm.loop !13

.lr.ph78:                                         ; preds = %.lr.ph78.preheader, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph78.preheader ], [ %indvars.iv.next, %30 ]
  %23 = getelementptr inbounds %struct.KeyValueType, ptr %1, i64 %indvars.iv
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = getelementptr inbounds %struct.KeyValueType, ptr %1, i64 %indvars.iv.next
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp sgt i32 %24, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %.lr.ph78
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %30

30:                                               ; preds = %.lr.ph78, %28
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph78, !llvm.loop !14

.loopexit:                                        ; preds = %30, %2
  ret void
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #2

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 = { nofree 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"KeyValueType", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass