; 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 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [22 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare i32 @fclose(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @fileBeforeExec(ptr noundef %0, i32 noundef %1, i1 noundef zeroext %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) #3 {
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  %15 = zext i1 %2 to i8
  store i8 %15, ptr %9, align 1, !tbaa !11
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %16 = call noalias ptr @fopen(ptr noundef @.str.4, ptr noundef @.str.5)
  store ptr %16, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %13, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %74

19:                                               ; preds = %6
  %20 = load ptr, ptr %13, align 8, !tbaa !5
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = icmp eq i32 %23, 2
  br i1 %24, label %25, label %27

25:                                               ; preds = %19
  %26 = load i32, ptr %11, align 4, !tbaa !9
  br label %29

27:                                               ; preds = %19
  %28 = load i32, ptr %8, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %27, %25
  %30 = phi i32 [ %26, %25 ], [ %28, %27 ]
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %34

33:                                               ; preds = %29
  br label %45

34:                                               ; preds = %29
  %35 = load i32, ptr %12, align 4, !tbaa !9
  %36 = icmp eq i32 %35, 2
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  br label %43

38:                                               ; preds = %34
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 3
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, ptr @.str.15, ptr @.str.16
  br label %43

43:                                               ; preds = %38, %37
  %44 = phi ptr [ @.str.14, %37 ], [ %42, %38 ]
  br label %45

45:                                               ; preds = %43, %33
  %46 = phi ptr [ @.str.13, %33 ], [ %44, %43 ]
  %47 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.12, ptr noundef %21, i32 noundef %22, i32 noundef %30, ptr noundef %46) #4
  %48 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %49 = trunc i8 %48 to i1
  br i1 %49, label %50, label %73

50:                                               ; preds = %45
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef @.str.17) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %53, ptr %14, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %67, %50
  %55 = load ptr, ptr %14, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i64, ptr %56, i64 %58
  %60 = icmp ult ptr %55, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %70

62:                                               ; preds = %54
  %63 = load ptr, ptr %13, align 8, !tbaa !5
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = load i64, ptr %64, align 8, !tbaa !15
  %66 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %63, ptr noundef @.str.1, i64 noundef %65) #4
  br label %67

67:                                               ; preds = %62
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = getelementptr inbounds i64, ptr %68, i32 1
  store ptr %69, ptr %14, align 8, !tbaa !5
  br label %54, !llvm.loop !17

70:                                               ; preds = %61
  %71 = load ptr, ptr %13, align 8, !tbaa !5
  %72 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str) #4
  br label %73

73:                                               ; preds = %70, %45
  br label %76

74:                                               ; preds = %6
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.10, ptr noundef @.str.11)
  br label %76

76:                                               ; preds = %74, %73
  %77 = load ptr, ptr %13, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %82

79:                                               ; preds = %76
  %80 = load ptr, ptr %13, align 8, !tbaa !5
  %81 = call i32 @fclose(ptr noundef %80)
  br label %82

82:                                               ; preds = %79, %76
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  ret void
}

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

!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"}


; 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 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.13 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [22 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #0

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @fileBeforeExec(ptr noundef readonly %0, i32 noundef %1, i1 noundef zeroext %2, ptr noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #1 {
  %7 = tail call noalias ptr @fopen(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %.thread, label %8

8:                                                ; preds = %6
  %9 = icmp eq i32 %5, 2
  %10 = select i1 %9, i32 %4, i32 %1
  %11 = icmp eq i32 %5, 1
  %12 = add i32 %5, -1
  %brmerge = icmp ult i32 %12, 2
  %.str.13.mux = select i1 %11, ptr @.str.13, ptr @.str.14
  %13 = icmp eq i32 %5, 3
  %14 = select i1 %13, ptr @.str.15, ptr @.str.16
  %15 = select i1 %brmerge, ptr %.str.13.mux, ptr %14
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %7, ptr noundef nonnull @.str.12, ptr noundef %3, i32 noundef %1, i32 noundef %10, ptr noundef nonnull %15) #2
  br i1 %2, label %17, label %.thread23

17:                                               ; preds = %8
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %7, ptr noundef nonnull @.str.17) #2
  %19 = sext i32 %1 to i64
  %20 = getelementptr inbounds i64, ptr %0, i64 %19
  %21 = icmp sgt i32 %1, 0
  br i1 %21, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %17, %.lr.ph
  %.024 = phi ptr [ %24, %.lr.ph ], [ %0, %17 ]
  %22 = load i64, ptr %.024, align 8, !tbaa !5
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %7, ptr noundef nonnull @.str.1, i64 noundef %22) #2
  %24 = getelementptr inbounds i8, ptr %.024, i64 8
  %25 = icmp ult ptr %24, %20
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.thread:                                          ; preds = %6
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10, ptr noundef nonnull @.str.11)
  br label %29

._crit_edge:                                      ; preds = %.lr.ph, %17
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %7, ptr noundef nonnull @.str) #2
  br label %.thread23

.thread23:                                        ; preds = %._crit_edge, %8
  %28 = tail call i32 @fclose(ptr noundef nonnull %7)
  br label %29

29:                                               ; preds = %.thread, %.thread23
  ret void
}

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


; Effective O3 passes: ConstraintEliminationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass