; LLVM IR from yudi-matsuzake/libgenerics :: doc/examples (pqueue2)

; 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.priority_queue_t = type { i64, i64, ptr, ptr, %struct.vector_t }
%struct.vector_t = type { ptr, i64, i64, i64 }

@__const.main.str = external hidden unnamed_addr constant [7 x ptr], align 16
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @priority_string(ptr noundef, ptr 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 i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca [7 x ptr], align 16
  %3 = alloca i64, align 8
  %4 = alloca %struct.priority_queue_t, align 8
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 56, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %2, ptr align 16 @__const.main.str, i64 56, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store i64 7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 64, ptr %4) #4
  %7 = call i32 @pqueue_create(ptr noundef %4, i64 noundef 8)
  %8 = call i32 @pqueue_set_compare_function(ptr noundef %4, ptr noundef @priority_string, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %21, %0
  %10 = load i64, ptr %5, align 8, !tbaa !5
  %11 = load i64, ptr %3, align 8, !tbaa !5
  %12 = icmp ult i64 %10, %11
  br i1 %12, label %13, label %24

13:                                               ; preds = %9
  %14 = load i64, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds [7 x ptr], ptr %2, i64 0, i64 %14
  %16 = call i32 @pqueue_add(ptr noundef %4, ptr noundef %15)
  %17 = load i64, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds [7 x ptr], ptr %2, i64 0, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.7, ptr noundef %19)
  br label %21

21:                                               ; preds = %13
  %22 = load i64, ptr %5, align 8, !tbaa !5
  %23 = add i64 %22, 1
  store i64 %23, ptr %5, align 8, !tbaa !5
  br label %9, !llvm.loop !11

24:                                               ; preds = %9
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %33, %24
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %29, label %36

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %30 = call i32 @pqueue_extract(ptr noundef %4, ptr noundef %6)
  %31 = load ptr, ptr %6, align 8, !tbaa !9
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.8, ptr noundef %31)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %33

33:                                               ; preds = %29
  %34 = load i64, ptr %5, align 8, !tbaa !5
  %35 = add i64 %34, 1
  store i64 %35, ptr %5, align 8, !tbaa !5
  br label %25, !llvm.loop !13

36:                                               ; preds = %25
  %37 = call i32 @pqueue_destroy(ptr noundef %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 56, ptr %2) #4
  ret i32 0
}

; 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) #2

declare i32 @pqueue_create(ptr noundef, i64 noundef) #3

declare i32 @pqueue_set_compare_function(ptr noundef, ptr noundef, ptr noundef) #3

declare i32 @pqueue_add(ptr noundef, ptr noundef) #3

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

declare i32 @pqueue_extract(ptr noundef, ptr noundef) #3

declare i32 @pqueue_destroy(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: readwrite) }
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 = { 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 = !{!"long", !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 = distinct !{!13, !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.priority_queue_t = type { i64, i64, ptr, ptr, %struct.vector_t }
%struct.vector_t = type { ptr, i64, i64, i64 }

@__const.main.str = external hidden unnamed_addr constant [7 x ptr], align 16
@.str.7 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [15 x i8], align 1

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
.preheader.preheader:
  %0 = alloca [7 x ptr], align 16
  %1 = alloca %struct.priority_queue_t, align 8
  %2 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 56, ptr nonnull %0) #5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(56) %0, ptr noundef nonnull align 16 dereferenceable(56) @__const.main.str, i64 56, i1 false)
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #5
  %3 = call i32 @pqueue_create(ptr noundef nonnull %1, i64 noundef 8) #5
  %4 = call i32 @pqueue_set_compare_function(ptr noundef nonnull %1, ptr noundef nonnull @priority_string, ptr noundef null) #5
  %5 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %0) #5
  %6 = load ptr, ptr %0, align 16, !tbaa !5
  %7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %6)
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %8) #5
  %10 = load ptr, ptr %8, align 8, !tbaa !5
  %11 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %10)
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %12) #5
  %14 = load ptr, ptr %12, align 16, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %14)
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %16) #5
  %18 = load ptr, ptr %16, align 8, !tbaa !5
  %19 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %18)
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  %21 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %20) #5
  %22 = load ptr, ptr %20, align 16, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %22)
  %24 = getelementptr inbounds i8, ptr %0, i64 40
  %25 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %24) #5
  %26 = load ptr, ptr %24, align 8, !tbaa !5
  %27 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %26)
  %28 = getelementptr inbounds i8, ptr %0, i64 48
  %29 = call i32 @pqueue_add(ptr noundef nonnull %1, ptr noundef nonnull %28) #5
  %30 = load ptr, ptr %28, align 16, !tbaa !5
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.7, ptr noundef %30)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %32 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %35 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %36)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %38 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %39)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %41 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %42)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %44 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %47 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %48)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %50 = call i32 @pqueue_extract(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.8, ptr noundef %51)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %53 = call i32 @pqueue_destroy(ptr noundef nonnull %1) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #5
  call void @llvm.lifetime.end.p0(i64 56, ptr nonnull %0) #5
  ret i32 0
}

; Function Attrs: mustprogress 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) #2

declare i32 @pqueue_create(ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @pqueue_set_compare_function(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @pqueue_add(ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @pqueue_extract(ptr noundef, ptr noundef) local_unnamed_addr #3

declare i32 @pqueue_destroy(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: readwrite) }
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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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