; LLVM IR from VAR-solutions/Algorithms :: data structures/queue/c (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.Node_t = type { %struct.DATA, ptr }
%struct.DATA = type { i32 }

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @ConstructQueue(i32 noundef) #0

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare dso_local void @DestructQueue(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @isEmpty(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @Dequeue(ptr noundef) #0

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @Enqueue(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %5 = call ptr @ConstructQueue(i32 noundef 7)
  store ptr %5, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %6

6:                                                ; preds = %19, %0
  %7 = load i32, ptr %2, align 4, !tbaa !9
  %8 = icmp slt i32 %7, 9
  br i1 %8, label %9, label %22

9:                                                ; preds = %6
  %10 = call noalias ptr @malloc(i64 noundef 16) #6
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load i32, ptr %2, align 4, !tbaa !9
  %12 = add nsw i32 100, %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Node_t, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.DATA, ptr %14, i32 0, i32 0
  store i32 %12, ptr %15, align 8, !tbaa !11
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call i32 @Enqueue(ptr noundef %16, ptr noundef %17)
  br label %19

19:                                               ; preds = %9
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !9
  br label %6, !llvm.loop !14

22:                                               ; preds = %6
  br label %23

23:                                               ; preds = %28, %22
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = call i32 @isEmpty(ptr noundef %24)
  %26 = icmp ne i32 %25, 0
  %27 = xor i1 %26, true
  br i1 %27, label %28, label %37

28:                                               ; preds = %23
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call ptr @Dequeue(ptr noundef %29)
  store ptr %30, ptr %4, align 8, !tbaa !5
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Node_t, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.DATA, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 %34)
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %36) #5
  br label %23, !llvm.loop !16

37:                                               ; preds = %23
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  call void @DestructQueue(ptr noundef %38)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

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

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 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 #3 = { 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 = { "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) }

!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, !10, i64 0}
!12 = !{!"Node_t", !13, i64 0, !6, i64 8}
!13 = !{!"", !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 [14 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @DestructQueue(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @Dequeue(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @Enqueue(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader:
  %0 = tail call ptr @ConstructQueue(i32 noundef 7)
  %1 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 100, ptr %1, align 8, !tbaa !5
  %2 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %1)
  %3 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 101, ptr %3, align 8, !tbaa !5
  %4 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %3)
  %5 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 102, ptr %5, align 8, !tbaa !5
  %6 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %5)
  %7 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 103, ptr %7, align 8, !tbaa !5
  %8 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %7)
  %9 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 104, ptr %9, align 8, !tbaa !5
  %10 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %9)
  %11 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 105, ptr %11, align 8, !tbaa !5
  %12 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %11)
  %13 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 106, ptr %13, align 8, !tbaa !5
  %14 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %13)
  %15 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 107, ptr %15, align 8, !tbaa !5
  %16 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %15)
  %17 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #4
  store i32 108, ptr %17, align 8, !tbaa !5
  %18 = tail call i32 @Enqueue(ptr noundef %0, ptr noundef nonnull %17)
  %19 = tail call i32 @isEmpty(ptr noundef %0)
  %.not11 = icmp eq i32 %19, 0
  br i1 %.not11, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %20 = tail call ptr @Dequeue(ptr noundef %0)
  %21 = load i32, ptr %20, align 8
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 %21)
  tail call void @free(ptr noundef %20) #5
  %23 = tail call i32 @isEmpty(ptr noundef %0)
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  tail call void @DestructQueue(ptr noundef %0)
  ret i32 0
}

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

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


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