; LLVM IR from JessonYue/LeetCodeLearning :: Array/fanbei/0617/c (soloution06_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, i32 }

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

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %13, %7
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.MyQueue, ptr %9, i32 0, i32 2
  %11 = load i32, ptr %10, align 8, !tbaa !12
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %46

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

46:                                               ; preds = %8
  br label %47

47:                                               ; preds = %46, %1
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.MyQueue, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !15
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MyQueue, ptr %51, i32 0, i32 3
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %50, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !14
  ret i32 %57
}

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, !11, i64 20}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !6, i64 0}
!14 = !{!11, !11, i64 0}
!15 = !{!10, !6, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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 i32 @myQueuePeek(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 20
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %8 = load ptr, ptr %0, align 8, !tbaa !12
  %invariant.gep = getelementptr i8, ptr %8, i64 -4
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %.lr.ph, %11
  %12 = phi i32 [ %6, %.lr.ph ], [ %22, %11 ]
  %13 = zext nneg i32 %12 to i64
  %gep = getelementptr i32, ptr %invariant.gep, i64 %13
  %14 = load i32, ptr %gep, align 4, !tbaa !14
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %2, align 4, !tbaa !5
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds i32, ptr %10, i64 %17
  store i32 %14, ptr %18, align 4, !tbaa !14
  %19 = load i32, ptr %5, align 8, !tbaa !11
  %20 = sext i32 %19 to i64
  %gep12 = getelementptr i32, ptr %invariant.gep, i64 %20
  store i32 0, ptr %gep12, align 4, !tbaa !14
  %21 = load i32, ptr %5, align 8, !tbaa !11
  %22 = add nsw i32 %21, -1
  store i32 %22, ptr %5, align 8, !tbaa !11
  %23 = icmp sgt i32 %21, 1
  br i1 %23, label %11, label %.loopexit.loopexit, !llvm.loop !15

.loopexit.loopexit:                               ; preds = %11
  %.pre = load i32, ptr %2, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.preheader, %1
  %24 = phi i32 [ %.pre, %.loopexit.loopexit ], [ 0, %.preheader ], [ %3, %1 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = load ptr, ptr %25, align 8, !tbaa !13
  %27 = sext i32 %24 to i64
  %28 = getelementptr i32, ptr %26, i64 %27
  %29 = getelementptr i8, ptr %28, i64 -4
  %30 = load i32, ptr %29, align 4, !tbaa !14
  ret i32 %30
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass