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

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

@txtFile = external dso_local global i8, align 1
@displayArray = external dso_local global i8, align 1
@executionTime = external dso_local global i8, align 1
@arraySorted = external dso_local global i8, align 1

; 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

declare void @printArray(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @informationsPosSort(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, i1 noundef zeroext %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !11
  store i64 %3, ptr %9, align 8, !tbaa !11
  %13 = zext i1 %4 to i8
  store i8 %13, ptr %10, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = load i8, ptr %10, align 1, !tbaa !13, !range !15, !noundef !16
  %17 = trunc i8 %16 to i1
  %18 = call zeroext i1 @isSorted(ptr noundef %14, i32 noundef %15, i1 noundef zeroext %17)
  %19 = zext i1 %18 to i8
  store i8 %19, ptr @arraySorted, align 1, !tbaa !13
  %20 = load i8, ptr @displayArray, align 1, !tbaa !13, !range !15, !noundef !16
  %21 = trunc i8 %20 to i1
  br i1 %21, label %22, label %25

22:                                               ; preds = %5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i32, ptr %7, align 4, !tbaa !9
  call void @printArray(ptr noundef %23, i32 noundef %24)
  br label %25

25:                                               ; preds = %22, %5
  %26 = load i8, ptr @executionTime, align 1, !tbaa !13, !range !15, !noundef !16
  %27 = trunc i8 %26 to i1
  br i1 %27, label %28, label %31

28:                                               ; preds = %25
  %29 = load i64, ptr %8, align 8, !tbaa !11
  %30 = load i64, ptr %9, align 8, !tbaa !11
  call void @calculateTime(i64 noundef %29, i64 noundef %30, ptr noundef %11, ptr noundef %12)
  br label %31

31:                                               ; preds = %28, %25
  %32 = load i8, ptr @txtFile, align 1, !tbaa !13, !range !15, !noundef !16
  %33 = trunc i8 %32 to i1
  br i1 %33, label %34, label %51

34:                                               ; preds = %31
  %35 = load i8, ptr @displayArray, align 1, !tbaa !13, !range !15, !noundef !16
  %36 = trunc i8 %35 to i1
  br i1 %36, label %40, label %37

37:                                               ; preds = %34
  %38 = load i8, ptr @executionTime, align 1, !tbaa !13, !range !15, !noundef !16
  %39 = trunc i8 %38 to i1
  br i1 %39, label %40, label %51

40:                                               ; preds = %37, %34
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load i8, ptr @displayArray, align 1, !tbaa !13, !range !15, !noundef !16
  %44 = trunc i8 %43 to i1
  %45 = load i8, ptr @executionTime, align 1, !tbaa !13, !range !15, !noundef !16
  %46 = trunc i8 %45 to i1
  %47 = load i64, ptr %11, align 8, !tbaa !11
  %48 = load i64, ptr %12, align 8, !tbaa !11
  %49 = load i8, ptr @arraySorted, align 1, !tbaa !13, !range !15, !noundef !16
  %50 = trunc i8 %49 to i1
  call void @fileAfterExec(ptr noundef %41, i32 noundef %42, i1 noundef zeroext %44, i1 noundef zeroext %46, i64 noundef %47, i64 noundef %48, i1 noundef zeroext %50)
  br label %51

51:                                               ; preds = %40, %37, %31
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret void
}

declare zeroext i1 @isSorted(ptr noundef, i32 noundef, i1 noundef zeroext) #1

declare void @calculateTime(i64 noundef, i64 noundef, ptr noundef, ptr noundef) #1

declare void @fileAfterExec(ptr noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext, i64 noundef, i64 noundef, i1 noundef zeroext) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!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"

@txtFile = external dso_local local_unnamed_addr global i8, align 1
@displayArray = external dso_local local_unnamed_addr global i8, align 1
@executionTime = external dso_local local_unnamed_addr global i8, align 1
@arraySorted = external dso_local local_unnamed_addr global i8, align 1

; 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

declare void @printArray(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @informationsPosSort(ptr noundef %0, i32 noundef %1, i64 noundef %2, i64 noundef %3, i1 noundef zeroext %4) local_unnamed_addr #2 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  %8 = tail call zeroext i1 @isSorted(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %4) #3
  %9 = zext i1 %8 to i8
  store i8 %9, ptr @arraySorted, align 1, !tbaa !5
  %10 = load i8, ptr @displayArray, align 1, !tbaa !5, !range !9, !noundef !10
  %11 = trunc nuw i8 %10 to i1
  br i1 %11, label %12, label %13

12:                                               ; preds = %5
  tail call void @printArray(ptr noundef %0, i32 noundef %1) #3
  br label %13

13:                                               ; preds = %12, %5
  %14 = load i8, ptr @executionTime, align 1, !tbaa !5, !range !9, !noundef !10
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  call void @calculateTime(i64 noundef %2, i64 noundef %3, ptr noundef nonnull %6, ptr noundef nonnull %7) #3
  br label %17

17:                                               ; preds = %16, %13
  %18 = load i8, ptr @txtFile, align 1, !tbaa !5, !range !9, !noundef !10
  %19 = trunc nuw i8 %18 to i1
  br i1 %19, label %20, label %27

20:                                               ; preds = %17
  %21 = load i8, ptr @displayArray, align 1, !tbaa !5, !range !9, !noundef !10
  %22 = trunc nuw i8 %21 to i1
  %.pre = load i8, ptr @executionTime, align 1, !tbaa !5, !range !9
  %.pre8 = trunc nuw i8 %.pre to i1
  %brmerge = select i1 %22, i1 true, i1 %.pre8
  br i1 %brmerge, label %._crit_edge, label %27

._crit_edge:                                      ; preds = %20
  %not. = xor i1 %22, true
  %.pre8.mux = select i1 %not., i1 true, i1 %.pre8
  %23 = load i64, ptr %6, align 8, !tbaa !11
  %24 = load i64, ptr %7, align 8, !tbaa !11
  %25 = load i8, ptr @arraySorted, align 1, !tbaa !5, !range !9, !noundef !10
  %26 = trunc nuw i8 %25 to i1
  call void @fileAfterExec(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %22, i1 noundef zeroext %.pre8.mux, i64 noundef %23, i64 noundef %24, i1 noundef zeroext %26) #3
  br label %27

27:                                               ; preds = %20, %._crit_edge, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret void
}

declare zeroext i1 @isSorted(ptr noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #1

declare void @calculateTime(i64 noundef, i64 noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @fileAfterExec(ptr noundef, i32 noundef, i1 noundef zeroext, i1 noundef zeroext, i64 noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{!"_Bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass