; 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: 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
define dso_local i32 @myQueuePop(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.MyQueue, ptr %4, i32 0, i32 3
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %48

8:                                                ; preds = %1
  br label %9

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

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

47:                                               ; preds = %9
  br label %48

48:                                               ; preds = %47, %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.MyQueue, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MyQueue, ptr %52, i32 0, i32 3
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = sub nsw i32 %54, 1
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %51, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !14
  store i32 %58, ptr %3, align 4, !tbaa !14
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.MyQueue, ptr %59, i32 0, i32 1
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.MyQueue, ptr %62, i32 0, i32 3
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 1
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr %61, i64 %66
  store i32 0, ptr %67, align 4, !tbaa !14
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.MyQueue, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = add nsw i32 %70, -1
  store i32 %71, ptr %69, align 4, !tbaa !9
  %72 = load i32, ptr %3, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %72
}

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, !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 @myQueuePop(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
  %gep15 = getelementptr i32, ptr %invariant.gep, i64 %20
  store i32 0, ptr %gep15, 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
  store i32 0, ptr %29, align 4, !tbaa !14
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = add nsw i32 %31, -1
  store i32 %32, ptr %2, align 4, !tbaa !5
  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,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass