; LLVM IR from HarshCasper/NeoAlgo :: C/ds (reverse-queue)

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @pop() #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isStackEmpty() #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isQueueEmpty() #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @dequeue() #0

; Function Attrs: nounwind uwtable
define dso_local void @reverseQueue() #0 {
  br label %1

1:                                                ; preds = %5, %0
  %2 = call i32 @isQueueEmpty()
  %3 = icmp ne i32 %2, 0
  %4 = xor i1 %3, true
  br i1 %4, label %5, label %7

5:                                                ; preds = %1
  %6 = call i32 @dequeue()
  call void @push(i32 noundef %6)
  br label %1, !llvm.loop !5

7:                                                ; preds = %1
  br label %8

8:                                                ; preds = %12, %7
  %9 = call i32 @isStackEmpty()
  %10 = icmp ne i32 %9, 0
  %11 = xor i1 %10, true
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = call i32 @pop()
  call void @enqueue(i32 noundef %13)
  br label %8, !llvm.loop !7

14:                                               ; preds = %8
  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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; 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 void @push(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @pop() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isStackEmpty() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isQueueEmpty() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @dequeue() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @reverseQueue() local_unnamed_addr #0 {
  %1 = tail call i32 @isQueueEmpty()
  %.not2 = icmp eq i32 %1, 0
  br i1 %.not2, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %0
  %2 = tail call i32 @isStackEmpty()
  %.not13 = icmp eq i32 %2, 0
  br i1 %.not13, label %.lr.ph4, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %3 = tail call i32 @dequeue()
  tail call void @push(i32 noundef %3)
  %4 = tail call i32 @isQueueEmpty()
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.lr.ph, label %.preheader, !llvm.loop !5

.lr.ph4:                                          ; preds = %.preheader, %.lr.ph4
  %5 = tail call i32 @pop()
  tail call void @enqueue(i32 noundef %5)
  %6 = tail call i32 @isStackEmpty()
  %.not1 = icmp eq i32 %6, 0
  br i1 %.not1, label %.lr.ph4, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph4, %.preheader
  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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SimplifyCFGPass,TailCallElimPass