; LLVM IR from albertobsd/keyhunt :: keyhunt.ll (Z10_partitionP13address_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
declare dso_local void @_Z5_swapP13address_valueS0_(ptr noundef, ptr noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z10_partitionP13address_valuel(ptr noundef %0, i64 noundef %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.address_value, align 1
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  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 20, 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
  %9 = load i64, ptr %4, align 8, !tbaa !9
  %10 = sdiv i64 %9, 2
  store i64 %10, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.address_value, ptr %11, i64 %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 %13, i64 20, i1 false), !tbaa.struct !11
  store i64 0, ptr %7, align 8, !tbaa !9
  %14 = load i64, ptr %4, align 8, !tbaa !9
  %15 = sub nsw i64 %14, 1
  store i64 %15, ptr %8, align 8, !tbaa !9
  br label %16

16:                                               ; preds = %89, %2
  br label %17

17:                                               ; preds = %33, %16
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = load i64, ptr %8, align 8, !tbaa !9
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %21, label %31

21:                                               ; preds = %17
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i64, ptr %7, 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 %5, 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 sle i32 %29, 0
  br label %31

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

33:                                               ; preds = %31
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = add nsw i64 %34, 1
  store i64 %35, ptr %7, align 8, !tbaa !9
  br label %17, !llvm.loop !13

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %53, %36
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = load i64, ptr %7, align 8, !tbaa !9
  %40 = icmp sge i64 %38, %39
  br i1 %40, label %41, label %51

41:                                               ; preds = %37
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.address_value, ptr %42, i64 %43
  %45 = getelementptr inbounds %struct.address_value, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds [20 x i8], ptr %45, i64 0, i64 0
  %47 = getelementptr inbounds %struct.address_value, ptr %5, i32 0, i32 0
  %48 = getelementptr inbounds [20 x i8], ptr %47, i64 0, i64 0
  %49 = call i32 @memcmp(ptr noundef %46, ptr noundef %48, i64 noundef 20) #5
  %50 = icmp sgt i32 %49, 0
  br label %51

51:                                               ; preds = %41, %37
  %52 = phi i1 [ false, %37 ], [ %50, %41 ]
  br i1 %52, label %53, label %56

53:                                               ; preds = %51
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = add nsw i64 %54, -1
  store i64 %55, ptr %8, align 8, !tbaa !9
  br label %37, !llvm.loop !15

56:                                               ; preds = %51
  %57 = load i64, ptr %7, align 8, !tbaa !9
  %58 = load i64, ptr %8, align 8, !tbaa !9
  %59 = icmp slt i64 %57, %58
  br i1 %59, label %60, label %88

60:                                               ; preds = %56
  %61 = load i64, ptr %7, align 8, !tbaa !9
  %62 = load i64, ptr %6, align 8, !tbaa !9
  %63 = icmp eq i64 %61, %62
  br i1 %63, label %68, label %64

64:                                               ; preds = %60
  %65 = load i64, ptr %8, align 8, !tbaa !9
  %66 = load i64, ptr %6, align 8, !tbaa !9
  %67 = icmp eq i64 %65, %66
  br i1 %67, label %68, label %81

68:                                               ; preds = %64, %60
  %69 = load i64, ptr %7, align 8, !tbaa !9
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = icmp eq i64 %69, %70
  br i1 %71, label %72, label %74

72:                                               ; preds = %68
  %73 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %73, ptr %6, align 8, !tbaa !9
  br label %74

74:                                               ; preds = %72, %68
  %75 = load i64, ptr %8, align 8, !tbaa !9
  %76 = load i64, ptr %6, align 8, !tbaa !9
  %77 = icmp eq i64 %75, %76
  br i1 %77, label %78, label %80

78:                                               ; preds = %74
  %79 = load i64, ptr %7, align 8, !tbaa !9
  store i64 %79, ptr %6, align 8, !tbaa !9
  br label %80

80:                                               ; preds = %78, %74
  br label %81

81:                                               ; preds = %80, %64
  %82 = load ptr, ptr %3, align 8, !tbaa !5
  %83 = load i64, ptr %8, align 8, !tbaa !9
  %84 = getelementptr inbounds %struct.address_value, ptr %82, i64 %83
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = load i64, ptr %7, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.address_value, ptr %85, i64 %86
  call void @_Z5_swapP13address_valueS0_(ptr noundef %84, ptr noundef %87)
  br label %88

88:                                               ; preds = %81, %56
  br label %89

89:                                               ; preds = %88
  %90 = load i64, ptr %7, align 8, !tbaa !9
  %91 = load i64, ptr %8, align 8, !tbaa !9
  %92 = icmp slt i64 %90, %91
  br i1 %92, label %16, label %93, !llvm.loop !16

93:                                               ; preds = %89
  %94 = load i64, ptr %8, align 8, !tbaa !9
  %95 = load i64, ptr %6, align 8, !tbaa !9
  %96 = icmp ne i64 %94, %95
  br i1 %96, label %97, label %104

97:                                               ; preds = %93
  %98 = load ptr, ptr %3, align 8, !tbaa !5
  %99 = load i64, ptr %8, align 8, !tbaa !9
  %100 = getelementptr inbounds %struct.address_value, ptr %98, i64 %99
  %101 = load ptr, ptr %3, align 8, !tbaa !5
  %102 = load i64, ptr %6, align 8, !tbaa !9
  %103 = getelementptr inbounds %struct.address_value, ptr %101, i64 %102
  call void @_Z5_swapP13address_valueS0_(ptr noundef %100, ptr noundef %103)
  br label %104

104:                                              ; preds = %97, %93
  %105 = load i64, ptr %8, align 8, !tbaa !9
  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 20, ptr %5) #4
  ret i64 %105
}

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}
!16 = distinct !{!16, !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 nounwind uwtable
declare dso_local void @_Z5_swapP13address_valueS0_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i64 -9223372036854775808, 9223372036854775807) i64 @_Z10_partitionP13address_valuel(ptr 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 = sdiv i64 %1, 2
  %5 = getelementptr inbounds %struct.address_value, ptr %0, i64 %4
  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
  %6 = add nsw i64 %1, -1
  br label %7

7:                                                ; preds = %21, %2
  %.042 = phi i64 [ %4, %2 ], [ %.2, %21 ]
  %.040 = phi i64 [ 0, %2 ], [ %.141.lcssa, %21 ]
  %.0 = phi i64 [ %6, %2 ], [ %.1.lcssa, %21 ]
  %8 = icmp slt i64 %.040, %.0
  br i1 %8, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %7, %12
  %.14148 = phi i64 [ %13, %12 ], [ %.040, %7 ]
  %9 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.14148
  %10 = call i32 @memcmp(ptr noundef nonnull dereferenceable(20) %9, ptr noundef nonnull dereferenceable(20) %3, i64 noundef 20) #5
  %11 = icmp slt i32 %10, 1
  br i1 %11, label %12, label %.critedge

12:                                               ; preds = %.lr.ph
  %13 = add i64 %.14148, 1
  %exitcond.not = icmp eq i64 %13, %.0
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph, %12, %7
  %.141.lcssa = phi i64 [ %.040, %7 ], [ %.0, %12 ], [ %.14148, %.lr.ph ]
  %.not51 = icmp slt i64 %.0, %.141.lcssa
  br i1 %.not51, label %.critedge2, label %.lr.ph53.preheader

.lr.ph53.preheader:                               ; preds = %.critedge
  %14 = add i64 %.141.lcssa, -1
  br label %.lr.ph53

.lr.ph53:                                         ; preds = %.lr.ph53.preheader, %18
  %.152 = phi i64 [ %19, %18 ], [ %.0, %.lr.ph53.preheader ]
  %15 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.152
  %16 = call i32 @memcmp(ptr noundef nonnull dereferenceable(20) %15, ptr noundef nonnull dereferenceable(20) %3, i64 noundef 20) #5
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %.critedge2

18:                                               ; preds = %.lr.ph53
  %19 = add nsw i64 %.152, -1
  %.not.not = icmp sgt i64 %.152, %.141.lcssa
  br i1 %.not.not, label %.lr.ph53, label %.critedge2, !llvm.loop !11

.critedge2:                                       ; preds = %.lr.ph53, %18, %.critedge
  %.1.lcssa = phi i64 [ %.0, %.critedge ], [ %14, %18 ], [ %.152, %.lr.ph53 ]
  %20 = icmp slt i64 %.141.lcssa, %.1.lcssa
  br i1 %20, label %21, label %27

21:                                               ; preds = %.critedge2
  %22 = icmp eq i64 %.141.lcssa, %.042
  %23 = icmp eq i64 %.1.lcssa, %.042
  %or.cond = or i1 %22, %23
  %spec.select = select i1 %22, i64 %.1.lcssa, i64 %.042
  %24 = icmp eq i64 %.1.lcssa, %spec.select
  %spec.select45 = select i1 %24, i64 %.141.lcssa, i64 %spec.select
  %.2 = select i1 %or.cond, i64 %spec.select45, i64 %.042
  %25 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.1.lcssa
  %26 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.141.lcssa
  tail call void @_Z5_swapP13address_valueS0_(ptr noundef %25, ptr noundef %26)
  br label %7

27:                                               ; preds = %.critedge2
  %.not44 = icmp eq i64 %.1.lcssa, %.042
  br i1 %.not44, label %31, label %28

28:                                               ; preds = %27
  %29 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.1.lcssa
  %30 = getelementptr inbounds %struct.address_value, ptr %0, i64 %.042
  tail call void @_Z5_swapP13address_valueS0_(ptr noundef %29, ptr noundef %30)
  br label %31

31:                                               ; preds = %28, %27
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %3) #4
  ret i64 %.1.lcssa
}

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 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 = !{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,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass