; LLVM IR from IOsonata/IOsonata :: src/stddev.ll (open)

; 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.StdDev_t = type { [8 x i8], ptr, ptr, ptr, ptr, ptr, ptr }

@g_DevTable = external dso_local global [6 x ptr], align 16
@.str = external hidden unnamed_addr constant [5 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

; 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 i32 @_open(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  br label %88

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 -1, ptr %9, align 4, !tbaa !9
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call ptr @strchr(ptr noundef %15, i32 noundef 58) #4
  store ptr %16, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %23, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call i32 @strncmp(ptr noundef %20, ptr noundef @.str, i64 noundef 4) #4
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %41

23:                                               ; preds = %19, %14
  %24 = load ptr, ptr getelementptr inbounds ([6 x ptr], ptr @g_DevTable, i64 0, i64 3), align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.StdDev_t, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 4, !tbaa !11
  %27 = load ptr, ptr getelementptr inbounds ([6 x ptr], ptr @g_DevTable, i64 0, i64 3), align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.StdDev_t, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 4, !tbaa !13
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = call i32 %26(ptr noundef %29, ptr noundef %30, i32 noundef %31, i32 noundef %32)
  store i32 %33, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = icmp ne i32 %34, -1
  br i1 %35, label %36, label %40

36:                                               ; preds = %23
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = shl i32 %37, 4
  %39 = or i32 %38, 3
  store i32 %39, ptr %9, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %36, %23
  br label %86

41:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 3, ptr %10, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %82, %41
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = icmp slt i32 %43, 6
  br i1 %44, label %46, label %45

45:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %85

46:                                               ; preds = %42
  %47 = load i32, ptr %10, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [6 x ptr], ptr @g_DevTable, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.StdDev_t, ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds [8 x i8], ptr %51, i64 0, i64 0
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = call i32 @strncmp(ptr noundef %52, ptr noundef %53, i64 noundef 4) #4
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %81

56:                                               ; preds = %46
  %57 = load i32, ptr %10, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [6 x ptr], ptr @g_DevTable, i64 0, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.StdDev_t, ptr %60, i32 0, i32 2
  %62 = load ptr, ptr %61, align 4, !tbaa !11
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [6 x ptr], ptr @g_DevTable, i64 0, i64 %64
  %66 = load ptr, ptr %65, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.StdDev_t, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 4, !tbaa !13
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = load i32, ptr %7, align 4, !tbaa !9
  %72 = call i32 %62(ptr noundef %68, ptr noundef %69, i32 noundef %70, i32 noundef %71)
  store i32 %72, ptr %9, align 4, !tbaa !9
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = icmp ne i32 %73, -1
  br i1 %74, label %75, label %80

75:                                               ; preds = %56
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = shl i32 %76, 4
  %78 = load i32, ptr %10, align 4, !tbaa !9
  %79 = or i32 %77, %78
  store i32 %79, ptr %9, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %75, %56
  br label %81

81:                                               ; preds = %80, %46
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %10, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %10, align 4, !tbaa !9
  br label %42, !llvm.loop !14

85:                                               ; preds = %45
  br label %86

86:                                               ; preds = %85, %40
  %87 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %87, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %88

88:                                               ; preds = %86, %13
  %89 = load i32, ptr %4, align 4
  ret i32 %89
}

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #2

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 willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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, !6, i64 16}
!12 = !{!"", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"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
@.str = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @_open(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %.loopexit, label %5

5:                                                ; preds = %3
  %6 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %0, i32 noundef 58) #2
  %7 = icmp eq ptr %6, null
  br i1 %7, label %14, label %8

8:                                                ; preds = %5
  %9 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) @.str, i64 noundef 4) #2
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %14, label %.preheader.preheader

.preheader.preheader:                             ; preds = %8
  %11 = load ptr, ptr getelementptr inbounds (i8, ptr @g_DevTable, i64 24), align 8, !tbaa !5
  %12 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 4) #2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %24, label %.preheader.1

