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

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

@.str = external hidden unnamed_addr constant [67 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [33 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 ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %6 = call ptr @mln_stack_init(ptr noundef @free, ptr noundef @copy)
  store ptr %6, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  br label %10

9:                                                ; preds = %0
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 24, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

10:                                               ; preds = %8
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %27, %10
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = icmp slt i32 %12, 3
  br i1 %13, label %14, label %30

14:                                               ; preds = %11
  %15 = call noalias ptr @malloc(i64 noundef 16) #8
  store ptr %15, ptr %3, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.1, i32 noundef 27, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

19:                                               ; preds = %17
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @mln_stack_push(ptr noundef %20, ptr noundef %21)
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  br label %26

25:                                               ; preds = %19
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.1, i32 noundef 28, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

26:                                               ; preds = %24
  br label %27

27:                                               ; preds = %26
  %28 = load i32, ptr %2, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !9
  br label %11, !llvm.loop !11

30:                                               ; preds = %11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call ptr @mln_stack_dup(ptr noundef %31, ptr noundef null)
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %36

35:                                               ; preds = %30
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 31, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

36:                                               ; preds = %34
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = call ptr @mln_stack_pop(ptr noundef %37)
  store ptr %38, ptr %3, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  br label %42

41:                                               ; preds = %36
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 33, ptr noundef @__PRETTY_FUNCTION__.main) #7
  unreachable

42:                                               ; preds = %40
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  call void @free(ptr noundef %43) #6
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mln_stack_destroy(ptr noundef %44)
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  call void @mln_stack_destroy(ptr noundef %45)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  ret i32 0
}

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

declare ptr @mln_stack_init(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @copy(ptr noundef, ptr noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #5

declare i32 @mln_stack_push(ptr noundef, ptr noundef) #2

declare ptr @mln_stack_dup(ptr noundef, ptr noundef) #2

declare ptr @mln_stack_pop(ptr noundef) #2

declare void @mln_stack_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 "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 = { noreturn 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 allocsize(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 #6 = { nounwind }
attributes #7 = { noreturn nounwind }
attributes #8 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@.str = external hidden unnamed_addr constant [67 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [15 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [47 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [28 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call ptr @mln_stack_init(ptr noundef nonnull @free, ptr noundef nonnull @copy) #5
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %3, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %2 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  %.not14 = icmp eq ptr %2, null
  br i1 %.not14, label %14, label %15

3:                                                ; preds = %0
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 24, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

.preheader.1:                                     ; preds = %15
  %4 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  %.not14.1 = icmp eq ptr %4, null
  br i1 %.not14.1, label %14, label %5

5:                                                ; preds = %.preheader.1
  %6 = tail call i32 @mln_stack_push(ptr noundef nonnull %1, ptr noundef nonnull %4) #5
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %.preheader.2, label %18

.preheader.2:                                     ; preds = %5
  %8 = tail call noalias dereferenceable_or_null(16) ptr @malloc(i64 noundef 16) #6
  %.not14.2 = icmp eq ptr %8, null
  br i1 %.not14.2, label %14, label %9

9:                                                ; preds = %.preheader.2
  %10 = tail call i32 @mln_stack_push(ptr noundef nonnull %1, ptr noundef nonnull %8) #5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %18

12:                                               ; preds = %9
  %13 = tail call ptr @mln_stack_dup(ptr noundef nonnull %1, ptr noundef null) #5
  %.not12 = icmp eq ptr %13, null
  br i1 %.not12, label %19, label %20

14:                                               ; preds = %.preheader.2, %.preheader.1, %.preheader.preheader
  tail call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.1, i32 noundef 27, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

15:                                               ; preds = %.preheader.preheader
  %16 = tail call i32 @mln_stack_push(ptr noundef nonnull %1, ptr noundef nonnull %2) #5
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.preheader.1, label %18

18:                                               ; preds = %9, %5, %15
  tail call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.1, i32 noundef 28, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

19:                                               ; preds = %12
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 31, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

20:                                               ; preds = %12
  %21 = tail call ptr @mln_stack_pop(ptr noundef nonnull %1) #5
  %.not13 = icmp eq ptr %21, null
  br i1 %.not13, label %22, label %23

22:                                               ; preds = %20
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 33, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #7
  unreachable

23:                                               ; preds = %20
  tail call void @free(ptr noundef nonnull %21) #5
  tail call void @mln_stack_destroy(ptr noundef nonnull %1) #5
  tail call void @mln_stack_destroy(ptr noundef nonnull %13) #5
  ret i32 0
}

declare ptr @mln_stack_init(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @copy(ptr noundef, ptr noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

declare i32 @mln_stack_push(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @mln_stack_dup(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @mln_stack_pop(ptr noundef) local_unnamed_addr #1

declare void @mln_stack_destroy(ptr noundef) local_unnamed_addr #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 = { "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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { noreturn 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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)"}


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