; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: Data Structures/Queues (circular_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"

@rear = external dso_local global i32, align 4
@front = external dso_local global i32, align 4
@queue = external dso_local global [5 x i32], align 16
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; 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 void @display() #2 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %2 = load i32, ptr @rear, align 4, !tbaa !5
  %3 = load i32, ptr @front, align 4, !tbaa !5
  %4 = icmp sge i32 %2, %3
  br i1 %4, label %5, label %21

5:                                                ; preds = %0
  %6 = load i32, ptr @front, align 4, !tbaa !5
  store i32 %6, ptr %1, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %17, %5
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr @rear, align 4, !tbaa !5
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %11, label %20

11:                                               ; preds = %7
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [5 x i32], ptr @queue, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %15)
  br label %17

17:                                               ; preds = %11
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %1, align 4, !tbaa !5
  br label %7, !llvm.loop !9

20:                                               ; preds = %7
  br label %50

21:                                               ; preds = %0
  %22 = load i32, ptr @front, align 4, !tbaa !5
  store i32 %22, ptr %1, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %32, %21
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = icmp slt i32 %24, 5
  br i1 %25, label %26, label %35

26:                                               ; preds = %23
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [5 x i32], ptr @queue, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %30)
  br label %32

32:                                               ; preds = %26
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr %1, align 4, !tbaa !5
  br label %23, !llvm.loop !11

35:                                               ; preds = %23
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %46, %35
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = load i32, ptr @rear, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %40, label %49

40:                                               ; preds = %36
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5 x i32], ptr @queue, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %44)
  br label %46

46:                                               ; preds = %40
  %47 = load i32, ptr %1, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %1, align 4, !tbaa !5
  br label %36, !llvm.loop !12

49:                                               ; preds = %36
  br label %50

50:                                               ; preds = %49, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

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


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

@rear = external dso_local local_unnamed_addr global i32, align 4
@front = external dso_local local_unnamed_addr global i32, align 4
@queue = external dso_local local_unnamed_addr global [5 x i32], align 16
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

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

; Function Attrs: nofree nounwind uwtable
define dso_local void @display() local_unnamed_addr #1 {
  %1 = load i32, ptr @rear, align 4, !tbaa !5
  %2 = load i32, ptr @front, align 4, !tbaa !5
  %.not = icmp slt i32 %1, %2
  br i1 %.not, label %.preheader13, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %3 = sext i32 %2 to i64
  br label %.lr.ph

.preheader13:                                     ; preds = %0
  %4 = icmp slt i32 %2, 5
  br i1 %4, label %.lr.ph19.preheader, label %.preheader

.lr.ph19.preheader:                               ; preds = %.preheader13
  %5 = sext i32 %2 to i64
  br label %.lr.ph19

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %3, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %6 = getelementptr inbounds [5 x i32], ptr @queue, i64 0, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %7)
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %9 = load i32, ptr @rear, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %.not12.not = icmp slt i64 %indvars.iv, %10
  br i1 %.not12.not, label %.lr.ph, label %.loopexit, !llvm.loop !9

.preheader.loopexit:                              ; preds = %.lr.ph19
  %.pre = load i32, ptr @rear, align 4, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit, %.preheader13
  %11 = phi i32 [ %.pre, %.preheader.loopexit ], [ %1, %.preheader13 ]
  %.not1120 = icmp slt i32 %11, 0
  br i1 %.not1120, label %.loopexit, label %.lr.ph22

.lr.ph19:                                         ; preds = %.lr.ph19.preheader, %.lr.ph19
  %indvars.iv25 = phi i64 [ %5, %.lr.ph19.preheader ], [ %indvars.iv.next26, %.lr.ph19 ]
  %12 = getelementptr inbounds [5 x i32], ptr @queue, i64 0, i64 %indvars.iv25
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %13)
  %indvars.iv.next26 = add nsw i64 %indvars.iv25, 1
  %15 = and i64 %indvars.iv.next26, 4294967295
  %exitcond.not = icmp eq i64 %15, 5
  br i1 %exitcond.not, label %.preheader.loopexit, label %.lr.ph19, !llvm.loop !11

.lr.ph22:                                         ; preds = %.preheader, %.lr.ph22
  %indvars.iv28 = phi i64 [ %indvars.iv.next29, %.lr.ph22 ], [ 0, %.preheader ]
  %16 = getelementptr inbounds [5 x i32], ptr @queue, i64 0, i64 %indvars.iv28
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %17)
  %indvars.iv.next29 = add nuw nsw i64 %indvars.iv28, 1
  %19 = load i32, ptr @rear, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not11.not = icmp slt i64 %indvars.iv28, %20
  br i1 %.not11.not, label %.lr.ph22, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph, %.lr.ph22, %.preheader
  ret void
}

attributes #0 = { 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 #1 = { nofree 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass