; LLVM IR from clibraries/array-algorithms :: test (impl)

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

; 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
declare dso_local void @intv_swap(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @intv_reverse(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @intv_next_permutation(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = icmp eq ptr %14, %15
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  br label %73

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %19, ptr %10, align 8, !tbaa !5
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = getelementptr inbounds i32, ptr %20, i32 -1
  store ptr %21, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = getelementptr inbounds i32, ptr %22, i64 -1
  store ptr %23, ptr %11, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %37, %18
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %25, %26
  br i1 %27, label %28, label %35

28:                                               ; preds = %24
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %10, align 8, !tbaa !5
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  %33 = call i32 %29(ptr noundef %30, ptr noundef %31, ptr noundef %32)
  %34 = icmp sge i32 %33, 0
  br label %35

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

37:                                               ; preds = %35
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %38, ptr %10, align 8, !tbaa !5
  %39 = load ptr, ptr %11, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i32 -1
  store ptr %40, ptr %11, align 8, !tbaa !5
  br label %24, !llvm.loop !9

41:                                               ; preds = %35
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = icmp ne ptr %42, %43
  br i1 %44, label %45, label %69

45:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds i32, ptr %46, i64 -1
  store ptr %47, ptr %12, align 8, !tbaa !5
  br label %48

48:                                               ; preds = %61, %45
  %49 = load ptr, ptr %12, align 8, !tbaa !5
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = icmp ne ptr %49, %50
  br i1 %51, label %52, label %59

52:                                               ; preds = %48
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %12, align 8, !tbaa !5
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = call i32 %53(ptr noundef %54, ptr noundef %55, ptr noundef %56)
  %58 = icmp sge i32 %57, 0
  br label %59

59:                                               ; preds = %52, %48
  %60 = phi i1 [ false, %48 ], [ %58, %52 ]
  br i1 %60, label %61, label %64

61:                                               ; preds = %59
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  %63 = getelementptr inbounds i32, ptr %62, i32 -1
  store ptr %63, ptr %12, align 8, !tbaa !5
  br label %48, !llvm.loop !11

64:                                               ; preds = %59
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  call void @intv_swap(ptr noundef %65, ptr noundef %66)
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  call void @intv_reverse(ptr noundef %67, ptr noundef %68)
  store i32 1, ptr %5, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  br label %72

69:                                               ; preds = %41
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  call void @intv_reverse(ptr noundef %70, ptr noundef %71)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %13, align 4
  br label %72

72:                                               ; preds = %69, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  br label %73

73:                                               ; preds = %72, %17
  %74 = load i32, ptr %5, align 4
  ret i32 %74
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @intv_next_permutation(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, %1
  br i1 %5, label %16, label %6

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %1, i64 -4
  %.not40 = icmp eq ptr %7, %0
  br i1 %.not40, label %.sink.split, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %8 = getelementptr inbounds i8, ptr %1, i64 -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %11
  %.03142 = phi ptr [ %12, %11 ], [ %8, %.lr.ph.preheader ]
  %.03241 = phi ptr [ %.03142, %11 ], [ %7, %.lr.ph.preheader ]
  %9 = tail call i32 %2(ptr noundef nonnull %.03142, ptr noundef nonnull %.03241, ptr noundef %3) #1
  %10 = icmp sgt i32 %9, -1
  br i1 %10, label %11, label %.critedge.preheader

11:                                               ; preds = %.lr.ph
  %12 = getelementptr inbounds i8, ptr %.03142, i64 -4
  %.not = icmp eq ptr %.03142, %0
  br i1 %.not, label %.sink.split, label %.lr.ph, !llvm.loop !5

.critedge.preheader:                              ; preds = %.lr.ph, %.critedge
  %.043 = phi ptr [ %15, %.critedge ], [ %7, %.lr.ph ]
  %13 = tail call i32 %2(ptr noundef nonnull %.03142, ptr noundef nonnull %.043, ptr noundef %3) #1
  %14 = icmp sgt i32 %13, -1
  br i1 %14, label %.critedge, label %.critedge2

.critedge:                                        ; preds = %.critedge.preheader
  %15 = getelementptr inbounds i8, ptr %.043, i64 -4
  %.not36 = icmp eq ptr %15, %.03142
  br i1 %.not36, label %.critedge2, label %.critedge.preheader, !llvm.loop !7

.critedge2:                                       ; preds = %.critedge, %.critedge.preheader
  %.0.lcssa = phi ptr [ %.03142, %.critedge ], [ %.043, %.critedge.preheader ]
  tail call void @intv_swap(ptr noundef nonnull %.03142, ptr noundef nonnull %.0.lcssa)
  br label %.sink.split

.sink.split:                                      ; preds = %11, %6, %.critedge2
  %.03241.lcssa.sink = phi ptr [ %.03241, %.critedge2 ], [ %0, %6 ], [ %0, %11 ]
  %.1.ph = phi i32 [ 1, %.critedge2 ], [ 0, %6 ], [ 0, %11 ]
  tail call void @intv_reverse(ptr noundef %.03241.lcssa.sink, ptr noundef %1)
  br label %16

16:                                               ; preds = %.sink.split, %4
  %.1 = phi i32 [ 0, %4 ], [ %.1.ph, %.sink.split ]
  ret i32 %.1
}

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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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