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

; 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_t = type { i64, i64, ptr, ptr }
%struct.cord = type { i32, i32 }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %struct.queue_t, align 8
  %4 = alloca %struct.queue_t, align 8
  %5 = alloca %struct.queue_t, align 8
  %6 = alloca double, align 8
  %7 = alloca %struct.cord, align 4
  %8 = alloca i32, align 4
  %9 = alloca double, align 8
  %10 = alloca %struct.cord, align 4
  store i32 0, ptr %1, align 4
  %11 = call i64 @time(ptr noundef null) #4
  %12 = trunc i64 %11 to i32
  call void @srand(i32 noundef %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #4
  %13 = call i32 @queue_create(ptr noundef %3, i64 noundef 4)
  %14 = call i32 @queue_create(ptr noundef %4, i64 noundef 8)
  %15 = call i32 @queue_create(ptr noundef %5, i64 noundef 8)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %48, %0
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 10
  br i1 %18, label %19, label %51

19:                                               ; preds = %16
  %20 = getelementptr inbounds %struct.queue_t, ptr %3, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %21, i32 noundef %22)
  %24 = call i32 @queue_enqueue(ptr noundef %3, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = sitofp i32 %26 to double
  %28 = fdiv double 1.000000e+00, %27
  store double %28, ptr %6, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.queue_t, ptr %4, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load double, ptr %6, align 8, !tbaa !13
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %30, double noundef %31)
  %33 = call i32 @queue_enqueue(ptr noundef %4, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %34 = getelementptr inbounds %struct.cord, ptr %7, i32 0, i32 0
  %35 = call i32 @rand() #4
  %36 = srem i32 %35, 10
  store i32 %36, ptr %34, align 4, !tbaa !15
  %37 = getelementptr inbounds %struct.cord, ptr %7, i32 0, i32 1
  %38 = call i32 @rand() #4
  %39 = srem i32 %38, 10
  store i32 %39, ptr %37, align 4, !tbaa !17
  %40 = getelementptr inbounds %struct.queue_t, ptr %5, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.cord, ptr %7, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !15
  %44 = getelementptr inbounds %struct.cord, ptr %7, i32 0, i32 1
  %45 = load i32, ptr %44, align 4, !tbaa !17
  %46 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %41, i32 noundef %43, i32 noundef %45)
  %47 = call i32 @queue_enqueue(ptr noundef %5, ptr noundef %7)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %48

48:                                               ; preds = %19
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !18

51:                                               ; preds = %16
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %69, %51
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = icmp slt i32 %54, 5
  br i1 %55, label %56, label %72

56:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %57 = call i32 @queue_dequeue(ptr noundef %3, ptr noundef %8)
  %58 = load i32, ptr %8, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %58)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %60 = call i32 @queue_dequeue(ptr noundef %4, ptr noundef %9)
  %61 = load double, ptr %9, align 8, !tbaa !13
  %62 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, double noundef %61)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %63 = call i32 @queue_dequeue(ptr noundef %5, ptr noundef %10)
  %64 = getelementptr inbounds %struct.cord, ptr %10, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !15
  %66 = getelementptr inbounds %struct.cord, ptr %10, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !17
  %68 = call i32 (ptr, ...) @printf(ptr noundef @.str.6, i32 noundef %65, i32 noundef %67)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %69

69:                                               ; preds = %56
  %70 = load i32, ptr %2, align 4, !tbaa !5
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %2, align 4, !tbaa !5
  br label %53, !llvm.loop !20

72:                                               ; preds = %53
  %73 = call i32 @queue_destroy(ptr noundef %3)
  %74 = call i32 @queue_destroy(ptr noundef %4)
  %75 = call i32 @queue_destroy(ptr noundef %5)
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  ret i32 0
}

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

; Function Attrs: nounwind
declare i64 @time(ptr noundef) #1

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

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

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

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

; Function Attrs: nounwind
declare i32 @rand() #1

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

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

declare i32 @queue_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 = { 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 #2 = { nocallback nofree nosync 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"queue_t", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"cord", !6, i64 0, !6, i64 4}
!17 = !{!16, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; 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_t = type { i64, i64, ptr, ptr }
%struct.cord = type { i32, i32 }

@.str = external hidden unnamed_addr constant [20 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [22 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.queue_t, align 8
  %3 = alloca %struct.queue_t, align 8
  %4 = alloca %struct.queue_t, align 8
  %5 = alloca double, align 8
  %6 = alloca %struct.cord, align 4
  %7 = alloca i32, align 4
  %8 = alloca double, align 8
  %9 = alloca %struct.cord, align 4
  %10 = tail call i64 @time(ptr noundef null) #5
  %11 = trunc i64 %10 to i32
  tail call void @srand(i32 noundef %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #5
  %12 = call i32 @queue_create(ptr noundef nonnull %2, i64 noundef 4) #5
  %13 = call i32 @queue_create(ptr noundef nonnull %3, i64 noundef 8) #5
  %14 = call i32 @queue_create(ptr noundef nonnull %4, i64 noundef 8) #5
  store i32 0, ptr %1, align 4, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %6, i64 4
  br label %16

16:                                               ; preds = %0, %16
  %storemerge2 = phi i32 [ 0, %0 ], [ %36, %16 ]
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %17, i32 noundef %storemerge2)
  %19 = call i32 @queue_enqueue(ptr noundef nonnull %2, ptr noundef nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  %22 = sitofp i32 %21 to double
  %23 = fdiv double 1.000000e+00, %22
  store double %23, ptr %5, align 8, !tbaa !13
  %24 = load i64, ptr %3, align 8, !tbaa !9
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %24, double noundef %23)
  %26 = call i32 @queue_enqueue(ptr noundef nonnull %3, ptr noundef nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %27 = call i32 @rand() #5
  %28 = srem i32 %27, 10
  store i32 %28, ptr %6, align 4, !tbaa !15
  %29 = call i32 @rand() #5
  %30 = srem i32 %29, 10
  store i32 %30, ptr %15, align 4, !tbaa !17
  %31 = load i64, ptr %4, align 8, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !15
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %31, i32 noundef %32, i32 noundef %30)
  %34 = call i32 @queue_enqueue(ptr noundef nonnull %4, ptr noundef nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  %35 = load i32, ptr %1, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %1, align 4, !tbaa !5
  %37 = icmp slt i32 %35, 9
  br i1 %37, label %16, label %38, !llvm.loop !18

38:                                               ; preds = %16
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  store i32 0, ptr %1, align 4, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %9, i64 4
  br label %41

41:                                               ; preds = %38, %41
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #5
  %42 = call i32 @queue_dequeue(ptr noundef nonnull %2, ptr noundef nonnull %7) #5
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %43)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #5
  %45 = call i32 @queue_dequeue(ptr noundef nonnull %3, ptr noundef nonnull %8) #5
  %46 = load double, ptr %8, align 8, !tbaa !13
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, double noundef %46)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #5
  %48 = call i32 @queue_dequeue(ptr noundef nonnull %4, ptr noundef nonnull %9) #5
  %49 = load i32, ptr %9, align 4, !tbaa !15
  %50 = load i32, ptr %40, align 4, !tbaa !17
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.6, i32 noundef %49, i32 noundef %50)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #5
  %52 = load i32, ptr %1, align 4, !tbaa !5
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %1, align 4, !tbaa !5
  %54 = icmp slt i32 %52, 4
  br i1 %54, label %41, label %55, !llvm.loop !20

55:                                               ; preds = %41
  %56 = call i32 @queue_destroy(ptr noundef nonnull %2) #5
  %57 = call i32 @queue_destroy(ptr noundef nonnull %3) #5
  %58 = call i32 @queue_destroy(ptr noundef nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0
}

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

; Function Attrs: nounwind
declare i64 @time(ptr noundef) local_unnamed_addr #1

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

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

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

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

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #1

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

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

declare i32 @queue_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 = { 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 #2 = { mustprogress nocallback nofree nosync 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"queue_t", !11, i64 0, !11, i64 8, !12, i64 16, !12, i64 24}
!11 = !{!"long", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"cord", !6, i64 0, !6, i64 4}
!17 = !{!16, !6, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass