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

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

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

; Function Attrs: nounwind uwtable
declare dso_local double @drand() #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @double_compare(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 %struct.priority_queue_t, align 8
  %3 = alloca i32, align 4
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  store i32 0, ptr %1, align 4
  %6 = call i64 @time(ptr noundef null) #4
  %7 = trunc i64 %6 to i32
  call void @srand(i32 noundef %7) #4
  call void @llvm.lifetime.start.p0(i64 64, ptr %2) #4
  %8 = call i32 @pqueue_create(ptr noundef %2, i64 noundef 8)
  %9 = call i32 @pqueue_set_compare_function(ptr noundef %2, ptr noundef @double_compare, ptr noundef null)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %18, %0
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp slt i32 %11, 10
  br i1 %12, label %13, label %21

13:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %14 = call double @drand()
  store double %14, ptr %4, align 8, !tbaa !9
  %15 = call i32 @pqueue_add(ptr noundef %2, ptr noundef %4)
  %16 = load double, ptr %4, align 8, !tbaa !9
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %16)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %10, !llvm.loop !11

21:                                               ; preds = %10
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %29, %21
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 10
  br i1 %24, label %25, label %32

25:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %26 = call i32 @pqueue_extract(ptr noundef %2, ptr noundef %5)
  %27 = load double, ptr %5, align 8, !tbaa !9
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %27)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %29

29:                                               ; preds = %25
  %30 = load i32, ptr %3, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %3, align 4, !tbaa !5
  br label %22, !llvm.loop !13

32:                                               ; preds = %22
  %33 = call i32 @pqueue_destroy(ptr noundef %2)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 64, ptr %2) #4
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #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 = { 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 = { "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !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 }

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

; Function Attrs: nounwind uwtable
declare dso_local double @drand() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @double_compare(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 %struct.priority_queue_t, align 8
  %1 = alloca double, align 8
  %2 = alloca double, align 8
  %3 = tail call i64 @time(ptr noundef null) #5
  %4 = trunc i64 %3 to i32
  tail call void @srand(i32 noundef %4) #5
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %0) #5
  %5 = call i32 @pqueue_create(ptr noundef nonnull %0, i64 noundef 8) #5
  %6 = call i32 @pqueue_set_compare_function(ptr noundef nonnull %0, ptr noundef nonnull @double_compare, ptr noundef null) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %7 = call double @drand()
  store double %7, ptr %1, align 8, !tbaa !5
  %8 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %9 = load double, ptr %1, align 8, !tbaa !5
  %10 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %9)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %11 = call double @drand()
  store double %11, ptr %1, align 8, !tbaa !5
  %12 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %13 = load double, ptr %1, align 8, !tbaa !5
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %13)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %15 = call double @drand()
  store double %15, ptr %1, align 8, !tbaa !5
  %16 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %17 = load double, ptr %1, align 8, !tbaa !5
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %17)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %19 = call double @drand()
  store double %19, ptr %1, align 8, !tbaa !5
  %20 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %21 = load double, ptr %1, align 8, !tbaa !5
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %21)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %23 = call double @drand()
  store double %23, ptr %1, align 8, !tbaa !5
  %24 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %25 = load double, ptr %1, align 8, !tbaa !5
  %26 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %25)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %27 = call double @drand()
  store double %27, ptr %1, align 8, !tbaa !5
  %28 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %29 = load double, ptr %1, align 8, !tbaa !5
  %30 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %29)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %31 = call double @drand()
  store double %31, ptr %1, align 8, !tbaa !5
  %32 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %33 = load double, ptr %1, align 8, !tbaa !5
  %34 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %33)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %35 = call double @drand()
  store double %35, ptr %1, align 8, !tbaa !5
  %36 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %37 = load double, ptr %1, align 8, !tbaa !5
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %37)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %39 = call double @drand()
  store double %39, ptr %1, align 8, !tbaa !5
  %40 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %41 = load double, ptr %1, align 8, !tbaa !5
  %42 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %43 = call double @drand()
  store double %43, ptr %1, align 8, !tbaa !5
  %44 = call i32 @pqueue_add(ptr noundef nonnull %0, ptr noundef nonnull %1) #5
  %45 = load double, ptr %1, align 8, !tbaa !5
  %46 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %45)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %47 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %48 = load double, ptr %2, align 8, !tbaa !5
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double 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 %0, ptr noundef nonnull %2) #5
  %51 = load double, ptr %2, align 8, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %51)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %53 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %54 = load double, ptr %2, align 8, !tbaa !5
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %54)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %56 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %57 = load double, ptr %2, align 8, !tbaa !5
  %58 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %57)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %59 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %60 = load double, ptr %2, align 8, !tbaa !5
  %61 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %60)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %62 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %63 = load double, ptr %2, align 8, !tbaa !5
  %64 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %63)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %65 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %66 = load double, ptr %2, align 8, !tbaa !5
  %67 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %66)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %68 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %69 = load double, ptr %2, align 8, !tbaa !5
  %70 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %69)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %71 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %72 = load double, ptr %2, align 8, !tbaa !5
  %73 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %72)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %74 = call i32 @pqueue_extract(ptr noundef nonnull %0, ptr noundef nonnull %2) #5
  %75 = load double, ptr %2, align 8, !tbaa !5
  %76 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %75)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %77 = call i32 @pqueue_destroy(ptr noundef nonnull %0) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %0) #5
  ret i32 0
}

; Function Attrs: nounwind
declare void @srand(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #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 = { 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 = { "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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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