; LLVM IR from bnidia/push_swap :: main (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"

%struct.s_minmaxmed = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.s_minmaxmed, align 4
  %9 = alloca i32, align 4
  %10 = alloca %struct.s_minmaxmed, align 4
  %11 = alloca { i64, i32 }, align 4
  %12 = alloca { i64, i32 }, align 4
  %13 = alloca { i64, i32 }, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load ptr, ptr %5, align 8, !tbaa !9
  %16 = call ptr @init_stack(i32 noundef %14, ptr noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.s_minmaxmed, ptr %10, i32 0, i32 0
  store i32 0, ptr %17, align 4, !tbaa !11
  %18 = getelementptr inbounds %struct.s_minmaxmed, ptr %10, i32 0, i32 1
  store i32 0, ptr %18, align 4, !tbaa !13
  %19 = getelementptr inbounds %struct.s_minmaxmed, ptr %10, i32 0, i32 2
  store i32 0, ptr %19, align 4, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 4 %10, i64 12, i1 false), !tbaa.struct !15
  call void @check_if_duplicated(ptr noundef %6, ptr noundef %8)
  %20 = call zeroext i1 @check_if_sorted(ptr noundef %6)
  br i1 %20, label %21, label %22

21:                                               ; preds = %2
  call void @exit(i32 noundef 0) #6
  unreachable

22:                                               ; preds = %2
  %23 = load ptr, ptr %6, align 8, !tbaa !9
  %24 = call i32 @ft_lstc_size(ptr noundef %23)
  %25 = icmp eq i32 %24, 5
  br i1 %25, label %26, label %31

26:                                               ; preds = %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %8, i64 12, i1 false)
  %27 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 0
  %28 = load i64, ptr %27, align 4
  %29 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 1
  %30 = load i32, ptr %29, align 4
  call void @sort_five(ptr noundef %6, ptr noundef %7, i64 %28, i32 %30)
  br label %31

31:                                               ; preds = %26, %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %8, i64 12, i1 false)
  %32 = getelementptr inbounds { i64, i32 }, ptr %12, i32 0, i32 0
  %33 = load i64, ptr %32, align 4
  %34 = getelementptr inbounds { i64, i32 }, ptr %12, i32 0, i32 1
  %35 = load i32, ptr %34, align 4
  call void @leave_three(ptr noundef %6, ptr noundef %7, i64 %33, i32 %35)
  call void @sort_three(ptr noundef %6)
  br label %36

36:                                               ; preds = %39, %31
  %37 = load ptr, ptr %7, align 8, !tbaa !9
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %43

39:                                               ; preds = %36
  %40 = load ptr, ptr %6, align 8, !tbaa !9
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  call void @score_count(ptr noundef %40, ptr noundef %41, ptr noundef %9)
  %42 = load i32, ptr %9, align 4, !tbaa !5
  call void @score_process(ptr noundef %6, ptr noundef %7, i32 noundef %42)
  br label %36, !llvm.loop !16

43:                                               ; preds = %36
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %8, i64 12, i1 false)
  %44 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 0
  %45 = load i64, ptr %44, align 4
  %46 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 1
  %47 = load i32, ptr %46, align 4
  call void @sort_final(ptr noundef %6, i64 %45, i32 %47)
  call void @ft_lstc_clear(ptr noundef %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  ret i32 0
}

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

declare ptr @init_stack(i32 noundef, ptr noundef) #2

; 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) #3

declare void @check_if_duplicated(ptr noundef, ptr noundef) #2

declare zeroext i1 @check_if_sorted(ptr noundef) #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

declare i32 @ft_lstc_size(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @sort_five(ptr noundef, ptr noundef, i64, i32) #0

; Function Attrs: nounwind uwtable
declare dso_local void @leave_three(ptr noundef, ptr noundef, i64, i32) #0

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

declare void @score_count(ptr noundef, ptr noundef, ptr noundef) #2

declare void @score_process(ptr noundef, ptr noundef, i32 noundef) #2

declare void @sort_final(ptr noundef, i64, i32) #2

declare void @ft_lstc_clear(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { noreturn 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 #5 = { nounwind }
attributes #6 = { noreturn 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"s_minmaxmed", !6, i64 0, !6, i64 4, !6, i64 8}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!16 = distinct !{!16, !17}
!17 = !{!"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"

%struct.s_minmaxmed = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca %struct.s_minmaxmed, align 8
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %7 = tail call ptr @init_stack(i32 noundef %0, ptr noundef %1) #4
  store ptr %7, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %5, align 8, !tbaa !9
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 4
  store i32 0, ptr %.sroa.26.0..sroa_idx, align 4, !tbaa !9
  %.sroa.3.0..sroa_idx = getelementptr inbounds i8, ptr %5, i64 8
  store i32 0, ptr %.sroa.3.0..sroa_idx, align 8, !tbaa !9
  call void @check_if_duplicated(ptr noundef nonnull %3, ptr noundef nonnull %5) #4
  %8 = call zeroext i1 @check_if_sorted(ptr noundef nonnull %3) #4
  br i1 %8, label %9, label %10

9:                                                ; preds = %2
  call void @exit(i32 noundef 0) #5
  unreachable

10:                                               ; preds = %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i32 @ft_lstc_size(ptr noundef %11) #4
  %13 = icmp eq i32 %12, 5
  br i1 %13, label %14, label %15

14:                                               ; preds = %10
  %.sroa.03.0.copyload = load i64, ptr %5, align 8
  %.sroa.24.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 8
  call void @sort_five(ptr noundef nonnull %3, ptr noundef nonnull %4, i64 %.sroa.03.0.copyload, i32 %.sroa.24.0.copyload)
  br label %15

15:                                               ; preds = %14, %10
  %.sroa.01.0.copyload = load i64, ptr %5, align 8
  %.sroa.22.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 8
  call void @leave_three(ptr noundef nonnull %3, ptr noundef nonnull %4, i64 %.sroa.01.0.copyload, i32 %.sroa.22.0.copyload)
  call void @sort_three(ptr noundef nonnull %3)
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %.not7 = icmp eq ptr %16, null
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %15, %.lr.ph
  %17 = phi ptr [ %20, %.lr.ph ], [ %16, %15 ]
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  call void @score_count(ptr noundef %18, ptr noundef nonnull %17, ptr noundef nonnull %6) #4
  %19 = load i32, ptr %6, align 4, !tbaa !9
  call void @score_process(ptr noundef nonnull %3, ptr noundef nonnull %4, i32 noundef %19) #4
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %15
  %.sroa.0.0.copyload = load i64, ptr %5, align 8
  %.sroa.2.0.copyload = load i32, ptr %.sroa.3.0..sroa_idx, align 8
  call void @sort_final(ptr noundef nonnull %3, i64 %.sroa.0.0.copyload, i32 %.sroa.2.0.copyload) #4
  call void @ft_lstc_clear(ptr noundef nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  ret i32 0
}

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

declare ptr @init_stack(i32 noundef, ptr noundef) local_unnamed_addr #2

declare void @check_if_duplicated(ptr noundef, ptr noundef) local_unnamed_addr #2

declare zeroext i1 @check_if_sorted(ptr noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #3

declare i32 @ft_lstc_size(ptr noundef) local_unnamed_addr #2

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

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

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

declare void @score_count(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @score_process(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @sort_final(ptr noundef, i64, i32) local_unnamed_addr #2

declare void @ft_lstc_clear(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { noreturn 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 #4 = { nounwind }
attributes #5 = { noreturn 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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