; LLVM IR from bnidia/push_swap :: sort (check_if_duplicated)

; 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_listc = type { i32, i32, i32, i32, i32, ptr, ptr }
%struct.s_minmaxmed = type { i32, i32, i32 }

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

declare i32 @ft_lstc_size(ptr noundef) #1

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

declare void @ft_lstc_clear(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @check_if_duplicated(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %7, align 8, !tbaa !5
  %9 = call i32 @ft_lstc_size(ptr noundef %8)
  %10 = sext i32 %9 to i64
  %11 = mul i64 4, %10
  %12 = call ptr @ft_malloc(i64 noundef %11)
  store ptr %12, ptr %5, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %13

13:                                               ; preds = %19, %2
  %14 = load i32, ptr %6, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  %17 = call i32 @ft_lstc_size(ptr noundef %16)
  %18 = icmp slt i32 %14, %17
  br i1 %18, label %19, label %34

19:                                               ; preds = %13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.s_listc, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !9
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds i32, ptr %24, i64 %27
  store i32 %23, ptr %28, align 4, !tbaa !9
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.s_listc, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %32, ptr %33, align 8, !tbaa !5
  br label %13, !llvm.loop !14

34:                                               ; preds = %13
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = call i32 @ft_lstc_size(ptr noundef %37)
  %39 = sub nsw i32 %38, 1
  call void @ft_quick_sort(ptr noundef %35, i32 noundef 0, i32 noundef %39)
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %63, %34
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %6, align 4, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = call i32 @ft_lstc_size(ptr noundef %44)
  %46 = sub nsw i32 %45, 1
  %47 = icmp slt i32 %41, %46
  br i1 %47, label %48, label %64

48:                                               ; preds = %40
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %49, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %55, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = icmp eq i32 %54, %59
  br i1 %60, label %61, label %63

61:                                               ; preds = %48
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  call void @ft_lstc_clear(ptr noundef %62)
  call void @ft_error()
  br label %63

63:                                               ; preds = %61, %48
  br label %40, !llvm.loop !16

64:                                               ; preds = %40
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds i32, ptr %65, i64 0
  %67 = load i32, ptr %66, align 4, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.s_minmaxmed, ptr %68, i32 0, i32 0
  store i32 %67, ptr %69, align 4, !tbaa !17
  %70 = load ptr, ptr %5, align 8, !tbaa !5
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  %73 = call i32 @ft_lstc_size(ptr noundef %72)
  %74 = sdiv i32 %73, 2
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %70, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = load ptr, ptr %4, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.s_minmaxmed, ptr %78, i32 0, i32 1
  store i32 %77, ptr %79, align 4, !tbaa !19
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = load ptr, ptr %81, align 8, !tbaa !5
  %83 = call i32 @ft_lstc_size(ptr noundef %82)
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i32, ptr %80, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = load ptr, ptr %4, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.s_minmaxmed, ptr %88, i32 0, i32 2
  store i32 %87, ptr %89, align 4, !tbaa !20
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  call void @free(ptr noundef %90) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

declare ptr @ft_malloc(i64 noundef) #1

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

declare void @ft_error() #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

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 "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, !10, i64 0}
!12 = !{!"s_listc", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!18, !10, i64 0}
!18 = !{!"s_minmaxmed", !10, i64 0, !10, i64 4, !10, i64 8}
!19 = !{!18, !10, i64 4}
!20 = !{!18, !10, i64 8}


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

declare i32 @ft_lstc_size(ptr noundef) local_unnamed_addr #0

declare void @ft_lstc_clear(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @check_if_duplicated(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = tail call i32 @ft_lstc_size(ptr noundef %3) #3
  %5 = sext i32 %4 to i64
  %6 = shl nsw i64 %5, 2
  %7 = tail call ptr @ft_malloc(i64 noundef %6) #3
  %8 = load ptr, ptr %0, align 8, !tbaa !5
  %9 = tail call i32 @ft_lstc_size(ptr noundef %8) #3
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %2 ]
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  store i32 %12, ptr %13, align 4, !tbaa !12
  %14 = getelementptr inbounds i8, ptr %11, i64 32
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  store ptr %15, ptr %0, align 8, !tbaa !5
  %16 = tail call i32 @ft_lstc_size(ptr noundef %15) #3
  %17 = sext i32 %16 to i64
  %18 = icmp slt i64 %indvars.iv.next, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %.lr.ph, %2
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  %20 = tail call i32 @ft_lstc_size(ptr noundef %19) #3
  %21 = add nsw i32 %20, -1
  tail call void @ft_quick_sort(ptr noundef %7, i32 noundef 0, i32 noundef %21) #3
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  %23 = tail call i32 @ft_lstc_size(ptr noundef %22) #3
  %24 = icmp sgt i32 %23, 1
  br i1 %24, label %.lr.ph28, label %._crit_edge29

.lr.ph28:                                         ; preds = %._crit_edge, %31
  %indvars.iv33 = phi i64 [ %indvars.iv.next34, %31 ], [ 0, %._crit_edge ]
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %31 ], [ 1, %._crit_edge ]
  %25 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv33
  %26 = load i32, ptr %25, align 4, !tbaa !12
  %27 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv31
  %28 = load i32, ptr %27, align 4, !tbaa !12
  %29 = icmp eq i32 %26, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %.lr.ph28
  tail call void @ft_lstc_clear(ptr noundef nonnull %0) #3
  tail call void @ft_error() #3
  br label %31

31:                                               ; preds = %30, %.lr.ph28
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %32 = load ptr, ptr %0, align 8, !tbaa !5
  %33 = tail call i32 @ft_lstc_size(ptr noundef %32) #3
  %34 = add nsw i32 %33, -1
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv31, %35
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  br i1 %36, label %.lr.ph28, label %._crit_edge29, !llvm.loop !16

._crit_edge29:                                    ; preds = %31, %._crit_edge
  %37 = load i32, ptr %7, align 4, !tbaa !12
  store i32 %37, ptr %1, align 4, !tbaa !17
  %38 = load ptr, ptr %0, align 8, !tbaa !5
  %39 = tail call i32 @ft_lstc_size(ptr noundef %38) #3
  %40 = sdiv i32 %39, 2
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %7, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 %43, ptr %44, align 4, !tbaa !19
  %45 = load ptr, ptr %0, align 8, !tbaa !5
  %46 = tail call i32 @ft_lstc_size(ptr noundef %45) #3
  %47 = sext i32 %46 to i64
  %48 = getelementptr i32, ptr %7, i64 %47
  %49 = getelementptr i8, ptr %48, i64 -4
  %50 = load i32, ptr %49, align 4, !tbaa !12
  %51 = getelementptr inbounds i8, ptr %1, i64 8
  store i32 %50, ptr %51, align 4, !tbaa !20
  tail call void @free(ptr noundef %7) #3
  ret void
}

declare ptr @ft_malloc(i64 noundef) local_unnamed_addr #0

declare void @ft_quick_sort(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @ft_error() local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

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 = { 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !11, i64 0}
!10 = !{!"s_listc", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}
!17 = !{!18, !11, i64 0}
!18 = !{!"s_minmaxmed", !11, i64 0, !11, i64 4, !11, i64 8}
!19 = !{!18, !11, i64 4}
!20 = !{!18, !11, i64 8}


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