; LLVM IR from Water-Melon/Melon :: t (array)

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.mln_array_t, align 8
  %6 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.start.p0(i64 64, ptr %5) #3
  %7 = call i32 @mln_array_init(ptr noundef %5, ptr noundef null, i64 noundef 8, i64 noundef 1)
  %8 = call ptr @mln_array_push(ptr noundef %5)
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %0
  store i32 -1, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %49

12:                                               ; preds = %0
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.test_t, ptr %13, i32 0, i32 0
  store i32 0, ptr %14, align 4, !tbaa !9
  %15 = call ptr @mln_array_pushn(ptr noundef %5, i64 noundef 9)
  store ptr %15, ptr %2, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !12
  br label %16

16:                                               ; preds = %27, %12
  %17 = load i64, ptr %3, align 8, !tbaa !12
  %18 = icmp ult i64 %17, 9
  br i1 %18, label %19, label %30

19:                                               ; preds = %16
  %20 = load i64, ptr %3, align 8, !tbaa !12
  %21 = add i64 %20, 1
  %22 = trunc i64 %21 to i32
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = load i64, ptr %3, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct.test_t, ptr %23, i64 %24
  %26 = getelementptr inbounds %struct.test_t, ptr %25, i32 0, i32 0
  store i32 %22, ptr %26, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %19
  %28 = load i64, ptr %3, align 8, !tbaa !12
  %29 = add i64 %28, 1
  store i64 %29, ptr %3, align 8, !tbaa !12
  br label %16, !llvm.loop !14

30:                                               ; preds = %16
  %31 = getelementptr inbounds %struct.mln_array_t, ptr %5, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  store ptr %32, ptr %2, align 8, !tbaa !5
  store i64 0, ptr %3, align 8, !tbaa !12
  br label %33

33:                                               ; preds = %45, %30
  %34 = load i64, ptr %3, align 8, !tbaa !12
  %35 = getelementptr inbounds %struct.mln_array_t, ptr %5, i32 0, i32 3
  %36 = load i64, ptr %35, align 8, !tbaa !18
  %37 = icmp ult i64 %34, %36
  br i1 %37, label %38, label %48

38:                                               ; preds = %33
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = load i64, ptr %3, align 8, !tbaa !12
  %41 = getelementptr inbounds %struct.test_t, ptr %39, i64 %40
  %42 = getelementptr inbounds %struct.test_t, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %43)
  br label %45

45:                                               ; preds = %38
  %46 = load i64, ptr %3, align 8, !tbaa !12
  %47 = add i64 %46, 1
  store i64 %47, ptr %3, align 8, !tbaa !12
  br label %33, !llvm.loop !19

48:                                               ; preds = %33
  call void @mln_array_destroy(ptr noundef %5)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %6, align 4
  br label %49

49:                                               ; preds = %48, %11
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  %50 = load i32, ptr %1, align 4
  ret i32 %50
}

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

declare i32 @mln_array_init(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #2

declare ptr @mln_array_push(ptr noundef) #2

declare ptr @mln_array_pushn(ptr noundef, i64 noundef) #2

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

declare void @mln_array_destroy(ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!18 = !{!17, !13, i64 24}
!19 = distinct !{!19, !15}


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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 1) i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.mln_array_t, align 8
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %1) #4
  %2 = call i32 @mln_array_init(ptr noundef nonnull %1, ptr noundef null, i64 noundef 8, i64 noundef 1) #4
  %3 = call ptr @mln_array_push(ptr noundef nonnull %1) #4
  %4 = icmp eq ptr %3, null
  br i1 %4, label %24, label %5

5:                                                ; preds = %0
  store i32 0, ptr %3, align 4, !tbaa !5
  %6 = call ptr @mln_array_pushn(ptr noundef nonnull %1, i64 noundef 9) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  store i32 2, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 3, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  store i32 4, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %6, i64 32
  store i32 5, ptr %10, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %6, i64 40
  store i32 6, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %6, i64 48
  store i32 7, ptr %12, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %6, i64 56
  store i32 8, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %6, i64 64
  store i32 9, ptr %14, align 4, !tbaa !5
  %15 = load ptr, ptr %1, align 8, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  %17 = load i64, ptr %16, align 8, !tbaa !14
  %.not = icmp eq i64 %17, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %.lr.ph
  %.114 = phi i64 [ %21, %.lr.ph ], [ 0, %5 ]
  %18 = getelementptr inbounds %struct.test_t, ptr %15, i64 %.114
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %19)
  %21 = add nuw i64 %.114, 1
  %22 = load i64, ptr %16, align 8, !tbaa !14
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %.lr.ph, %5
  call void @mln_array_destroy(ptr noundef nonnull %1) #4
  br label %24

24:                                               ; preds = %0, %._crit_edge
  %.0 = phi i32 [ 0, %._crit_edge ], [ -1, %0 ]
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %1) #4
  ret i32 %.0
}

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

declare i32 @mln_array_init(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #2

declare ptr @mln_array_push(ptr noundef) local_unnamed_addr #2

declare ptr @mln_array_pushn(ptr noundef, i64 noundef) local_unnamed_addr #2

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

declare void @mln_array_destroy(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 #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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!11, !13, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass