; LLVM IR from ritikbanger/Hacktoberfest2022-DSA :: 30. CPP Programs (Reversing 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"

%struct.queue = type { [5 x i32], i32, i32 }

@st = external dso_local global %struct.queue, align 4
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [23 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4fullv() #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5emptyv() #0

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7dequeuev() #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7displayv() #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z25reverse_queue_using_stackv() #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #5 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 -1, ptr getelementptr inbounds (%struct.queue, ptr @st, i32 0, i32 2), align 4, !tbaa !5
  store i32 -1, ptr getelementptr inbounds (%struct.queue, ptr @st, i32 0, i32 1), align 4, !tbaa !10
  %4 = call i32 (ptr, ...) @printf(ptr noundef @.str.6)
  %5 = call i32 (ptr, ...) @printf(ptr noundef @.str.7)
  br label %6

6:                                                ; preds = %33, %0
  br label %7

7:                                                ; preds = %6
  %8 = call i32 (ptr, ...) @printf(ptr noundef @.str.8)
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.9, ptr noundef %3)
  %10 = load i32, ptr %3, align 4, !tbaa !11
  switch i32 %10, label %32 [
    i32 1, label %11
    i32 2, label %21
    i32 3, label %30
    i32 4, label %31
  ]

11:                                               ; preds = %7
  %12 = call noundef i32 @_Z4fullv()
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %11
  %15 = call i32 (ptr, ...) @printf(ptr noundef @.str.10)
  br label %20

16:                                               ; preds = %11
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str.11)
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.9, ptr noundef %2)
  %19 = load i32, ptr %2, align 4, !tbaa !11
  call void @_Z7enqueuei(i32 noundef %19)
  br label %20

20:                                               ; preds = %16, %14
  br label %33

21:                                               ; preds = %7
  %22 = call noundef i32 @_Z5emptyv()
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  br label %29

26:                                               ; preds = %21
  %27 = call noundef i32 @_Z7dequeuev()
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.12, i32 noundef %27)
  br label %29

29:                                               ; preds = %26, %24
  br label %33

30:                                               ; preds = %7
  call void @_Z7displayv()
  br label %33

31:                                               ; preds = %7
  call void @_Z25reverse_queue_using_stackv()
  br label %33

32:                                               ; preds = %7
  call void @exit(i32 noundef 0) #7
  unreachable

33:                                               ; preds = %31, %30, %29, %20
  br label %6, !llvm.loop !12
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

attributes #0 = { mustprogress 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { "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 #4 = { noreturn nounwind "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 #5 = { mustprogress norecurse 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 #6 = { nounwind }
attributes #7 = { noreturn 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, !9, i64 24}
!6 = !{!"_ZTS5queue", !7, i64 0, !9, i64 20, !9, i64 24}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 20}
!11 = !{!9, !9, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.queue = type { [5 x i32], i32, i32 }

@st = external dso_local local_unnamed_addr global %struct.queue, align 4
@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [33 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [49 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [23 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z7displayv() local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z25reverse_queue_using_stackv() local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress norecurse noreturn uwtable
define dso_local noundef i32 @main() local_unnamed_addr #5 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  store i32 -1, ptr getelementptr inbounds (i8, ptr @st, i64 24), align 4, !tbaa !5
  store i32 -1, ptr getelementptr inbounds (i8, ptr @st, i64 20), align 4, !tbaa !10
  %3 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6)
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7)
  br label %5

5:                                                ; preds = %.backedge, %0
  %6 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8)
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.9, ptr noundef nonnull %2)
  %8 = load i32, ptr %2, align 4, !tbaa !11
  switch i32 %8, label %26 [
    i32 1, label %9
    i32 2, label %17
    i32 3, label %24
    i32 4, label %25
  ]

9:                                                ; preds = %5
  %10 = call noundef i32 @_Z4fullv()
  %.not1 = icmp eq i32 %10, 0
  br i1 %.not1, label %13, label %11

11:                                               ; preds = %9
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.10)
  br label %.backedge

13:                                               ; preds = %9
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.11)
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.9, ptr noundef nonnull %1)
  %16 = load i32, ptr %1, align 4, !tbaa !11
  call void @_Z7enqueuei(i32 noundef %16)
  br label %.backedge

17:                                               ; preds = %5
  %18 = call noundef i32 @_Z5emptyv()
  %.not = icmp eq i32 %18, 0
  br i1 %.not, label %21, label %19

19:                                               ; preds = %17
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  br label %.backedge

.backedge:                                        ; preds = %19, %21, %11, %13, %25, %24
  br label %5, !llvm.loop !12

21:                                               ; preds = %17
  %22 = call noundef i32 @_Z7dequeuev()
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.12, i32 noundef %22)
  br label %.backedge

24:                                               ; preds = %5
  call void @_Z7displayv()
  br label %.backedge

25:                                               ; preds = %5
  call void @_Z25reverse_queue_using_stackv()
  br label %.backedge

26:                                               ; preds = %5
  call void @exit(i32 noundef 0) #7
  unreachable
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #3

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass