; 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.Queue = type { ptr, ptr, i32, i32 }
%struct.Node_t = type { %struct.DATA, ptr }
%struct.DATA = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @Enqueue(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %8, %2
  store i32 0, ptr %3, align 4
  br label %49

12:                                               ; preds = %8
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Queue, ptr %13, i32 0, i32 2
  %15 = load i32, ptr %14, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.Queue, ptr %16, i32 0, i32 3
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = icmp sge i32 %15, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %12
  store i32 0, ptr %3, align 4
  br label %49

21:                                               ; preds = %12
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Node_t, ptr %22, i32 0, i32 1
  store ptr null, ptr %23, align 8, !tbaa !13
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Queue, ptr %24, i32 0, i32 2
  %26 = load i32, ptr %25, align 8, !tbaa !9
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %21
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Queue, ptr %30, i32 0, i32 0
  store ptr %29, ptr %31, align 8, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Queue, ptr %33, i32 0, i32 1
  store ptr %32, ptr %34, align 8, !tbaa !17
  br label %44

35:                                               ; preds = %21
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.Queue, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds %struct.Node_t, ptr %39, i32 0, i32 1
  store ptr %36, ptr %40, align 8, !tbaa !13
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Queue, ptr %42, i32 0, i32 1
  store ptr %41, ptr %43, align 8, !tbaa !17
  br label %44

44:                                               ; preds = %35, %28
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.Queue, ptr %45, i32 0, i32 2
  %47 = load i32, ptr %46, align 8, !tbaa !9
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %46, align 8, !tbaa !9
  store i32 1, ptr %3, align 4
  br label %49

49:                                               ; preds = %44, %20, %11
  %50 = load i32, ptr %3, align 4
  ret i32 %50
}

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

!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 16}
!10 = !{!"Queue", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 20}
!13 = !{!14, !6, i64 8}
!14 = !{!"Node_t", !15, i64 0, !6, i64 8}
!15 = !{!"", !11, i64 0}
!16 = !{!10, !6, i64 0}
!17 = !{!10, !6, i64 8}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @Enqueue(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %21, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 20
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %.not = icmp slt i32 %7, %9
  br i1 %.not, label %10, label %21

10:                                               ; preds = %5
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  store ptr null, ptr %11, align 8, !tbaa !12
  %12 = icmp eq i32 %7, 0
  br i1 %12, label %13, label %15

13:                                               ; preds = %10
  store ptr %1, ptr %0, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  br label %19

15:                                               ; preds = %10
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  store ptr %1, ptr %18, align 8, !tbaa !12
  br label %19

19:                                               ; preds = %15, %13
  %.sink = phi ptr [ %16, %15 ], [ %14, %13 ]
  store ptr %1, ptr %.sink, align 8, !tbaa !16
  %20 = add nsw i32 %7, 1
  store i32 %20, ptr %6, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %5, %2, %19
  %.0 = phi i32 [ 1, %19 ], [ 0, %2 ], [ 0, %5 ]
  ret i32 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, 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, !10, i64 16}
!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 20}
!12 = !{!13, !7, i64 8}
!13 = !{!"Node_t", !14, i64 0, !7, i64 8}
!14 = !{!"", !10, i64 0}
!15 = !{!6, !7, i64 0}
!16 = !{!6, !7, i64 8}


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