14:                                               ; preds = %8, %5
  %15 = load ptr, ptr getelementptr inbounds (i8, ptr @g_DevTable, i64 24), align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 16
  %17 = load ptr, ptr %16, align 4, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %15, i64 8
  %19 = load ptr, ptr %18, align 4, !tbaa !11
  %20 = tail call i32 %17(ptr noundef %19, ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2) #3
  %.not29 = icmp eq i32 %20, -1
  br i1 %.not29, label %.loopexit, label %21

21:                                               ; preds = %14
  %22 = shl i32 %20, 4
  %23 = or disjoint i32 %22, 3
  br label %.loopexit

24:                                               ; preds = %.preheader.preheader
  %25 = getelementptr inbounds i8, ptr %11, i64 16
  %26 = load ptr, ptr %25, align 4, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %11, i64 8
  %28 = load ptr, ptr %27, align 4, !tbaa !11
  %29 = tail call i32 %26(ptr noundef %28, ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2) #3
  %.not = icmp eq i32 %29, -1
  br i1 %.not, label %.preheader.1, label %30

30:                                               ; preds = %24
  %31 = shl i32 %29, 4
  %32 = or disjoint i32 %31, 3
  br label %.preheader.1

.preheader.1:                                     ; preds = %.preheader.preheader, %30, %24
  %.1 = phi i32 [ %32, %30 ], [ -1, %24 ], [ -1, %.preheader.preheader ]
  %33 = load ptr, ptr getelementptr inbounds (i8, ptr @g_DevTable, i64 32), align 16, !tbaa !5
  %34 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %33, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 4) #2
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %.preheader.2

36:                                               ; preds = %.preheader.1
  %37 = getelementptr inbounds i8, ptr %33, i64 16
  %38 = load ptr, ptr %37, align 4, !tbaa !9
  %39 = getelementptr inbounds i8, ptr %33, i64 8
  %40 = load ptr, ptr %39, align 4, !tbaa !11
  %41 = tail call i32 %38(ptr noundef %40, ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2) #3
  %.not.1 = icmp eq i32 %41, -1
  br i1 %.not.1, label %.preheader.2, label %42

42:                                               ; preds = %36
  %43 = shl i32 %41, 4
  %44 = or disjoint i32 %43, 4
  br label %.preheader.2

.preheader.2:                                     ; preds = %42, %36, %.preheader.1
  %.1.1 = phi i32 [ %44, %42 ], [ -1, %36 ], [ %.1, %.preheader.1 ]
  %45 = load ptr, ptr getelementptr inbounds (i8, ptr @g_DevTable, i64 40), align 8, !tbaa !5
  %46 = tail call i32 @strncmp(ptr noundef nonnull dereferenceable(1) %45, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 4) #2
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %.loopexit

48:                                               ; preds = %.preheader.2
  %49 = getelementptr inbounds i8, ptr %45, i64 16
  %50 = load ptr, ptr %49, align 4, !tbaa !9
  %51 = getelementptr inbounds i8, ptr %45, i64 8
  %52 = load ptr, ptr %51, align 4, !tbaa !11
  %53 = tail call i32 %50(ptr noundef %52, ptr noundef nonnull %0, i32 noundef %1, i32 noundef %2) #3
  %.not.2 = icmp eq i32 %53, -1
  br i1 %.not.2, label %.loopexit, label %54

54:                                               ; preds = %48
  %55 = shl i32 %53, 4
  %56 = or disjoint i32 %55, 5
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.2, %48, %54, %21, %14, %3
  %.023 = phi i32 [ -1, %3 ], [ %23, %21 ], [ -1, %14 ], [ %56, %54 ], [ -1, %48 ], [ %.1.1, %.preheader.2 ]
  ret i32 %.023
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 willreturn memory(read) }
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, !6, i64 16}
!10 = !{!"", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!11 = !{!10, !6, i64 8}


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