; LLVM IR from LeoVen/C-Macro-Collections :: tests (types)

; 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.struct_s = type { i32, i32, ptr, ptr, [10 x double] }

; 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 void @sl1_impl_sort_insertion(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.struct_s, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i64 %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %12 = load i64, ptr %7, align 8, !tbaa !9
  %13 = add i64 %12, 1
  store i64 %13, ptr %9, align 8, !tbaa !9
  br label %14

14:                                               ; preds = %52, %4
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %16 = load i64, ptr %8, align 8, !tbaa !9
  %17 = icmp ule i64 %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %55

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 104, ptr %10) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %9, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.struct_s, ptr %20, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %10, ptr align 8 %22, i64 104, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %23 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %23, ptr %11, align 8, !tbaa !9
  br label %24

24:                                               ; preds = %38, %19
  %25 = load i64, ptr %11, align 8, !tbaa !9
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = icmp ugt i64 %25, %26
  br i1 %27, label %28, label %36

28:                                               ; preds = %24
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i64, ptr %11, align 8, !tbaa !9
  %32 = sub i64 %31, 1
  %33 = getelementptr inbounds %struct.struct_s, ptr %30, i64 %32
  %34 = call i32 %29(ptr noundef byval(%struct.struct_s) align 8 %33, ptr noundef byval(%struct.struct_s) align 8 %10)
  %35 = icmp sgt i32 %34, 0
  br label %36

36:                                               ; preds = %28, %24
  %37 = phi i1 [ false, %24 ], [ %35, %28 ]
  br i1 %37, label %38, label %48

38:                                               ; preds = %36
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i64, ptr %11, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.struct_s, ptr %39, i64 %40
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i64, ptr %11, align 8, !tbaa !9
  %44 = sub i64 %43, 1
  %45 = getelementptr inbounds %struct.struct_s, ptr %42, i64 %44
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 8 %45, i64 104, i1 false), !tbaa.struct !11
  %46 = load i64, ptr %11, align 8, !tbaa !9
  %47 = add i64 %46, -1
  store i64 %47, ptr %11, align 8, !tbaa !9
  br label %24, !llvm.loop !15

48:                                               ; preds = %36
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i64, ptr %11, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.struct_s, ptr %49, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %51, ptr align 8 %10, i64 104, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 104, ptr %10) #3
  br label %52

52:                                               ; preds = %48
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = add i64 %53, 1
  store i64 %54, ptr %9, align 8, !tbaa !9
  br label %14, !llvm.loop !17

55:                                               ; preds = %18
  ret void
}

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 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 4, !12, i64 4, i64 4, !12, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 80, !14}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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.struct_s = type { i32, i32, ptr, ptr, [10 x double] }

; 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 void @sl1_impl_sort_insertion(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.struct_s, align 8
  %.01822 = add i64 %2, 1
  %.not23 = icmp ugt i64 %.01822, %3
  br i1 %.not23, label %._crit_edge, label %.lr.ph25

._crit_edge:                                      ; preds = %.critedge, %4
  ret void

.lr.ph25:                                         ; preds = %4, %.critedge
  %.01824 = phi i64 [ %.018, %.critedge ], [ %.01822, %4 ]
  call void @llvm.lifetime.start.p0(i64 104, ptr nonnull %5) #3
  %6 = getelementptr inbounds %struct.struct_s, ptr %0, i64 %.01824
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %5, ptr noundef nonnull align 8 dereferenceable(104) %6, i64 104, i1 false), !tbaa.struct !5
  %7 = icmp ugt i64 %.01824, %2
  br i1 %7, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.lr.ph25, %12
  %.019 = phi i64 [ %13, %12 ], [ %.01824, %.lr.ph25 ]
  %8 = getelementptr %struct.struct_s, ptr %0, i64 %.019
  %9 = getelementptr i8, ptr %8, i64 -104
  %10 = tail call i32 %1(ptr noundef byval(%struct.struct_s) align 8 %9, ptr noundef nonnull byval(%struct.struct_s) align 8 %5) #3
  %11 = icmp sgt i32 %10, 0
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %.lr.ph
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %8, ptr noundef nonnull align 8 dereferenceable(104) %9, i64 104, i1 false), !tbaa.struct !5
  %13 = add i64 %.019, -1
  %14 = icmp ugt i64 %13, %2
  br i1 %14, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %12, %.lr.ph25
  %.0.lcssa = phi i64 [ %.01824, %.lr.ph25 ], [ %2, %12 ], [ %.019, %.lr.ph ]
  %15 = getelementptr inbounds %struct.struct_s, ptr %0, i64 %.0.lcssa
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(104) %15, ptr noundef nonnull align 8 dereferenceable(104) %5, i64 104, i1 false), !tbaa.struct !5
  call void @llvm.lifetime.end.p0(i64 104, ptr nonnull %5) #3
  %.018 = add i64 %.01824, 1
  %.not = icmp ugt i64 %.018, %3
  br i1 %.not, label %._crit_edge, label %.lr.ph25, !llvm.loop !15
}

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


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