; LLVM IR from bnidia/push_swap :: main (leave_three)

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

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare i32 @ft_lstc_size(ptr noundef) #2

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

19:                                               ; preds = %4
  store i32 1, ptr %10, align 4
  br label %68

20:                                               ; preds = %4
  br label %21

21:                                               ; preds = %66, %49, %20
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr %9, align 4, !tbaa !9
  %24 = icmp ne i32 %22, 0
  br i1 %24, label %25, label %67

25:                                               ; preds = %21
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load ptr, ptr %26, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.s_listc, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %struct.s_minmaxmed, ptr %5, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = icmp eq i32 %29, %31
  br i1 %32, label %49, label %33

33:                                               ; preds = %25
  %34 = load ptr, ptr %7, align 8, !tbaa !5
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.s_listc, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %36, align 8, !tbaa !11
  %38 = getelementptr inbounds %struct.s_minmaxmed, ptr %5, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !15
  %40 = icmp eq i32 %37, %39
  br i1 %40, label %49, label %41

41:                                               ; preds = %33
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.s_listc, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.s_minmaxmed, ptr %5, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !16
  %48 = icmp eq i32 %45, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %41, %33, %25
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  call void @ra(ptr noundef %50, i1 noundef zeroext true)
  br label %21, !llvm.loop !17

51:                                               ; preds = %41
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = load ptr, ptr %52, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.s_listc, ptr %53, i32 0, i32 0
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = getelementptr inbounds %struct.s_minmaxmed, ptr %5, i32 0, i32 1
  %57 = load i32, ptr %56, align 4, !tbaa !16
  %58 = icmp slt i32 %55, %57
  br i1 %58, label %59, label %62

59:                                               ; preds = %51
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  call void @pb(ptr noundef %60, ptr noundef %61, i1 noundef zeroext true)
  br label %66

62:                                               ; preds = %51
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  call void @pb(ptr noundef %63, ptr noundef %64, i1 noundef zeroext true)
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  call void @rb(ptr noundef %65, i1 noundef zeroext true)
  br label %66

66:                                               ; preds = %62, %59
  br label %21, !llvm.loop !17

67:                                               ; preds = %21
  store i32 0, ptr %10, align 4
  br label %68

68:                                               ; preds = %67, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %69 = load i32, ptr %10, align 4
  switch i32 %69, label %71 [
    i32 0, label %70
    i32 1, label %70
  ]

70:                                               ; preds = %68, %68
  ret void

71:                                               ; preds = %68
  unreachable
}

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

declare void @ra(ptr noundef, i1 noundef zeroext) #2

declare void @pb(ptr noundef, ptr noundef, i1 noundef zeroext) #2

declare void @rb(ptr noundef, i1 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 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, !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 = !{!14, !10, i64 0}
!14 = !{!"s_minmaxmed", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!14, !10, i64 4}
!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"

declare i32 @ft_lstc_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @leave_three(ptr noundef %0, ptr noundef %1, i64 %2, i32 %3) local_unnamed_addr #1 {
  %.sroa.013.0.extract.trunc = trunc i64 %2 to i32
  %.sroa.214.0.extract.shift = lshr i64 %2, 32
  %.sroa.214.0.extract.trunc = trunc nuw i64 %.sroa.214.0.extract.shift to i32
  store ptr null, ptr %1, align 8, !tbaa !5
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = tail call i32 @ft_lstc_size(ptr noundef %5) #2
  %7 = icmp slt i32 %6, 4
  br i1 %7, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %4, %.backedge
  %.in = phi i32 [ %8, %.backedge ], [ %6, %4 ]
  %8 = add nsw i32 %.in, -1
  %9 = load ptr, ptr %0, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, %.sroa.013.0.extract.trunc
  %12 = icmp eq i32 %10, %3
  %or.cond = select i1 %11, i1 true, i1 %12
  %13 = icmp eq i32 %10, %.sroa.214.0.extract.trunc
  %or.cond18 = select i1 %or.cond, i1 true, i1 %13
  br i1 %or.cond18, label %14, label %15

14:                                               ; preds = %.preheader
  tail call void @ra(ptr noundef nonnull %0, i1 noundef zeroext true) #2
  br label %.backedge

.backedge:                                        ; preds = %15, %17, %14
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %.loopexit, label %.preheader, !llvm.loop !12

15:                                               ; preds = %.preheader
  %16 = icmp slt i32 %10, %.sroa.214.0.extract.trunc
  tail call void @pb(ptr noundef nonnull %0, ptr noundef nonnull %1, i1 noundef zeroext true) #2
  br i1 %16, label %.backedge, label %17

17:                                               ; preds = %15
  tail call void @rb(ptr noundef nonnull %1, i1 noundef zeroext true) #2
  br label %.backedge

.loopexit:                                        ; preds = %.backedge, %4
  ret void
}

declare void @ra(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @pb(ptr noundef, ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

declare void @rb(ptr noundef, i1 noundef zeroext) local_unnamed_addr #0

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 = { 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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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