; LLVM IR from certik/mlc :: mlc_clib (kernels)

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

; 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 @batch_norm_2d(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) #1 {
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca float, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  store i32 %0, ptr %10, align 4, !tbaa !5
  store i32 %1, ptr %11, align 4, !tbaa !5
  store i32 %2, ptr %12, align 4, !tbaa !5
  store ptr %3, ptr %13, align 8, !tbaa !9
  store ptr %4, ptr %14, align 8, !tbaa !9
  store ptr %5, ptr %15, align 8, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !9
  store ptr %7, ptr %17, align 8, !tbaa !9
  store ptr %8, ptr %18, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  store float 0x3F50624DE0000000, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #4
  store i32 0, ptr %20, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %110, %9
  %25 = load i32, ptr %20, align 4, !tbaa !5
  %26 = load i32, ptr %10, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 2, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #4
  br label %113

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #4
  store i32 0, ptr %22, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %106, %29
  %31 = load i32, ptr %22, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %30
  store i32 5, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #4
  br label %109

35:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #4
  store i32 0, ptr %23, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %102, %35
  %37 = load i32, ptr %23, align 4, !tbaa !5
  %38 = load i32, ptr %12, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  store i32 8, ptr %21, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #4
  br label %105

41:                                               ; preds = %36
  %42 = load ptr, ptr %13, align 8, !tbaa !9
  %43 = load i32, ptr %20, align 4, !tbaa !5
  %44 = load i32, ptr %12, align 4, !tbaa !5
  %45 = mul nsw i32 %43, %44
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = mul nsw i32 %45, %46
  %48 = load i32, ptr %22, align 4, !tbaa !5
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = mul nsw i32 %48, %49
  %51 = add nsw i32 %47, %50
  %52 = load i32, ptr %23, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds float, ptr %42, i64 %54
  %56 = load float, ptr %55, align 4, !tbaa !11
  %57 = load ptr, ptr %17, align 8, !tbaa !9
  %58 = load i32, ptr %20, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds float, ptr %57, i64 %59
  %61 = load float, ptr %60, align 4, !tbaa !11
  %62 = fsub float %56, %61
  %63 = fpext float %62 to double
  %64 = load ptr, ptr %18, align 8, !tbaa !9
  %65 = load i32, ptr %20, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds float, ptr %64, i64 %66
  %68 = load float, ptr %67, align 4, !tbaa !11
  %69 = load float, ptr %19, align 4, !tbaa !11
  %70 = fadd float %68, %69
  %71 = fpext float %70 to double
  %72 = call double @sqrt(double noundef %71) #4
  %73 = fdiv double %63, %72
  %74 = load ptr, ptr %15, align 8, !tbaa !9
  %75 = load i32, ptr %20, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds float, ptr %74, i64 %76
  %78 = load float, ptr %77, align 4, !tbaa !11
  %79 = fpext float %78 to double
  %80 = load ptr, ptr %16, align 8, !tbaa !9
  %81 = load i32, ptr %20, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds float, ptr %80, i64 %82
  %84 = load float, ptr %83, align 4, !tbaa !11
  %85 = fpext float %84 to double
  %86 = call double @llvm.fmuladd.f64(double %73, double %79, double %85)
  %87 = fptrunc double %86 to float
  %88 = load ptr, ptr %14, align 8, !tbaa !9
  %89 = load i32, ptr %20, align 4, !tbaa !5
  %90 = load i32, ptr %12, align 4, !tbaa !5
  %91 = mul nsw i32 %89, %90
  %92 = load i32, ptr %11, align 4, !tbaa !5
  %93 = mul nsw i32 %91, %92
  %94 = load i32, ptr %22, align 4, !tbaa !5
  %95 = load i32, ptr %12, align 4, !tbaa !5
  %96 = mul nsw i32 %94, %95
  %97 = add nsw i32 %93, %96
  %98 = load i32, ptr %23, align 4, !tbaa !5
  %99 = add nsw i32 %97, %98
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds float, ptr %88, i64 %100
  store float %87, ptr %101, align 4, !tbaa !11
  br label %102

102:                                              ; preds = %41
  %103 = load i32, ptr %23, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %23, align 4, !tbaa !5
  br label %36, !llvm.loop !13

105:                                              ; preds = %40
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %22, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %22, align 4, !tbaa !5
  br label %30, !llvm.loop !15

109:                                              ; preds = %34
  br label %110

110:                                              ; preds = %109
  %111 = load i32, ptr %20, align 4, !tbaa !5
  %112 = add nsw i32 %111, 1
  store i32 %112, ptr %20, align 4, !tbaa !5
  br label %24, !llvm.loop !16

113:                                              ; preds = %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  ret void
}

; Function Attrs: nounwind
declare double @sqrt(double noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #3

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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}


; 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 nounwind memory(write, argmem: readwrite) uwtable
define dso_local void @batch_norm_2d(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef readonly %5, ptr nocapture noundef readonly %6, ptr nocapture noundef readonly %7, ptr nocapture noundef readonly %8) local_unnamed_addr #0 {
  %10 = icmp sgt i32 %0, 0
  %11 = icmp sgt i32 %1, 0
  %or.cond = and i1 %10, %11
  %12 = icmp sgt i32 %2, 0
  %or.cond53 = and i1 %or.cond, %12
  br i1 %or.cond53, label %.preheader35.us.us.preheader, label %._crit_edge

.preheader35.us.us.preheader:                     ; preds = %9
  %wide.trip.count51 = zext nneg i32 %0 to i64
  %wide.trip.count = zext nneg i32 %2 to i64
  br label %.preheader35.us.us

.preheader35.us.us:                               ; preds = %.preheader35.us.us.preheader, %._crit_edge38.split.us.us.us
  %indvars.iv48 = phi i64 [ 0, %.preheader35.us.us.preheader ], [ %indvars.iv.next49, %._crit_edge38.split.us.us.us ]
  %13 = trunc nuw nsw i64 %indvars.iv48 to i32
  %14 = mul i32 %13, %1
  %15 = getelementptr inbounds float, ptr %7, i64 %indvars.iv48
  %16 = getelementptr inbounds float, ptr %8, i64 %indvars.iv48
  %17 = getelementptr inbounds float, ptr %5, i64 %indvars.iv48
  %18 = getelementptr inbounds float, ptr %6, i64 %indvars.iv48
  br label %.preheader.us.us.us

.preheader.us.us.us:                              ; preds = %._crit_edge.us.us.us, %.preheader35.us.us
  %.03137.us.us.us = phi i32 [ 0, %.preheader35.us.us ], [ %40, %._crit_edge.us.us.us ]
  %reass.add.us.us.us = add i32 %.03137.us.us.us, %14
  %reass.mul.us.us.us = mul i32 %reass.add.us.us.us, %2
  br label %19

19:                                               ; preds = %19, %.preheader.us.us.us
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %.preheader.us.us.us ]
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  %21 = add i32 %reass.mul.us.us.us, %20
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds float, ptr %3, i64 %22
  %24 = load float, ptr %23, align 4, !tbaa !5
  %25 = load float, ptr %15, align 4, !tbaa !5
  %26 = fsub float %24, %25
  %27 = fpext float %26 to double
  %28 = load float, ptr %16, align 4, !tbaa !5
  %29 = fadd float %28, 0x3F50624DE0000000
  %30 = fpext float %29 to double
  %31 = tail call double @sqrt(double noundef %30) #3
  %32 = fdiv double %27, %31
  %33 = load float, ptr %17, align 4, !tbaa !5
  %34 = fpext float %33 to double
  %35 = load float, ptr %18, align 4, !tbaa !5
  %36 = fpext float %35 to double
  %37 = tail call double @llvm.fmuladd.f64(double %32, double %34, double %36)
  %38 = fptrunc double %37 to float
  %39 = getelementptr inbounds float, ptr %4, i64 %22
  store float %38, ptr %39, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us.us.us, label %19, !llvm.loop !9

._crit_edge.us.us.us:                             ; preds = %19
  %40 = add nuw nsw i32 %.03137.us.us.us, 1
  %exitcond47.not = icmp eq i32 %40, %1
  br i1 %exitcond47.not, label %._crit_edge38.split.us.us.us, label %.preheader.us.us.us, !llvm.loop !11

._crit_edge38.split.us.us.us:                     ; preds = %._crit_edge.us.us.us
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 1
  %exitcond52.not = icmp eq i64 %indvars.iv.next49, %wide.trip.count51
  br i1 %exitcond52.not, label %._crit_edge, label %.preheader35.us.us, !llvm.loop !12

._crit_edge:                                      ; preds = %._crit_edge38.split.us.us.us, %9
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

attributes #0 = { nofree nounwind memory(write, argmem: readwrite) 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 nofree nounwind willreturn memory(write) "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass