; LLVM IR from introlab/odas :: src/system (gain2mask)

; 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.gain2mask_obj = type { i32, i32, float }
%struct.gains_obj = type { i32, i32, ptr }
%struct.masks_obj = type { i32, i32, ptr }

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

; 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
define dso_local void @gain2mask_process(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %71, %3
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.gain2mask_obj, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = icmp ult i32 %10, %13
  br i1 %14, label %15, label %74

15:                                               ; preds = %9
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %67, %15
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.gain2mask_obj, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !14
  %21 = icmp ult i32 %17, %20
  br i1 %21, label %22, label %70

22:                                               ; preds = %16
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.gains_obj, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.gain2mask_obj, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = mul i32 %26, %29
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = add i32 %30, %31
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds float, ptr %25, i64 %33
  %35 = load float, ptr %34, align 4, !tbaa !17
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gain2mask_obj, ptr %36, i32 0, i32 2
  %38 = load float, ptr %37, align 4, !tbaa !18
  %39 = fcmp oge float %35, %38
  br i1 %39, label %40, label %53

40:                                               ; preds = %22
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.masks_obj, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !19
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.gain2mask_obj, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !14
  %48 = mul i32 %44, %47
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = add i32 %48, %49
  %51 = zext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %43, i64 %51
  store i8 1, ptr %52, align 1, !tbaa !21
  br label %66

53:                                               ; preds = %22
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.masks_obj, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = load i32, ptr %7, align 4, !tbaa !9
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.gain2mask_obj, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !14
  %61 = mul i32 %57, %60
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = add i32 %61, %62
  %64 = zext i32 %63 to i64
  %65 = getelementptr inbounds i8, ptr %56, i64 %64
  store i8 0, ptr %65, align 1, !tbaa !21
  br label %66

66:                                               ; preds = %53, %40
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = add i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !9
  br label %16, !llvm.loop !22

70:                                               ; preds = %16
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = add i32 %72, 1
  store i32 %73, ptr %7, align 4, !tbaa !9
  br label %9, !llvm.loop !24

74:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !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 = !{!12, !10, i64 0}
!12 = !{!"gain2mask_obj", !10, i64 0, !10, i64 4, !13, i64 8}
!13 = !{!"float", !7, i64 0}
!14 = !{!12, !10, i64 4}
!15 = !{!16, !6, i64 8}
!16 = !{!"gains_obj", !10, i64 0, !10, i64 4, !6, i64 8}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !13, i64 8}
!19 = !{!20, !6, i64 8}
!20 = !{!"masks_obj", !10, i64 0, !10, i64 4, !6, i64 8}
!21 = !{!7, !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = distinct !{!24, !23}


; 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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @gain2mask_process(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = load i32, ptr %0, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %._crit_edge22, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = getelementptr inbounds i8, ptr %2, i64 8
  %9 = load i32, ptr %5, align 4, !tbaa !11
  %.not23 = icmp eq i32 %9, 0
  br i1 %.not23, label %._crit_edge22, label %.preheader

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %10 = phi i32 [ %26, %._crit_edge ], [ %4, %.preheader.lr.ph ]
  %11 = phi i32 [ %27, %._crit_edge ], [ %9, %.preheader.lr.ph ]
  %.01821 = phi i32 [ %28, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %.not24 = icmp eq i32 %11, 0
  br i1 %.not24, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %12 = phi i32 [ %24, %.lr.ph ], [ %11, %.preheader ]
  %.020 = phi i32 [ %23, %.lr.ph ], [ 0, %.preheader ]
  %13 = load ptr, ptr %6, align 8, !tbaa !12
  %14 = mul i32 %12, %.01821
  %15 = add i32 %14, %.020
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds float, ptr %13, i64 %16
  %18 = load float, ptr %17, align 4, !tbaa !15
  %19 = load float, ptr %7, align 4, !tbaa !16
  %20 = fcmp oge float %18, %19
  %21 = load ptr, ptr %8, align 8, !tbaa !17
  %22 = getelementptr inbounds i8, ptr %21, i64 %16
  %. = zext i1 %20 to i8
  store i8 %., ptr %22, align 1, !tbaa !19
  %23 = add nuw i32 %.020, 1
  %24 = load i32, ptr %5, align 4, !tbaa !11
  %25 = icmp ult i32 %23, %24
  br i1 %25, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !20

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %26 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %10, %.preheader ]
  %27 = phi i32 [ %24, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %28 = add nuw i32 %.01821, 1
  %29 = icmp ult i32 %28, %26
  br i1 %29, label %.preheader, label %._crit_edge22, !llvm.loop !22

._crit_edge22:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %3
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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" }

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


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