; LLVM IR from JessonYue/LeetCodeLearning :: Array/wuchao/stack/6-17栈实现队列 (MyQueue)

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @myStackPop(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @myQueuePush(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %11, %2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MyQueue, ptr %6, i32 0, i32 1
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = call zeroext i1 @myStackEmpty(ptr noundef %8)
  %10 = xor i1 %9, true
  br i1 %10, label %11, label %19

11:                                               ; preds = %5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.MyQueue, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.MyQueue, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = call i32 @myStackPop(ptr noundef %17)
  call void @myStackPush(ptr noundef %14, i32 noundef %18)
  br label %5, !llvm.loop !14

19:                                               ; preds = %5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MyQueue, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load i32, ptr %4, align 4, !tbaa !9
  call void @myStackPush(ptr noundef %22, i32 noundef %23)
  br label %24

24:                                               ; preds = %30, %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MyQueue, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = call zeroext i1 @myStackEmpty(ptr noundef %27)
  %29 = xor i1 %28, true
  br i1 %29, label %30, label %38

30:                                               ; preds = %24
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MyQueue, ptr %31, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !11
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MyQueue, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = call i32 @myStackPop(ptr noundef %36)
  call void @myStackPush(ptr noundef %33, i32 noundef %37)
  br label %24, !llvm.loop !16

38:                                               ; preds = %24
  ret void
}

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

!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, !6, i64 8}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 @myStackEmpty(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local void @myQueuePush(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call zeroext i1 @myStackEmpty(ptr noundef %4)
  br i1 %5, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %.lr.ph
  %6 = load ptr, ptr %0, align 8, !tbaa !10
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = tail call i32 @myStackPop(ptr noundef %7)
  tail call void @myStackPush(ptr noundef %6, i32 noundef %8)
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = tail call zeroext i1 @myStackEmpty(ptr noundef %9)
  br i1 %10, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %2
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @myStackPush(ptr noundef %11, i32 noundef %1)
  %12 = load ptr, ptr %0, align 8, !tbaa !10
  %13 = tail call zeroext i1 @myStackEmpty(ptr noundef %12)
  br i1 %13, label %._crit_edge9, label %.lr.ph8

.lr.ph8:                                          ; preds = %._crit_edge, %.lr.ph8
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = load ptr, ptr %0, align 8, !tbaa !10
  %16 = tail call i32 @myStackPop(ptr noundef %15)
  tail call void @myStackPush(ptr noundef %14, i32 noundef %16)
  %17 = load ptr, ptr %0, align 8, !tbaa !10
  %18 = tail call zeroext i1 @myStackEmpty(ptr noundef %17)
  br i1 %18, label %._crit_edge9, label %.lr.ph8, !llvm.loop !13

._crit_edge9:                                     ; preds = %.lr.ph8, %._crit_edge
  ret void
}

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass