; LLVM IR from IOsonata/IOsonata :: src (stddev)

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

@g_DevTable = external dso_local global [6 x ptr], align 16

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

9:                                                ; preds = %2, %2, %2, %2
  %10 = load i32, ptr %4, align 4, !tbaa !9
  store i32 %10, ptr %5, align 4, !tbaa !9
  br label %30

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  store i32 4, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %25, %11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 6
  br i1 %14, label %16, label %15

15:                                               ; preds = %12
  store i32 3, ptr %7, align 4
  br label %28

16:                                               ; preds = %12
  %17 = load i32, ptr %6, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [6 x ptr], ptr @g_DevTable, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %16
  %23 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %23, ptr %5, align 4, !tbaa !9
  store i32 3, ptr %7, align 4
  br label %28

24:                                               ; preds = %16
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %6, align 4, !tbaa !9
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !11

28:                                               ; preds = %22, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %29

29:                                               ; preds = %28
  br label %30

30:                                               ; preds = %29, %9
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %33, label %38

33:                                               ; preds = %30
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [6 x ptr], ptr @g_DevTable, i64 0, i64 %36
  store ptr %34, ptr %37, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %33, %30
  %39 = load i32, ptr %5, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 %39
}

; 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

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, !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"

@g_DevTable = external dso_local local_unnamed_addr global [6 x ptr], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @InstallBlkDev(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %switch = icmp ult i32 %1, 4
  br i1 %switch, label %.loopexit13, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @g_DevTable, i64 32), align 16, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %.loopexit13, label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @g_DevTable, i64 40), align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %.loopexit13, label %.loopexit

.loopexit13:                                      ; preds = %.preheader.preheader, %.preheader.1, %2
  %.1.ph = phi i32 [ %1, %2 ], [ 4, %.preheader.preheader ], [ 5, %.preheader.1 ]
  %7 = zext nneg i32 %.1.ph to i64
  %8 = getelementptr inbounds [6 x ptr], ptr @g_DevTable, i64 0, i64 %7
  store ptr %0, ptr %8, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.1, %.loopexit13
  %.111 = phi i32 [ %.1.ph, %.loopexit13 ], [ -1, %.preheader.1 ]
  ret i32 %.111
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass