; LLVM IR from h-ssiqueira/Sort_Algorithms :: src/utils (array)

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

@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isSorted(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2) #2 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  %11 = zext i1 %2 to i8
  store i8 %11, ptr %7, align 1, !tbaa !11
  %12 = load i8, ptr %7, align 1, !tbaa !11, !range !13, !noundef !14
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %41

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %15, ptr %8, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %35, %14
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i64, ptr %18, i64 %20
  %22 = getelementptr inbounds i64, ptr %21, i64 -1
  %23 = icmp ult ptr %17, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  store i32 2, ptr %9, align 4
  br label %38

25:                                               ; preds = %16
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds i64, ptr %28, i64 1
  %30 = load i64, ptr %29, align 8, !tbaa !15
  %31 = icmp sgt i64 %27, %30
  br i1 %31, label %32, label %34

32:                                               ; preds = %25
  %33 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %38

34:                                               ; preds = %25
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds i64, ptr %36, i32 1
  store ptr %37, ptr %8, align 8, !tbaa !5
  br label %16, !llvm.loop !17

38:                                               ; preds = %32, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %39 = load i32, ptr %9, align 4
  switch i32 %39, label %72 [
    i32 2, label %40
    i32 1, label %70
  ]

40:                                               ; preds = %38
  br label %68

41:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %42, ptr %10, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %62, %41
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = load i32, ptr %6, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds i64, ptr %45, i64 %47
  %49 = getelementptr inbounds i64, ptr %48, i64 -1
  %50 = icmp ult ptr %44, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %43
  store i32 5, ptr %9, align 4
  br label %65

52:                                               ; preds = %43
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load i64, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = getelementptr inbounds i64, ptr %55, i64 1
  %57 = load i64, ptr %56, align 8, !tbaa !15
  %58 = icmp slt i64 %54, %57
  br i1 %58, label %59, label %61

59:                                               ; preds = %52
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %9, align 4
  br label %65

61:                                               ; preds = %52
  br label %62

62:                                               ; preds = %61
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds i64, ptr %63, i32 1
  store ptr %64, ptr %10, align 8, !tbaa !5
  br label %43, !llvm.loop !19

65:                                               ; preds = %59, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %66 = load i32, ptr %9, align 4
  switch i32 %66, label %72 [
    i32 5, label %67
    i32 1, label %70
  ]

67:                                               ; preds = %65
  br label %68

68:                                               ; preds = %67, %40
  %69 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i1 true, ptr %4, align 1
  br label %70

70:                                               ; preds = %68, %65, %38
  %71 = load i1, ptr %4, align 1
  ret i1 %71

72:                                               ; preds = %65, %38
  unreachable
}

attributes #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 = { nocallback nofree nosync 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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

@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [15 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local noundef zeroext i1 @isSorted(ptr noundef readonly %0, i32 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #1 {
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds i64, ptr %0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 -8
  br i1 %2, label %.preheader, label %.preheader30

.preheader:                                       ; preds = %3, %8
  %.018 = phi ptr [ %10, %8 ], [ %0, %3 ]
  %7 = icmp uge ptr %.018, %6
  br i1 %7, label %.thread, label %8

8:                                                ; preds = %.preheader
  %9 = load i64, ptr %.018, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %.018, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = icmp sgt i64 %9, %11
  br i1 %12, label %.thread, label %.preheader, !llvm.loop !9

.preheader30:                                     ; preds = %3, %14
  %.0 = phi ptr [ %16, %14 ], [ %0, %3 ]
  %13 = icmp uge ptr %.0, %6
  br i1 %13, label %.thread, label %14

14:                                               ; preds = %.preheader30
  %15 = load i64, ptr %.0, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %.0, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = icmp slt i64 %15, %17
  br i1 %18, label %.thread, label %.preheader30, !llvm.loop !11

.thread:                                          ; preds = %.preheader30, %14, %.preheader, %8
  %.str.2.sink = phi ptr [ @.str.2, %8 ], [ @.str.3, %.preheader ], [ @.str.2, %14 ], [ @.str.3, %.preheader30 ]
  %.2 = phi i1 [ %7, %8 ], [ %7, %.preheader ], [ %13, %14 ], [ %13, %.preheader30 ]
  %19 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.2.sink)
  ret i1 %.2
}

attributes #0 = { 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 #1 = { nofree 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" }

!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 = !{!"long", !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}


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