; LLVM IR from HarshCasper/NeoAlgo :: C-Plus-Plus/ds/Double_Ended_Queue.ll (Z12delete_frontv)

; 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.dequeue = type { [10 x i32], i32, i32 }

@dq = external dso_local global %struct.dequeue, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z12delete_frontv() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  %4 = load i32, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 1), align 4, !tbaa !5
  %5 = icmp eq i32 %4, -1
  br i1 %5, label %6, label %7

6:                                                ; preds = %0
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %23

7:                                                ; preds = %0
  %8 = load i32, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 1), align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [10 x i32], ptr @dq, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %11, ptr %2, align 4, !tbaa !10
  %12 = load i32, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 1), align 4, !tbaa !5
  %13 = load i32, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 2), align 4, !tbaa !11
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %7
  store i32 -1, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 1), align 4, !tbaa !5
  store i32 -1, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 2), align 4, !tbaa !11
  br label %20

16:                                               ; preds = %7
  %17 = load i32, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 1), align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  %19 = srem i32 %18, 10
  store i32 %19, ptr getelementptr inbounds (%struct.dequeue, ptr @dq, i32 0, i32 1), align 4, !tbaa !5
  br label %20

20:                                               ; preds = %16, %15
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %2, align 4, !tbaa !10
  store i32 %22, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %23

23:                                               ; preds = %21, %6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  %24 = load i32, ptr %1, align 4
  ret i32 %24
}

; 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 = { 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 = { 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 40}
!6 = !{!"_ZTS7dequeue", !7, i64 0, !9, i64 40, !9, i64 44}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = !{!6, !9, i64 44}


; 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.dequeue = type { [10 x i32], i32, i32 }

@dq = external dso_local local_unnamed_addr global %struct.dequeue, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z12delete_frontv() local_unnamed_addr #0 {
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @dq, i64 40), align 4, !tbaa !5
  %2 = icmp eq i32 %1, -1
  br i1 %2, label %13, label %3

3:                                                ; preds = %0
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [10 x i32], ptr @dq, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !10
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @dq, i64 44), align 4, !tbaa !11
  %8 = icmp eq i32 %1, %7
  br i1 %8, label %9, label %10

9:                                                ; preds = %3
  store i32 -1, ptr getelementptr inbounds (i8, ptr @dq, i64 40), align 4, !tbaa !5
  store i32 -1, ptr getelementptr inbounds (i8, ptr @dq, i64 44), align 4, !tbaa !11
  br label %13

10:                                               ; preds = %3
  %11 = add nuw nsw i32 %1, 1
  %12 = srem i32 %11, 10
  store i32 %12, ptr getelementptr inbounds (i8, ptr @dq, i64 40), align 4, !tbaa !5
  br label %13

13:                                               ; preds = %10, %9, %0
  %.0 = phi i32 [ -1, %0 ], [ %6, %9 ], [ %6, %10 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, 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, !9, i64 40}
!6 = !{!"_ZTS7dequeue", !7, i64 0, !9, i64 40, !9, i64 44}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!9, !9, i64 0}
!11 = !{!6, !9, i64 44}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass