; LLVM IR from bnidia/push_swap :: score (score_count)

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

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

16:                                               ; preds = %81, %3
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %20, label %87

20:                                               ; preds = %16
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  call void @reset_scores(ptr noundef %21)
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  call void @score_count_a(ptr noundef %22, ptr noundef %23)
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.s_listc, ptr %25, i32 0, i32 3
  store i32 %24, ptr %26, align 4, !tbaa !11
  %27 = load i32, ptr %9, align 4, !tbaa !9
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = sub nsw i32 %27, %28
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.s_listc, ptr %30, i32 0, i32 4
  store i32 %29, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.s_listc, ptr %32, i32 0, i32 4
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s_listc, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 4, !tbaa !11
  %38 = icmp sge i32 %34, %37
  br i1 %38, label %39, label %42

39:                                               ; preds = %20
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.s_listc, ptr %40, i32 0, i32 4
  store i32 0, ptr %41, align 8, !tbaa !13
  br label %45

42:                                               ; preds = %20
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_listc, ptr %43, i32 0, i32 3
  store i32 0, ptr %44, align 4, !tbaa !11
  br label %45

45:                                               ; preds = %42, %39
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.s_listc, ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !11
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.s_listc, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !14
  %54 = add nsw i32 %50, %53
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.s_listc, ptr %55, i32 0, i32 4
  %57 = load i32, ptr %56, align 8, !tbaa !13
  %58 = add nsw i32 %54, %57
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.s_listc, ptr %59, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !15
  %62 = add nsw i32 %58, %61
  %63 = icmp sgt i32 %47, %62
  br i1 %63, label %64, label %81

64:                                               ; preds = %45
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.s_listc, ptr %65, i32 0, i32 3
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.s_listc, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !14
  %71 = add nsw i32 %67, %70
  %72 = load ptr, ptr %8, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.s_listc, ptr %72, i32 0, i32 4
  %74 = load i32, ptr %73, align 8, !tbaa !13
  %75 = add nsw i32 %71, %74
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.s_listc, ptr %76, i32 0, i32 2
  %78 = load i32, ptr %77, align 8, !tbaa !15
  %79 = add nsw i32 %75, %78
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !9
  br label %81

81:                                               ; preds = %64, %45
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.s_listc, ptr %82, i32 0, i32 6
  %84 = load ptr, ptr %83, align 8, !tbaa !16
  store ptr %84, ptr %8, align 8, !tbaa !5
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr %10, align 4, !tbaa !9
  br label %16, !llvm.loop !17

87:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret void
}

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

declare i32 @ft_lstc_size(ptr noundef) #2

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

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

; 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 = { 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 12}
!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, !10, i64 16}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !6, i64 32}
!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"

; Function Attrs: nounwind uwtable
define dso_local void @score_count(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2) local_unnamed_addr #0 {
  store i32 2147483647, ptr %2, align 4, !tbaa !5
  %4 = tail call i32 @ft_lstc_size(ptr noundef %1) #2
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %24
  %.033 = phi i32 [ %27, %24 ], [ 0, %3 ]
  %.02932 = phi ptr [ %26, %24 ], [ %1, %3 ]
  tail call void @reset_scores(ptr noundef %.02932)
  tail call void @score_count_a(ptr noundef %0, ptr noundef %.02932)
  %6 = getelementptr inbounds i8, ptr %.02932, i64 12
  store i32 %.033, ptr %6, align 4, !tbaa !9
  %7 = sub nsw i32 %4, %.033
  %8 = getelementptr inbounds i8, ptr %.02932, i64 16
  store i32 %7, ptr %8, align 8, !tbaa !12
  %.not = icmp slt i32 %7, %.033
  br i1 %.not, label %10, label %9

9:                                                ; preds = %.lr.ph
  store i32 0, ptr %8, align 8, !tbaa !12
  br label %11

10:                                               ; preds = %.lr.ph
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %10, %9
  %12 = phi i32 [ %7, %10 ], [ 0, %9 ]
  %13 = phi i32 [ 0, %10 ], [ %.033, %9 ]
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %.02932, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !13
  %17 = add nsw i32 %16, %13
  %18 = add nsw i32 %17, %12
  %19 = getelementptr inbounds i8, ptr %.02932, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !14
  %21 = add nsw i32 %18, %20
  %22 = icmp sgt i32 %14, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %11
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %23, %11
  %25 = getelementptr inbounds i8, ptr %.02932, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = add nuw nsw i32 %.033, 1
  %exitcond.not = icmp eq i32 %27, %4
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %24, %3
  ret void
}

declare i32 @ft_lstc_size(ptr noundef) local_unnamed_addr #1

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

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

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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 12}
!10 = !{!"s_listc", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !11, i64 24, !11, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 4}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !11, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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