; LLVM IR from HarshCasper/NeoAlgo :: C/ds (QueueImplementationWithList)

; 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 { ptr, ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [13 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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 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 @enqueue(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.Queue, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp ne ptr %11, null
  br i1 %12, label %31, label %13

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %14 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %14, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @perror(ptr noundef @.str)
  call void @exit(i32 noundef -1) #7
  unreachable

18:                                               ; preds = %13
  %19 = load i32, ptr %4, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Queue, ptr %20, i32 0, i32 2
  store i32 %19, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Queue, ptr %22, i32 0, i32 1
  store ptr null, ptr %23, align 8, !tbaa !14
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Queue, ptr %25, i32 0, i32 0
  store ptr %24, ptr %26, align 8, !tbaa !11
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.Queue, ptr %27, i32 0, i32 3
  %29 = load i32, ptr %28, align 4, !tbaa !15
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %28, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %58

31:                                               ; preds = %2
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.Queue, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  store ptr %34, ptr %5, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %40, %31
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Queue, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %44

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.Queue, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !14
  store ptr %43, ptr %5, align 8, !tbaa !5
  br label %35, !llvm.loop !16

44:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %45 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %45, ptr %7, align 8, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !9
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Queue, ptr %47, i32 0, i32 2
  store i32 %46, ptr %48, align 8, !tbaa !13
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Queue, ptr %49, i32 0, i32 1
  store ptr null, ptr %50, align 8, !tbaa !14
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Queue, ptr %52, i32 0, i32 1
  store ptr %51, ptr %53, align 8, !tbaa !14
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Queue, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !15
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %55, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  br label %58

58:                                               ; preds = %44, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret void
}

declare void @perror(ptr noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 #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 = { "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 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"Queue", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 20}
!16 = distinct !{!16, !17}
!17 = !{!"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"

@.str = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @enqueue(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %4, label %.preheader

4:                                                ; preds = %2
  %5 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #4
  %.not20 = icmp eq ptr %5, null
  br i1 %.not20, label %6, label %7

6:                                                ; preds = %4
  tail call void @perror(ptr noundef nonnull @.str) #5
  tail call void @exit(i32 noundef -1) #6
  unreachable

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %5, i64 16
  store i32 %1, ptr %8, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr null, ptr %9, align 8, !tbaa !12
  store ptr %5, ptr %0, align 8, !tbaa !5
  br label %17

.preheader:                                       ; preds = %2, %.preheader
  %.0 = phi ptr [ %11, %.preheader ], [ %3, %2 ]
  %10 = getelementptr inbounds i8, ptr %.0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %.not21 = icmp eq ptr %11, null
  br i1 %.not21, label %12, label %.preheader, !llvm.loop !13

12:                                               ; preds = %.preheader
  %13 = getelementptr inbounds i8, ptr %.0, i64 8
  %14 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #4
  %15 = getelementptr inbounds i8, ptr %14, i64 16
  store i32 %1, ptr %15, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %14, i64 8
  store ptr null, ptr %16, align 8, !tbaa !12
  store ptr %14, ptr %13, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %12, %7
  %18 = getelementptr inbounds i8, ptr %0, i64 20
  %19 = load i32, ptr %18, align 4, !tbaa !15
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !15
  ret void
}

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 #2 = { 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 #3 = { 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 #4 = { nounwind allocsize(0) }
attributes #5 = { cold }
attributes #6 = { 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, !7, i64 0}
!6 = !{!"Queue", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !7, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 20}


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