; LLVM IR from jingweizhanghuai/Morn :: src/wave (morn_wave)

; 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.MWave = type { i32, i32, [32 x ptr] }

@.str = external hidden unnamed_addr constant [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mWaveOperate = external hidden unnamed_addr constant [13 x i8], align 1

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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @mWaveRedefine(ptr noundef, i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @mWaveOperate(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  br label %12

12:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %19, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = icmp eq i64 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %12
  br label %44

20:                                               ; preds = %15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MWave, ptr %21, i32 0, i32 2
  %23 = getelementptr inbounds [32 x ptr], ptr %22, i64 0, i64 0
  %24 = icmp eq ptr %23, null
  br i1 %24, label %41, label %25

25:                                               ; preds = %20
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.MWave, ptr %26, i32 0, i32 2
  %28 = getelementptr inbounds [32 x ptr], ptr %27, i64 0, i64 0
  %29 = ptrtoint ptr %28 to i64
  %30 = icmp eq i64 %29, -1
  br i1 %30, label %41, label %31

31:                                               ; preds = %25
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.MWave, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = icmp sle i32 %34, 0
  br i1 %35, label %41, label %36

36:                                               ; preds = %31
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MWave, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !12
  %40 = icmp sle i32 %39, 0
  br label %41

41:                                               ; preds = %36, %31, %25, %20
  %42 = phi i1 [ true, %31 ], [ true, %25 ], [ true, %20 ], [ %40, %36 ]
  %43 = zext i1 %42 to i32
  br label %44

44:                                               ; preds = %41, %19
  %45 = phi i32 [ 1, %19 ], [ %43, %41 ]
  store i32 %45, ptr %10, align 4, !tbaa !13
  %46 = load i32, ptr %10, align 4, !tbaa !13
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %48, label %50

48:                                               ; preds = %44
  %49 = load i32, ptr %10, align 4, !tbaa !13
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %49, i32 noundef -1, ptr noundef @.str, i32 noundef 409, ptr noundef @__FUNCTION__.mWaveOperate, ptr noundef @.str.2)
  br label %50

50:                                               ; preds = %48, %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %59, label %55

55:                                               ; preds = %52
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = ptrtoint ptr %56 to i64
  %58 = icmp eq i64 %57, -1
  br i1 %58, label %59, label %61

59:                                               ; preds = %55, %52
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %60, ptr %6, align 8, !tbaa !5
  br label %72

61:                                               ; preds = %55
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.MWave, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !9
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.MWave, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !12
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.MWave, ptr %69, i32 0, i32 2
  %71 = getelementptr inbounds [32 x ptr], ptr %70, i64 0, i64 0
  call void @mWaveRedefine(ptr noundef %62, i32 noundef %65, i32 noundef %68, ptr noundef %71)
  br label %72

72:                                               ; preds = %61, %59
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %73

73:                                               ; preds = %114, %72
  %74 = load i32, ptr %11, align 4, !tbaa !13
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.MWave, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !9
  %78 = icmp slt i32 %74, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %117

80:                                               ; preds = %73
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %81

81:                                               ; preds = %110, %80
  %82 = load i32, ptr %9, align 4, !tbaa !13
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.MWave, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !12
  %86 = icmp slt i32 %82, %85
  br i1 %86, label %87, label %113

87:                                               ; preds = %81
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.MWave, ptr %89, i32 0, i32 2
  %91 = load i32, ptr %11, align 4, !tbaa !13
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [32 x ptr], ptr %90, i64 0, i64 %92
  %94 = load ptr, ptr %93, align 8, !tbaa !5
  %95 = load i32, ptr %9, align 4, !tbaa !13
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds float, ptr %94, i64 %96
  %98 = load float, ptr %97, align 4, !tbaa !14
  %99 = load ptr, ptr %8, align 8, !tbaa !5
  %100 = call float %88(float noundef %98, ptr noundef %99)
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.MWave, ptr %101, i32 0, i32 2
  %103 = load i32, ptr %11, align 4, !tbaa !13
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [32 x ptr], ptr %102, i64 0, i64 %104
  %106 = load ptr, ptr %105, align 8, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !13
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds float, ptr %106, i64 %108
  store float %100, ptr %109, align 4, !tbaa !14
  br label %110

110:                                              ; preds = %87
  %111 = load i32, ptr %9, align 4, !tbaa !13
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %9, align 4, !tbaa !13
  br label %81, !llvm.loop !16

113:                                              ; preds = %81
  br label %114

114:                                              ; preds = %113
  %115 = load i32, ptr %11, align 4, !tbaa !13
  %116 = add nsw i32 %115, 1
  store i32 %116, ptr %11, align 4, !tbaa !13
  br label %73, !llvm.loop !18

117:                                              ; preds = %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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 = !{!"MWave", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; 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 [76 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mWaveOperate = external hidden unnamed_addr constant [13 x i8], align 1

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @mWaveRedefine(ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @mWaveOperate(ptr noundef %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3) local_unnamed_addr #1 {
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %5 [
    i64 -1, label %.critedge
    i64 0, label %.critedge
  ]

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = icmp eq ptr %6, inttoptr (i64 -1 to ptr)
  br i1 %7, label %.critedge, label %8

8:                                                ; preds = %5
  %9 = load i32, ptr %0, align 8, !tbaa !5
  %10 = icmp slt i32 %9, 1
  br i1 %10, label %.critedge, label %11

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %15, label %.critedge

.critedge:                                        ; preds = %4, %4, %8, %5, %11
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 409, ptr noundef nonnull @__FUNCTION__.mWaveOperate, ptr noundef nonnull @.str.2) #2
  br label %15

15:                                               ; preds = %.critedge, %11
  %magicptr43 = ptrtoint ptr %1 to i64
  switch i64 %magicptr43, label %16 [
    i64 -1, label %21
    i64 0, label %21
  ]

16:                                               ; preds = %15
  %17 = load i32, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %1, i64 8
  tail call void @mWaveRedefine(ptr noundef %1, i32 noundef %17, i32 noundef %19, ptr noundef nonnull %20)
  br label %21

21:                                               ; preds = %15, %15, %16
  %.038 = phi ptr [ %1, %16 ], [ %0, %15 ], [ %0, %15 ]
  %22 = load i32, ptr %0, align 8, !tbaa !5
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.preheader.lr.ph, label %._crit_edge46

.preheader.lr.ph:                                 ; preds = %21
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  %26 = getelementptr inbounds i8, ptr %.038, i64 8
  %27 = load i32, ptr %24, align 4, !tbaa !10
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.preheader, label %._crit_edge46

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %29 = phi i32 [ %44, %._crit_edge ], [ %22, %.preheader.lr.ph ]
  %30 = phi i32 [ %45, %._crit_edge ], [ %27, %.preheader.lr.ph ]
  %indvars.iv49 = phi i64 [ %indvars.iv.next50, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %32 = getelementptr inbounds [32 x ptr], ptr %25, i64 0, i64 %indvars.iv49
  %33 = getelementptr inbounds [32 x ptr], ptr %26, i64 0, i64 %indvars.iv49
  br label %34

._crit_edge46:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %21
  ret void

34:                                               ; preds = %.lr.ph, %34
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %34 ]
  %35 = load ptr, ptr %32, align 8, !tbaa !11
  %36 = getelementptr inbounds float, ptr %35, i64 %indvars.iv
  %37 = load float, ptr %36, align 4, !tbaa !13
  %38 = tail call float %2(float noundef %37, ptr noundef %3) #2
  %39 = load ptr, ptr %33, align 8, !tbaa !11
  %40 = getelementptr inbounds float, ptr %39, i64 %indvars.iv
  store float %38, ptr %40, align 4, !tbaa !13
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = load i32, ptr %24, align 4, !tbaa !10
  %42 = sext i32 %41 to i64
  %43 = icmp slt i64 %indvars.iv.next, %42
  br i1 %43, label %34, label %._crit_edge.loopexit, !llvm.loop !15

._crit_edge.loopexit:                             ; preds = %34
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %44 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %29, %.preheader ]
  %45 = phi i32 [ %41, %._crit_edge.loopexit ], [ %30, %.preheader ]
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %46 = sext i32 %44 to i64
  %47 = icmp slt i64 %indvars.iv.next50, %46
  br i1 %47, label %.preheader, label %._crit_edge46, !llvm.loop !17
}

attributes #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 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 #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, !7, i64 0}
!6 = !{!"MWave", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16, !18}
!18 = !{!"llvm.loop.unswitch.partial.disable"}


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