; LLVM IR from AdrianWR/push_swap :: libstack/src (rotate)

; 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_stack = type { i32, i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @rotate(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.s_stack, ptr %5, i32 0, i32 0
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %3, align 4, !tbaa !12
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.s_stack, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.s_stack, ptr %12, i32 0, i32 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds i32, ptr %11, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !12
  store i32 %17, ptr %4, align 4, !tbaa !12
  br label %18

18:                                               ; preds = %22, %1
  %19 = load i32, ptr %3, align 4, !tbaa !12
  %20 = add i32 %19, -1
  store i32 %20, ptr %3, align 4, !tbaa !12
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %37

22:                                               ; preds = %18
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.s_stack, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load i32, ptr %3, align 4, !tbaa !12
  %27 = sub i32 %26, 1
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %25, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.s_stack, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = load i32, ptr %3, align 4, !tbaa !12
  %35 = zext i32 %34 to i64
  %36 = getelementptr inbounds i32, ptr %33, i64 %35
  store i32 %30, ptr %36, align 4, !tbaa !12
  br label %18, !llvm.loop !14

37:                                               ; preds = %18
  %38 = load i32, ptr %4, align 4, !tbaa !12
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.s_stack, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !13
  %42 = getelementptr inbounds i32, ptr %41, i64 0
  store i32 %38, ptr %42, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

; 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

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 = { 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_stack", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @rotate(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !11
  %5 = sext i32 %2 to i64
  %6 = getelementptr inbounds i32, ptr %4, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %.not10 = icmp eq i32 %2, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %8 = add nsw i32 %2, 1
  %9 = zext i32 %2 to i64
  %min.iters.check = icmp ult i32 %2, 44
  br i1 %min.iters.check, label %.lr.ph.preheader28, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %.lr.ph.preheader
  %10 = add i32 %2, -1
  %11 = shl nuw nsw i64 %9, 2
  %scevgep = getelementptr i8, ptr %4, i64 %11
  %12 = zext i32 %10 to i64
  %mul13.neg = mul nsw i64 %12, -4
  %13 = getelementptr i8, ptr %scevgep, i64 %mul13.neg
  %14 = icmp ugt ptr %13, %scevgep
  %15 = zext i32 %10 to i64
  %16 = shl nuw nsw i64 %15, 2
  %scevgep16 = getelementptr i8, ptr %4, i64 %16
  %17 = zext i32 %10 to i64
  %mul17.neg = mul nsw i64 %17, -4
  %18 = getelementptr i8, ptr %scevgep16, i64 %mul17.neg
  %19 = icmp ugt ptr %18, %scevgep16
  %20 = or i1 %14, %19
  br i1 %20, label %.lr.ph.preheader28, label %vector.memcheck

vector.memcheck:                                  ; preds = %vector.scevcheck
  %21 = add i32 %2, -1
  %22 = zext i32 %21 to i64
  %23 = sub nsw i64 %22, %9
  %24 = and i64 %23, 4611686018427387896
  %diff.check = icmp eq i64 %24, 0
  br i1 %diff.check, label %.lr.ph.preheader28, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %9, 4294967288
  %ind.end = and i64 %9, 7
  %.cast = trunc nuw i64 %n.vec to i32
  %ind.end20 = sub i32 %8, %.cast
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = sub i64 %9, %index
  %.cast22 = trunc i64 %index to i32
  %offset.idx23 = sub i32 %8, %.cast22
  %25 = add i32 %offset.idx23, -2
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds i32, ptr %4, i64 %26
  %28 = getelementptr inbounds i8, ptr %27, i64 -12
  %29 = getelementptr inbounds i8, ptr %27, i64 -28
  %wide.load = load <4 x i32>, ptr %28, align 4, !tbaa !12
  %wide.load24 = load <4 x i32>, ptr %29, align 4, !tbaa !12
  %30 = getelementptr inbounds i32, ptr %4, i64 %offset.idx
  %31 = getelementptr inbounds i8, ptr %30, i64 -12
  %32 = getelementptr inbounds i8, ptr %30, i64 -28
  store <4 x i32> %wide.load, ptr %31, align 4, !tbaa !12
  store <4 x i32> %wide.load24, ptr %32, align 4, !tbaa !12
  %index.next = add nuw i64 %index, 8
  %33 = icmp eq i64 %index.next, %n.vec
  br i1 %33, label %middle.block, label %vector.body, !llvm.loop !13

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %9
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader28

.lr.ph.preheader28:                               ; preds = %middle.block, %vector.memcheck, %vector.scevcheck, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ %9, %vector.memcheck ], [ %9, %vector.scevcheck ], [ %9, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  %.011.ph = phi i32 [ %8, %vector.memcheck ], [ %8, %vector.scevcheck ], [ %8, %.lr.ph.preheader ], [ %ind.end20, %middle.block ]
  %34 = trunc nuw i64 %indvars.iv.ph to i32
  %35 = add i32 %34, -1
  %xtraiter = and i32 %34, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader28, %.lr.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %.lr.ph.prol ], [ %indvars.iv.ph, %.lr.ph.preheader28 ]
  %.011.prol = phi i32 [ %41, %.lr.ph.prol ], [ %.011.ph, %.lr.ph.preheader28 ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader28 ]
  %36 = add i32 %.011.prol, -2
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %4, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv.prol
  store i32 %39, ptr %40, align 4, !tbaa !12
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %41 = trunc nuw i64 %indvars.iv.prol to i32
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !17

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader28
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %.lr.ph.preheader28 ], [ %indvars.iv.next.prol, %.lr.ph.prol ]
  %.011.unr = phi i32 [ %.011.ph, %.lr.ph.preheader28 ], [ %41, %.lr.ph.prol ]
  %42 = icmp ult i32 %35, 3
  br i1 %42, label %._crit_edge, label %.lr.ph.preheader28.new

.lr.ph.preheader28.new:                           ; preds = %.lr.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %4, i64 -4
  %invariant.gep29 = getelementptr i8, ptr %4, i64 -8
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader28.new
  %indvars.iv = phi i64 [ %indvars.iv.unr, %.lr.ph.preheader28.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %.011 = phi i32 [ %.011.unr, %.lr.ph.preheader28.new ], [ %62, %.lr.ph ]
  %43 = add i32 %.011, -2
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %4, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv
  store i32 %46, ptr %47, align 4, !tbaa !12
  %48 = add i64 %indvars.iv, 4294967294
  %49 = and i64 %48, 4294967295
  %50 = getelementptr inbounds i32, ptr %4, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !12
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
  store i32 %51, ptr %gep, align 4, !tbaa !12
  %52 = add i64 %indvars.iv, 4294967293
  %53 = and i64 %52, 4294967295
  %54 = getelementptr inbounds i32, ptr %4, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !12
  %gep30 = getelementptr i32, ptr %invariant.gep29, i64 %indvars.iv
  store i32 %55, ptr %gep30, align 4, !tbaa !12
  %indvars.iv.next.2 = add nsw i64 %indvars.iv, -3
  %56 = add i64 %indvars.iv, 4294967292
  %57 = and i64 %56, 4294967295
  %58 = getelementptr inbounds i32, ptr %4, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !12
  %60 = getelementptr inbounds i32, ptr %4, i64 %indvars.iv.next.2
  store i32 %59, ptr %60, align 4, !tbaa !12
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %61 = and i64 %indvars.iv.next.3, 4294967295
  %.not.3 = icmp eq i64 %61, 0
  %62 = trunc nuw i64 %indvars.iv.next.2 to i32
  br i1 %.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !19

._crit_edge:                                      ; preds = %.lr.ph.prol.loopexit, %.lr.ph, %middle.block, %1
  store i32 %7, ptr %4, align 4, !tbaa !12
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

!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, !7, i64 0}
!6 = !{!"s_stack", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14, !15, !16}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!"llvm.loop.isvectorized", i32 1}
!16 = !{!"llvm.loop.unroll.runtime.disable"}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = distinct !{!19, !14, !15}


; Effective O3 passes: EarlyCSEPass,GlobalDCEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass