; LLVM IR from bartobri/data-structures-c :: FIFO-queue/linked-list-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"

%struct.QUEUEnode = type { i32, ptr }

@head = external hidden global ptr, align 8
@tail = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local ptr @NEW(i32 noundef, ptr 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

9:                                                ; preds = %1
  %10 = load ptr, ptr %4, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.QUEUEnode, ptr %10, i32 0, i32 0
  %12 = load i32, ptr %11, align 8, !tbaa !11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %9
  %16 = load ptr, ptr %4, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.QUEUEnode, ptr %16, i32 0, i32 1
  %18 = load ptr, ptr %17, align 8, !tbaa !13
  store ptr %18, ptr @head, align 8, !tbaa !9
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  call void @free(ptr noundef %19) #3
  br label %51

20:                                               ; preds = %9
  br label %21

21:                                               ; preds = %46, %20
  %22 = load ptr, ptr %4, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.QUEUEnode, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %50

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.QUEUEnode, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.QUEUEnode, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = icmp eq i32 %31, %32
  br i1 %33, label %34, label %46

34:                                               ; preds = %26
  %35 = load ptr, ptr %4, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.QUEUEnode, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !13
  store ptr %37, ptr %3, align 8, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.QUEUEnode, ptr %38, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !13
  %41 = getelementptr inbounds %struct.QUEUEnode, ptr %40, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %4, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.QUEUEnode, ptr %43, i32 0, i32 1
  store ptr %42, ptr %44, align 8, !tbaa !13
  %45 = load ptr, ptr %3, align 8, !tbaa !9
  call void @free(ptr noundef %45) #3
  br label %50

46:                                               ; preds = %26
  %47 = load ptr, ptr %4, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.QUEUEnode, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !13
  store ptr %49, ptr %4, align 8, !tbaa !9
  br label %21, !llvm.loop !14

50:                                               ; preds = %34, %21
  br label %51

51:                                               ; preds = %50, %15
  br label %52

52:                                               ; preds = %51, %1
  %53 = load ptr, ptr @head, align 8, !tbaa !9
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %59

55:                                               ; preds = %52
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = load ptr, ptr @head, align 8, !tbaa !9
  %58 = call ptr @NEW(i32 noundef %56, ptr noundef %57)
  store ptr %58, ptr @tail, align 8, !tbaa !9
  store ptr %58, ptr @head, align 8, !tbaa !9
  store i32 1, ptr %5, align 4
  br label %70

59:                                               ; preds = %52
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = load ptr, ptr @tail, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.QUEUEnode, ptr %61, i32 0, i32 1
  %63 = load ptr, ptr %62, align 8, !tbaa !13
  %64 = call ptr @NEW(i32 noundef %60, ptr noundef %63)
  %65 = load ptr, ptr @tail, align 8, !tbaa !9
  %66 = getelementptr inbounds %struct.QUEUEnode, ptr %65, i32 0, i32 1
  store ptr %64, ptr %66, align 8, !tbaa !13
  %67 = load ptr, ptr @tail, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.QUEUEnode, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !13
  store ptr %69, ptr @tail, align 8, !tbaa !9
  store i32 0, ptr %5, align 4
  br label %70

70:                                               ; preds = %59, %55
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %71 = load i32, ptr %5, align 4
  switch i32 %71, label %73 [
    i32 0, label %72
    i32 1, label %72
  ]

72:                                               ; preds = %70, %70
  ret void

73:                                               ; preds = %70
  unreachable
}

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

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

!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 = !{!12, !6, i64 0}
!12 = !{!"QUEUEnode", !6, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@head = external hidden local_unnamed_addr global ptr, align 8
@tail = external hidden local_unnamed_addr global ptr, align 8

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

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

3:                                                ; preds = %1
  %4 = load i32, ptr %2, align 8, !tbaa !9
  %5 = icmp eq i32 %4, %0
  br i1 %5, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %3, %8
  %.0 = phi ptr [ %7, %8 ], [ %2, %3 ]
  %6 = getelementptr inbounds i8, ptr %.0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %.not17 = icmp eq ptr %7, null
  br i1 %.not17, label %.loopexit, label %8

8:                                                ; preds = %.preheader
  %9 = load i32, ptr %7, align 8, !tbaa !9
  %10 = icmp eq i32 %9, %0
  br i1 %10, label %11, label %.preheader, !llvm.loop !13

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %.0, i64 8
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %3, %11
  %.sink28 = phi ptr [ %7, %11 ], [ %2, %3 ]
  %head.sink = phi ptr [ %12, %11 ], [ @head, %3 ]
  %13 = getelementptr inbounds i8, ptr %.sink28, i64 8
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  store ptr %14, ptr %head.sink, align 8, !tbaa !5
  tail call void @free(ptr noundef nonnull %.sink28) #2
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %.loopexit.sink.split
  %.pr = load ptr, ptr @head, align 8, !tbaa !5
  %15 = icmp eq ptr %.pr, null
  br i1 %15, label %.thread, label %17

.thread:                                          ; preds = %1, %.loopexit
  %16 = tail call ptr @NEW(i32 noundef %0, ptr noundef null)
  store ptr %16, ptr @tail, align 8, !tbaa !5
  store ptr %16, ptr @head, align 8, !tbaa !5
  br label %24

17:                                               ; preds = %.loopexit
  %18 = load ptr, ptr @tail, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %18, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = tail call ptr @NEW(i32 noundef %0, ptr noundef %20)
  %22 = load ptr, ptr @tail, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  store ptr %21, ptr %23, align 8, !tbaa !12
  store ptr %21, ptr @tail, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %17, %.thread
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"QUEUEnode", !11, i64 0, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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