; LLVM IR from qc-tum/chemtensor :: test/util (test_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.queue = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@__const.test_queue.static_data = external hidden unnamed_addr constant [6 x i32], align 16
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @test_queue() #0 {
  %1 = alloca ptr, align 8
  %2 = alloca %struct.queue, align 8
  %3 = alloca i32, align 4
  %4 = alloca [6 x i32], align 16
  %5 = alloca [6 x ptr], align 16
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %2) #6
  call void @llvm.memset.p0.i64(ptr align 8 %2, i8 0, i64 16, i1 false)
  %8 = call zeroext i1 @queue_is_empty(ptr noundef %2)
  br i1 %8, label %10, label %9

9:                                                ; preds = %0
  store ptr @.str, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %93

10:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 24, ptr %4) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %4, ptr align 16 @__const.test_queue.static_data, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 48, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %28, %10
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 6
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %31

15:                                               ; preds = %11
  %16 = call ptr @ct_malloc(i64 noundef 4)
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 %18
  store ptr %16, ptr %19, align 8, !tbaa !9
  %20 = load i32, ptr %6, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [6 x i32], ptr %4, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 %25
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  store i32 %23, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %15
  %29 = load i32, ptr %6, align 4, !tbaa !5
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %6, align 4, !tbaa !5
  br label %11, !llvm.loop !11

31:                                               ; preds = %14
  %32 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 0
  %33 = load ptr, ptr %32, align 16, !tbaa !9
  call void @enqueue(ptr noundef %2, ptr noundef %33)
  %34 = call zeroext i1 @queue_is_empty(ptr noundef %2)
  br i1 %34, label %35, label %36

35:                                               ; preds = %31
  store ptr @.str.1, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %92

36:                                               ; preds = %31
  %37 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 1
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  call void @enqueue(ptr noundef %2, ptr noundef %38)
  %39 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 2
  %40 = load ptr, ptr %39, align 16, !tbaa !9
  call void @enqueue(ptr noundef %2, ptr noundef %40)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %41 = call ptr @dequeue(ptr noundef %2)
  store ptr %41, ptr %7, align 8, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !9
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = getelementptr inbounds [6 x i32], ptr %4, i64 0, i64 0
  %45 = load i32, ptr %44, align 16, !tbaa !5
  %46 = icmp ne i32 %43, %45
  br i1 %46, label %47, label %48

47:                                               ; preds = %36
  store ptr @.str.2, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %91

48:                                               ; preds = %36
  %49 = load ptr, ptr %7, align 8, !tbaa !9
  call void @ct_free(ptr noundef %49)
  %50 = call ptr @peek_queue(ptr noundef %2)
  store ptr %50, ptr %7, align 8, !tbaa !9
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = getelementptr inbounds [6 x i32], ptr %4, i64 0, i64 1
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = icmp ne i32 %52, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %48
  store ptr @.str.3, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %91

57:                                               ; preds = %48
  %58 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 3
  %59 = load ptr, ptr %58, align 8, !tbaa !9
  call void @enqueue(ptr noundef %2, ptr noundef %59)
  %60 = call ptr @dequeue(ptr noundef %2)
  store ptr %60, ptr %7, align 8, !tbaa !9
  %61 = load ptr, ptr %7, align 8, !tbaa !9
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = getelementptr inbounds [6 x i32], ptr %4, i64 0, i64 1
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = icmp ne i32 %62, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %57
  store ptr @.str.2, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %91

67:                                               ; preds = %57
  %68 = load ptr, ptr %7, align 8, !tbaa !9
  call void @ct_free(ptr noundef %68)
  br label %69

69:                                               ; preds = %73, %67
  %70 = getelementptr inbounds %struct.queue, ptr %2, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = icmp ne ptr %71, null
  br i1 %72, label %73, label %75

73:                                               ; preds = %69
  %74 = call ptr @dequeue(ptr noundef %2)
  call void @ct_free(ptr noundef %74)
  br label %69, !llvm.loop !15

75:                                               ; preds = %69
  %76 = call zeroext i1 @queue_is_empty(ptr noundef %2)
  br i1 %76, label %78, label %77

77:                                               ; preds = %75
  store ptr @.str, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %91

78:                                               ; preds = %75
  %79 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 4
  %80 = load ptr, ptr %79, align 16, !tbaa !9
  call void @enqueue(ptr noundef %2, ptr noundef %80)
  %81 = getelementptr inbounds [6 x ptr], ptr %5, i64 0, i64 5
  %82 = load ptr, ptr %81, align 8, !tbaa !9
  call void @enqueue(ptr noundef %2, ptr noundef %82)
  %83 = call ptr @peek_queue(ptr noundef %2)
  store ptr %83, ptr %7, align 8, !tbaa !9
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = getelementptr inbounds [6 x i32], ptr %4, i64 0, i64 4
  %87 = load i32, ptr %86, align 16, !tbaa !5
  %88 = icmp ne i32 %85, %87
  br i1 %88, label %89, label %90

89:                                               ; preds = %78
  store ptr @.str.3, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %91

90:                                               ; preds = %78
  call void @free_queue(ptr noundef %2, ptr noundef @ct_free)
  store ptr null, ptr %1, align 8
  store i32 1, ptr %3, align 4
  br label %91

91:                                               ; preds = %90, %89, %77, %66, %56, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %92

92:                                               ; preds = %91, %35
  call void @llvm.lifetime.end.p0(i64 48, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 24, ptr %4) #6
  br label %93

93:                                               ; preds = %92, %9
  call void @llvm.lifetime.end.p0(i64 16, ptr %2) #6
  %94 = load ptr, ptr %1, align 8
  ret ptr %94
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare zeroext i1 @queue_is_empty(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ct_malloc(i64 noundef) #5

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

declare void @enqueue(ptr noundef, ptr noundef) #3

declare ptr @dequeue(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @ct_free(ptr noundef) #5

declare ptr @peek_queue(ptr noundef) #3

declare void @free_queue(ptr noundef, ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { inlinehint 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 #6 = { 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 = !{!14, !10, i64 0}
!14 = !{!"queue", !10, i64 0, !10, i64 8}
!15 = distinct !{!15, !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"

%struct.queue = type { ptr, ptr }

@.str = external hidden unnamed_addr constant [22 x i8], align 1
@__const.test_queue.static_data = external hidden unnamed_addr constant [6 x i32], align 16
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [43 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [50 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @test_queue() local_unnamed_addr #0 {
  %1 = alloca %struct.queue, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %1, i8 0, i64 16, i1 false)
  %2 = call zeroext i1 @queue_is_empty(ptr noundef nonnull %1) #5
  br i1 %2, label %3, label %35

3:                                                ; preds = %0
  %4 = call ptr @ct_malloc(i64 noundef 4)
  %5 = load i32, ptr @__const.test_queue.static_data, align 16, !tbaa !5
  store i32 %5, ptr %4, align 4, !tbaa !5
  %6 = call ptr @ct_malloc(i64 noundef 4)
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_queue.static_data, i64 4), align 4, !tbaa !5
  store i32 %7, ptr %6, align 4, !tbaa !5
  %8 = call ptr @ct_malloc(i64 noundef 4)
  %9 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_queue.static_data, i64 8), align 8, !tbaa !5
  store i32 %9, ptr %8, align 4, !tbaa !5
  %10 = call ptr @ct_malloc(i64 noundef 4)
  %11 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_queue.static_data, i64 12), align 4, !tbaa !5
  store i32 %11, ptr %10, align 4, !tbaa !5
  %12 = call ptr @ct_malloc(i64 noundef 4)
  %13 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_queue.static_data, i64 16), align 16, !tbaa !5
  store i32 %13, ptr %12, align 4, !tbaa !5
  %14 = call ptr @ct_malloc(i64 noundef 4)
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @__const.test_queue.static_data, i64 20), align 4, !tbaa !5
  store i32 %15, ptr %14, align 4, !tbaa !5
  call void @enqueue(ptr noundef nonnull %1, ptr noundef nonnull %4) #5
  %16 = call zeroext i1 @queue_is_empty(ptr noundef nonnull %1) #5
  br i1 %16, label %35, label %17

17:                                               ; preds = %3
  call void @enqueue(ptr noundef nonnull %1, ptr noundef nonnull %6) #5
  call void @enqueue(ptr noundef nonnull %1, ptr noundef nonnull %8) #5
  %18 = call ptr @dequeue(ptr noundef nonnull %1) #5
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not = icmp eq i32 %19, %5
  br i1 %.not, label %20, label %35

20:                                               ; preds = %17
  call void @ct_free(ptr noundef nonnull %18)
  %21 = call ptr @peek_queue(ptr noundef nonnull %1) #5
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %.not12 = icmp eq i32 %22, %7
  br i1 %.not12, label %23, label %35

23:                                               ; preds = %20
  call void @enqueue(ptr noundef nonnull %1, ptr noundef nonnull %10) #5
  %24 = call ptr @dequeue(ptr noundef nonnull %1) #5
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %.not13 = icmp eq i32 %25, %7
  br i1 %.not13, label %26, label %35

26:                                               ; preds = %23
  call void @ct_free(ptr noundef nonnull %24)
  %27 = load ptr, ptr %1, align 8, !tbaa !9
  %.not1417 = icmp eq ptr %27, null
  br i1 %.not1417, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %26, %.lr.ph
  %28 = call ptr @dequeue(ptr noundef nonnull %1) #5
  call void @ct_free(ptr noundef %28)
  %29 = load ptr, ptr %1, align 8, !tbaa !9
  %.not14 = icmp eq ptr %29, null
  br i1 %.not14, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %26
  %30 = call zeroext i1 @queue_is_empty(ptr noundef nonnull %1) #5
  br i1 %30, label %31, label %35

31:                                               ; preds = %._crit_edge
  call void @enqueue(ptr noundef nonnull %1, ptr noundef nonnull %12) #5
  call void @enqueue(ptr noundef nonnull %1, ptr noundef nonnull %14) #5
  %32 = call ptr @peek_queue(ptr noundef nonnull %1) #5
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %.not15 = icmp eq i32 %33, %13
  br i1 %.not15, label %34, label %35

34:                                               ; preds = %31
  call void @free_queue(ptr noundef nonnull %1, ptr noundef nonnull @ct_free) #5
  br label %35

35:                                               ; preds = %3, %31, %._crit_edge, %23, %20, %17, %34, %0
  %.2 = phi ptr [ @.str, %0 ], [ @.str.1, %3 ], [ null, %34 ], [ @.str.2, %17 ], [ @.str.3, %20 ], [ @.str.2, %23 ], [ @.str, %._crit_edge ], [ @.str.3, %31 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #5
  ret ptr %.2
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare zeroext i1 @queue_is_empty(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @ct_malloc(i64 noundef) local_unnamed_addr #4

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

declare void @enqueue(ptr noundef, ptr noundef) local_unnamed_addr #3

declare ptr @dequeue(ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @ct_free(ptr noundef) #4

declare ptr @peek_queue(ptr noundef) local_unnamed_addr #3

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


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