; LLVM IR from JessonYue/LeetCodeLearning :: Array/zhangjunwei/queue (MyQueue_6_17)

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @myQueueEmpty(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @myQueuePeek(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 -1, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call zeroext i1 @myQueueEmpty(ptr noundef %8)
  br i1 %9, label %10, label %12

10:                                               ; preds = %1
  %11 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %11, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %61

12:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.MyQueue, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !11
  store i32 %15, ptr %7, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %19, %12
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp sge i32 %17, 0
  br i1 %18, label %19, label %35

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

35:                                               ; preds = %16
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MyQueue, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MyQueue, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %38, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  store i32 %44, ptr %4, align 4, !tbaa !9
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MyQueue, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !11
  store i32 %47, ptr %7, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %51, %35
  %49 = load i32, ptr %7, align 4, !tbaa !9
  %50 = icmp sge i32 %49, 0
  br i1 %50, label %51, label %59

51:                                               ; preds = %48
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MyQueue, ptr %52, i32 0, i32 1
  %54 = load ptr, ptr %53, align 8, !tbaa !14
  %55 = load i32, ptr %7, align 4, !tbaa !9
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr %7, align 4, !tbaa !9
  %57 = sext i32 %55 to i64
  %58 = getelementptr inbounds i32, ptr %54, i64 %57
  store i32 0, ptr %58, align 4, !tbaa !9
  br label %48, !llvm.loop !17

59:                                               ; preds = %48
  %60 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %60, ptr %2, align 4
  store i32 1, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %61

61:                                               ; preds = %59, %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %62 = load i32, ptr %2, align 4
  ret i32 %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 0}
!14 = !{!12, !6, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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
declare dso_local zeroext i1 @myQueueEmpty(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @myQueuePeek(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call zeroext i1 @myQueueEmpty(ptr noundef %0)
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp sgt i32 %5, -1
  br i1 %6, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %3
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !11
  %7 = sext i32 %5 to i64
  %8 = getelementptr inbounds i32, ptr %.pre, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !12
  br label %.loopexit

.lr.ph:                                           ; preds = %3
  %10 = load ptr, ptr %0, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = zext nneg i32 %5 to i64
  %14 = add nuw i32 %5, 1
  %wide.trip.count = zext i32 %14 to i64
  %min.iters.check = icmp ult i32 %5, 15
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

vector.memcheck:                                  ; preds = %.lr.ph
  %15 = shl nuw nsw i64 %wide.trip.count, 2
  %scevgep = getelementptr i8, ptr %12, i64 %15
  %16 = shl nuw nsw i64 %13, 2
  %17 = add nuw nsw i64 %16, 4
  %18 = sub nsw i64 %17, %15
  %scevgep31 = getelementptr i8, ptr %10, i64 %18
  %19 = getelementptr i8, ptr %10, i64 %16
  %scevgep32 = getelementptr i8, ptr %19, i64 4
  %bound0 = icmp ult ptr %12, %scevgep32
  %bound1 = icmp ult ptr %scevgep31, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 4294967288
  %ind.end = sub nsw i64 %13, %n.vec
  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 %13, %index
  %20 = getelementptr inbounds i32, ptr %10, i64 %offset.idx
  %21 = getelementptr inbounds i8, ptr %20, i64 -12
  %22 = getelementptr inbounds i8, ptr %20, i64 -28
  %wide.load = load <4 x i32>, ptr %21, align 4, !tbaa !12, !alias.scope !14
  %reverse = shufflevector <4 x i32> %wide.load, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %wide.load34 = load <4 x i32>, ptr %22, align 4, !tbaa !12, !alias.scope !14
  %reverse35 = shufflevector <4 x i32> %wide.load34, <4 x i32> poison, <4 x i32> <i32 3, i32 2, i32 1, i32 0>
  %23 = getelementptr inbounds i32, ptr %12, i64 %index
  %24 = getelementptr inbounds i8, ptr %23, i64 16
  store <4 x i32> %reverse, ptr %23, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  store <4 x i32> %reverse35, ptr %24, align 4, !tbaa !12, !alias.scope !17, !noalias !14
  %index.next = add nuw i64 %index, 8
  %25 = icmp eq i64 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !19

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv22.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %indvars.iv.ph = phi i64 [ %13, %vector.memcheck ], [ %13, %.lr.ph ], [ %ind.end, %middle.block ]
  %26 = zext nneg i32 %5 to i64
  %27 = sub nsw i64 %26, %indvars.iv22.ph
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv22.prol = phi i64 [ %indvars.iv.next23.prol, %scalar.ph.prol ], [ %indvars.iv22.ph, %scalar.ph.preheader ]
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %indvars.iv.next.prol = add nsw i64 %indvars.iv.prol, -1
  %28 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.prol
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %indvars.iv.next23.prol = add nuw nsw i64 %indvars.iv22.prol, 1
  %30 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv22.prol
  store i32 %29, ptr %30, align 4, !tbaa !12
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !23

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv22.unr = phi i64 [ %indvars.iv22.ph, %scalar.ph.preheader ], [ %indvars.iv.next23.prol, %scalar.ph.prol ]
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %31 = icmp ult i64 %27, 3
  br i1 %31, label %._crit_edge, label %scalar.ph.preheader.new

scalar.ph.preheader.new:                          ; preds = %scalar.ph.prol.loopexit
  %invariant.gep = getelementptr i8, ptr %10, i64 -4
  %invariant.gep36 = getelementptr i8, ptr %12, i64 4
  %invariant.gep38 = getelementptr i8, ptr %10, i64 -8
  %invariant.gep40 = getelementptr i8, ptr %12, i64 8
  %invariant.gep42 = getelementptr i8, ptr %10, i64 -12
  %invariant.gep44 = getelementptr i8, ptr %12, i64 12
  br label %scalar.ph

scalar.ph:                                        ; preds = %scalar.ph, %scalar.ph.preheader.new
  %indvars.iv22 = phi i64 [ %indvars.iv22.unr, %scalar.ph.preheader.new ], [ %indvars.iv.next23.3, %scalar.ph ]
  %indvars.iv = phi i64 [ %indvars.iv.unr, %scalar.ph.preheader.new ], [ %indvars.iv.next.3, %scalar.ph ]
  %32 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = getelementptr inbounds i32, ptr %12, i64 %indvars.iv22
  store i32 %33, ptr %34, align 4, !tbaa !12
  %gep = getelementptr i32, ptr %invariant.gep, i64 %indvars.iv
  %35 = load i32, ptr %gep, align 4, !tbaa !12
  %gep37 = getelementptr i32, ptr %invariant.gep36, i64 %indvars.iv22
  store i32 %35, ptr %gep37, align 4, !tbaa !12
  %gep39 = getelementptr i32, ptr %invariant.gep38, i64 %indvars.iv
  %36 = load i32, ptr %gep39, align 4, !tbaa !12
  %gep41 = getelementptr i32, ptr %invariant.gep40, i64 %indvars.iv22
  store i32 %36, ptr %gep41, align 4, !tbaa !12
  %indvars.iv.next.3 = add nsw i64 %indvars.iv, -4
  %gep43 = getelementptr i32, ptr %invariant.gep42, i64 %indvars.iv
  %37 = load i32, ptr %gep43, align 4, !tbaa !12
  %indvars.iv.next23.3 = add nuw nsw i64 %indvars.iv22, 4
  %gep45 = getelementptr i32, ptr %invariant.gep44, i64 %indvars.iv22
  store i32 %37, ptr %gep45, align 4, !tbaa !12
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next23.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !25

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block
  %.pre30 = load i32, ptr %4, align 8, !tbaa !5
  %38 = sext i32 %.pre30 to i64
  %39 = getelementptr inbounds i32, ptr %12, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !12
  %41 = icmp sgt i32 %.pre30, -1
  br i1 %41, label %.lr.ph21.preheader, label %.loopexit

.lr.ph21.preheader:                               ; preds = %._crit_edge
  %42 = add nuw i32 %.pre30, 1
  %43 = zext i32 %42 to i64
  %44 = shl nuw nsw i64 %43, 2
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %12, i8 0, i64 %44, i1 false), !tbaa !12
  br label %.loopexit

.loopexit:                                        ; preds = %._crit_edge.thread, %.lr.ph21.preheader, %._crit_edge, %1
  %.016 = phi i32 [ -1, %1 ], [ %40, %._crit_edge ], [ %40, %.lr.ph21.preheader ], [ %9, %._crit_edge.thread ]
  ret i32 %.016
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 nounwind willreturn memory(argmem: write) }

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


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopIdiomRecognizePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass,TailCallElimPass