; LLVM IR from bartobri/data-structures-c :: FIFO-queue/array-no-dup-forget-old (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"

@q = external hidden global ptr, align 8
@N = external hidden global i32, align 4
@head = external hidden global i32, align 4
@tail = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local void @QUEUEput(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %4 = load i32, ptr @head, align 4, !tbaa !5
  store i32 %4, ptr %3, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %52, %1
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = load i32, ptr @tail, align 4, !tbaa !5
  %8 = icmp ne i32 %6, %7
  br i1 %8, label %9, label %57

9:                                                ; preds = %5
  %10 = load ptr, ptr @q, align 8, !tbaa !9
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i32, ptr %10, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %51

17:                                               ; preds = %9
  br label %18

18:                                               ; preds = %35, %17
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = load i32, ptr @tail, align 4, !tbaa !5
  %21 = icmp ne i32 %19, %20
  br i1 %21, label %22, label %40

22:                                               ; preds = %18
  %23 = load ptr, ptr @q, align 8, !tbaa !9
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = load i32, ptr @N, align 4, !tbaa !5
  %27 = srem i32 %25, %26
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds i32, ptr %23, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load ptr, ptr @q, align 8, !tbaa !9
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i32, ptr %31, i64 %33
  store i32 %30, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %22
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = load i32, ptr @N, align 4, !tbaa !5
  %39 = srem i32 %37, %38
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %18, !llvm.loop !11

40:                                               ; preds = %18
  %41 = load i32, ptr @tail, align 4, !tbaa !5
  %42 = icmp eq i32 %41, 0
  br i1 %42, label %43, label %46

43:                                               ; preds = %40
  %44 = load i32, ptr @N, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  br label %49

46:                                               ; preds = %40
  %47 = load i32, ptr @tail, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  br label %49

49:                                               ; preds = %46, %43
  %50 = phi i32 [ %45, %43 ], [ %48, %46 ]
  store i32 %50, ptr @tail, align 4, !tbaa !5
  br label %57

51:                                               ; preds = %9
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr @N, align 4, !tbaa !5
  %56 = srem i32 %54, %55
  store i32 %56, ptr %3, align 4, !tbaa !5
  br label %5, !llvm.loop !13

57:                                               ; preds = %49, %5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = load ptr, ptr @q, align 8, !tbaa !9
  %60 = load i32, ptr @tail, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr @tail, align 4, !tbaa !5
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds i32, ptr %59, i64 %62
  store i32 %58, ptr %63, align 4, !tbaa !5
  %64 = load i32, ptr @tail, align 4, !tbaa !5
  %65 = load i32, ptr @N, align 4, !tbaa !5
  %66 = srem i32 %64, %65
  store i32 %66, ptr @tail, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

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

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

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


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

@q = external hidden local_unnamed_addr global ptr, align 8
@N = external hidden local_unnamed_addr global i32, align 4
@head = external hidden local_unnamed_addr global i32, align 4
@tail = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @QUEUEput(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @head, align 4, !tbaa !5
  %3 = load i32, ptr @tail, align 4
  %.not13 = icmp eq i32 %2, %3
  %.pre = load ptr, ptr @q, align 8, !tbaa !9
  br i1 %.not13, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %4 = load i32, ptr @N, align 4
  br label %5

5:                                                ; preds = %.lr.ph, %24
  %.014 = phi i32 [ %2, %.lr.ph ], [ %26, %24 ]
  %6 = sext i32 %.014 to i64
  %7 = getelementptr inbounds i32, ptr %.pre, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %8, %0
  br i1 %9, label %.preheader, label %24

.preheader:                                       ; preds = %5
  %.not1015 = icmp eq i32 %.014, %3
  br i1 %.not1015, label %._crit_edge, label %.lr.ph17

.lr.ph17:                                         ; preds = %.preheader, %.lr.ph17
  %10 = phi i32 [ %18, %.lr.ph17 ], [ %4, %.preheader ]
  %.116 = phi i32 [ %19, %.lr.ph17 ], [ %.014, %.preheader ]
  %11 = add nsw i32 %.116, 1
  %12 = srem i32 %11, %10
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr %.pre, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = sext i32 %.116 to i64
  %17 = getelementptr inbounds i32, ptr %.pre, i64 %16
  store i32 %15, ptr %17, align 4, !tbaa !5
  %18 = load i32, ptr @N, align 4
  %19 = srem i32 %11, %18
  %20 = load i32, ptr @tail, align 4
  %.not10 = icmp eq i32 %19, %20
  br i1 %.not10, label %._crit_edge, label %.lr.ph17, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph17, %.preheader
  %21 = phi i32 [ %4, %.preheader ], [ %18, %.lr.ph17 ]
  %.lcssa = phi i32 [ %3, %.preheader ], [ %19, %.lr.ph17 ]
  %22 = icmp eq i32 %.lcssa, 0
  %.v = select i1 %22, i32 %21, i32 %.lcssa
  %23 = add nsw i32 %.v, -1
  br label %.loopexit

24:                                               ; preds = %5
  %25 = add nsw i32 %.014, 1
  %26 = srem i32 %25, %4
  %.not = icmp eq i32 %26, %3
  br i1 %.not, label %.loopexit, label %5, !llvm.loop !13

.loopexit:                                        ; preds = %24, %1, %._crit_edge
  %27 = phi i32 [ %2, %1 ], [ %23, %._crit_edge ], [ %3, %24 ]
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @tail, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds i32, ptr %.pre, i64 %29
  store i32 %0, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr @tail, align 4, !tbaa !5
  %32 = load i32, ptr @N, align 4, !tbaa !5
  %33 = srem i32 %31, %32
  store i32 %33, ptr @tail, align 4, !tbaa !5
  ret void
}

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass