; LLVM IR from albertobsd/keyhunt :: keyhunt.ll (Z14_insertionsortP13address_valuel)

; 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.address_value = type { [20 x i8] }

; 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 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z14_insertionsortP13address_valuel(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca %struct.address_value, align 1
  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) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 20, ptr %7) #4
  store i64 1, ptr %6, align 8, !tbaa !9
  br label %8

8:                                                ; preds = %48, %2
  %9 = load i64, ptr %6, align 8, !tbaa !9
  %10 = load i64, ptr %4, align 8, !tbaa !9
  %11 = icmp slt i64 %9, %10
  br i1 %11, label %12, label %51

12:                                               ; preds = %8
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.address_value, ptr %13, i64 %14
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %7, ptr align 1 %15, i64 20, i1 false), !tbaa.struct !11
  %16 = load i64, ptr %6, align 8, !tbaa !9
  %17 = sub nsw i64 %16, 1
  store i64 %17, ptr %5, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %33, %12
  %19 = load i64, ptr %5, align 8, !tbaa !9
  %20 = icmp sge i64 %19, 0
  br i1 %20, label %21, label %31

21:                                               ; preds = %18
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %5, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.address_value, ptr %22, i64 %23
  %25 = getelementptr inbounds %struct.address_value, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [20 x i8], ptr %25, i64 0, i64 0
  %27 = getelementptr inbounds %struct.address_value, ptr %7, i32 0, i32 0
  %28 = getelementptr inbounds [20 x i8], ptr %27, i64 0, i64 0
  %29 = call i32 @memcmp(ptr noundef %26, ptr noundef %28, i64 noundef 20) #5
  %30 = icmp sgt i32 %29, 0
  br label %31

31:                                               ; preds = %21, %18
  %32 = phi i1 [ false, %18 ], [ %30, %21 ]
  br i1 %32, label %33, label %43

33:                                               ; preds = %31
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.address_value, ptr %34, i64 %35
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i64, ptr %5, align 8, !tbaa !9
  %39 = add nsw i64 %38, 1
  %40 = getelementptr inbounds %struct.address_value, ptr %37, i64 %39
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %40, ptr align 1 %36, i64 20, i1 false), !tbaa.struct !11
  %41 = load i64, ptr %5, align 8, !tbaa !9
  %42 = add nsw i64 %41, -1
  store i64 %42, ptr %5, align 8, !tbaa !9
  br label %18, !llvm.loop !13

43:                                               ; preds = %31
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = load i64, ptr %5, align 8, !tbaa !9
  %46 = add nsw i64 %45, 1
  %47 = getelementptr inbounds %struct.address_value, ptr %44, i64 %46
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %47, ptr align 1 %7, i64 20, i1 false), !tbaa.struct !11
  br label %48

48:                                               ; preds = %43
  %49 = load i64, ptr %6, align 8, !tbaa !9
  %50 = add nsw i64 %49, 1
  store i64 %50, ptr %6, align 8, !tbaa !9
  br label %8, !llvm.loop !15

51:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 20, 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
  ret void
}

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

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{i64 0, i64 20, !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"

%struct.address_value = type { [20 x i8] }

; 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 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @memcmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind memory(argmem: readwrite) uwtable
define dso_local void @_Z14_insertionsortP13address_valuel(ptr nocapture noundef %0, i64 noundef %1) local_unnamed_addr #3 {
  %3 = alloca %struct.address_value, align 1
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #4
  %4 = icmp sgt i64 %1, 1
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.critedge
  %.019 = phi i64 [ %14, %.critedge ], [ 1, %2 ]
  %5 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.019
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %3, ptr noundef nonnull align 1 dereferenceable(20) %5, i64 20, i1 false), !tbaa.struct !5
  br label %6

6:                                                ; preds = %.lr.ph, %10
  %.015.in17 = phi i64 [ %.019, %.lr.ph ], [ %.01518, %10 ]
  %.01518 = add nsw i64 %.015.in17, -1
  %7 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.01518
  %8 = call i32 @memcmp(ptr noundef nonnull dereferenceable(20) %7, ptr noundef nonnull dereferenceable(20) %3, i64 noundef 20) #5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %10, label %.critedge

10:                                               ; preds = %6
  %11 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.015.in17
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %11, ptr noundef nonnull align 1 dereferenceable(20) %7, i64 20, i1 false), !tbaa.struct !5
  %12 = icmp sgt i64 %.015.in17, 1
  br i1 %12, label %6, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %10, %6
  %.015.in.lcssa = phi i64 [ 0, %10 ], [ %.015.in17, %6 ]
  %13 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.015.in.lcssa
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(20) %13, ptr noundef nonnull align 1 dereferenceable(20) %3, i64 20, i1 false), !tbaa.struct !5
  %14 = add nuw nsw i64 %.019, 1
  %exitcond.not = icmp eq i64 %14, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.critedge, %2
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %3) #4
  ret void
}

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

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


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