; LLVM IR from Water-Melon/Melon :: src (mln_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"

%struct.mln_stack_t = type { ptr, ptr, ptr, ptr, i64, ptr, ptr }
%struct.mln_stack_node_s = type { ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local ptr @mln_stack_init(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
declare dso_local void @mln_stack_destroy(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_stack_dup(ptr noundef nonnull %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.mln_stack_t, ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mln_stack_t, ptr %13, i32 0, i32 6
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = call ptr @mln_stack_init(ptr noundef %12, ptr noundef %15)
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %75

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mln_stack_t, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  store ptr %23, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %68, %20
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %72

27:                                               ; preds = %24
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mln_stack_t, ptr %28, i32 0, i32 6
  %30 = load ptr, ptr %29, align 8, !tbaa !12
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %36

32:                                               ; preds = %27
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mln_stack_node_s, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  store ptr %35, ptr %9, align 8, !tbaa !5
  br label %50

36:                                               ; preds = %27
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mln_stack_t, ptr %37, i32 0, i32 6
  %39 = load ptr, ptr %38, align 8, !tbaa !12
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mln_stack_node_s, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !14
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = call ptr %39(ptr noundef %42, ptr noundef %43)
  store ptr %44, ptr %9, align 8, !tbaa !5
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %36
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  call void @mln_stack_destroy(ptr noundef %48)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %74

49:                                               ; preds = %36
  br label %50

50:                                               ; preds = %49, %32
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = call i32 @mln_stack_push(ptr noundef %51, ptr noundef %52)
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %67

55:                                               ; preds = %50
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.mln_stack_t, ptr %56, i32 0, i32 5
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %65

60:                                               ; preds = %55
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mln_stack_t, ptr %61, i32 0, i32 5
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  call void %63(ptr noundef %64)
  br label %65

65:                                               ; preds = %60, %55
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  call void @mln_stack_destroy(ptr noundef %66)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %74

67:                                               ; preds = %50
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mln_stack_node_s, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  store ptr %71, ptr %8, align 8, !tbaa !5
  br label %24, !llvm.loop !17

72:                                               ; preds = %24
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %73, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %74

74:                                               ; preds = %72, %65, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  br label %75

75:                                               ; preds = %74, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  %76 = load ptr, ptr %3, align 8
  ret ptr %76
}

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 }

!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, !6, i64 40}
!10 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !11, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 48}
!13 = !{!10, !6, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"mln_stack_node_s", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 16}
!17 = distinct !{!17, !18}
!18 = !{!"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"

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

; Function Attrs: nounwind uwtable
declare dso_local void @mln_stack_destroy(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @mln_stack_dup(ptr nocapture noundef nonnull readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = tail call ptr @mln_stack_init(ptr noundef %4, ptr noundef %6)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %.02128 = load ptr, ptr %0, align 8, !tbaa !12
  %.not29 = icmp eq ptr %.02128, null
  br i1 %.not29, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %9 = getelementptr inbounds i8, ptr %7, i64 48
  br label %12

10:                                               ; preds = %19
  %11 = getelementptr inbounds i8, ptr %.02130, i64 16
  %.021 = load ptr, ptr %11, align 8, !tbaa !12
  %.not = icmp eq ptr %.021, null
  br i1 %.not, label %.loopexit, label %12, !llvm.loop !13

12:                                               ; preds = %.lr.ph, %10
  %.02130 = phi ptr [ %.02128, %.lr.ph ], [ %.021, %10 ]
  %13 = load ptr, ptr %9, align 8, !tbaa !11
  %14 = icmp eq ptr %13, null
  %15 = load ptr, ptr %.02130, align 8, !tbaa !15
  br i1 %14, label %19, label %16

16:                                               ; preds = %12
  %17 = tail call ptr %13(ptr noundef %15, ptr noundef %1) #1
  %18 = icmp eq ptr %17, null
  br i1 %18, label %.loopexit.sink.split, label %19

19:                                               ; preds = %12, %16
  %.0 = phi ptr [ %17, %16 ], [ %15, %12 ]
  %20 = tail call i32 @mln_stack_push(ptr noundef %7, ptr noundef %.0)
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %22, label %10

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %7, i64 40
  %24 = load ptr, ptr %23, align 8, !tbaa !5
  %.not27 = icmp eq ptr %24, null
  br i1 %.not27, label %.loopexit.sink.split, label %25

25:                                               ; preds = %22
  tail call void %24(ptr noundef nonnull %.0) #1
  br label %.loopexit.sink.split

.loopexit.sink.split:                             ; preds = %16, %22, %25
  tail call void @mln_stack_destroy(ptr noundef nonnull %7)
  br label %.loopexit

.loopexit:                                        ; preds = %10, %.loopexit.sink.split, %.preheader, %2
  %.1 = phi ptr [ null, %2 ], [ %7, %.preheader ], [ null, %.loopexit.sink.split ], [ %7, %10 ]
  ret ptr %.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 = { 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 40}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !7, i64 48}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 48}
!12 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !7, i64 0}
!16 = !{!"mln_stack_node_s", !7, i64 0, !7, i64 8, !7, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass