; LLVM IR from JessonYue/LeetCodeLearning :: Array/linchuanxin/Algorithm/day17_0617_通过栈实现队列 (day_17_leetcode232)

; 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 { %struct.MyStack, %struct.MyStack }
%struct.MyStack = type { [5 x i32], i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @myQueuePop(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.MyQueue, ptr %4, i32 0, i32 1
  %6 = getelementptr inbounds %struct.MyStack, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %9, label %57

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MyQueue, ptr %10, i32 0, i32 0
  %12 = getelementptr inbounds %struct.MyStack, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !13
  %14 = icmp ne i32 %13, -1
  br i1 %14, label %15, label %56

15:                                               ; preds = %9
  br label %16

16:                                               ; preds = %22, %15
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MyQueue, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.MyStack, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = icmp ne i32 %20, -1
  br i1 %21, label %22, label %44

22:                                               ; preds = %16
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MyQueue, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.MyStack, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.MyQueue, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.MyStack, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !13
  %30 = add nsw i32 %29, -1
  store i32 %30, ptr %28, align 4, !tbaa !13
  %31 = sext i32 %29 to i64
  %32 = getelementptr inbounds [5 x i32], ptr %25, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !14
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MyQueue, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.MyStack, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MyQueue, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.MyStack, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %39, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5 x i32], ptr %36, i64 0, i64 %42
  store i32 %33, ptr %43, align 4, !tbaa !14
  br label %16, !llvm.loop !15

44:                                               ; preds = %16
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MyQueue, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.MyStack, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.MyQueue, ptr %48, i32 0, i32 1
  %50 = getelementptr inbounds %struct.MyStack, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = add nsw i32 %51, -1
  store i32 %52, ptr %50, align 4, !tbaa !9
  %53 = sext i32 %51 to i64
  %54 = getelementptr inbounds [5 x i32], ptr %47, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !14
  store i32 %55, ptr %2, align 4
  br label %69

56:                                               ; preds = %9
  store i32 -1, ptr %2, align 4
  br label %69

57:                                               ; preds = %1
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.MyQueue, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.MyStack, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.MyQueue, ptr %61, i32 0, i32 1
  %63 = getelementptr inbounds %struct.MyStack, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = add nsw i32 %64, -1
  store i32 %65, ptr %63, align 4, !tbaa !9
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [5 x i32], ptr %60, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !14
  store i32 %68, ptr %2, align 4
  br label %69

69:                                               ; preds = %57, %56, %44
  %70 = load i32, ptr %2, align 4
  ret i32 %70
}

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, !12, i64 44}
!10 = !{!"", !11, i64 0, !11, i64 24}
!11 = !{!"", !7, i64 0, !12, i64 20}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 20}
!14 = !{!12, !12, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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(argmem: readwrite) uwtable
define dso_local i32 @myQueuePop(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 24
  %3 = getelementptr inbounds i8, ptr %0, i64 44
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp eq i32 %4, -1
  br i1 %5, label %6, label %.sink.split

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %.not = icmp eq i32 %8, -1
  br i1 %.not, label %24, label %.preheader

.preheader:                                       ; preds = %6, %.preheader
  %9 = phi i32 [ %.pr, %.preheader ], [ %8, %6 ]
  %10 = add nsw i32 %9, -1
  store i32 %10, ptr %7, align 4, !tbaa !11
  %11 = sext i32 %9 to i64
  %12 = getelementptr inbounds [5 x i32], ptr %0, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !12
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %3, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %16
  store i32 %13, ptr %17, align 4, !tbaa !12
  %.pr = load i32, ptr %7, align 4, !tbaa !11
  %.not13 = icmp eq i32 %.pr, -1
  br i1 %.not13, label %18, label %.preheader, !llvm.loop !13

18:                                               ; preds = %.preheader
  %19 = load i32, ptr %3, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %1, %18
  %.sink16 = phi i32 [ %19, %18 ], [ %4, %1 ]
  %20 = add nsw i32 %.sink16, -1
  store i32 %20, ptr %3, align 4, !tbaa !5
  %21 = sext i32 %.sink16 to i64
  %22 = getelementptr inbounds [5 x i32], ptr %2, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !12
  br label %24

24:                                               ; preds = %.sink.split, %6
  %.0 = phi i32 [ -1, %6 ], [ %23, %.sink.split ]
  ret i32 %.0
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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, !10, i64 44}
!6 = !{!"", !7, i64 0, !7, i64 24}
!7 = !{!"", !8, i64 0, !10, i64 20}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 20}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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