; LLVM IR from stan-dev/math :: lib/tbb_2020.3/src/test/test_fp.ll (Z26TestArenaFpuEnvPersistencei)

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

%class.RoundingModeCheckBody = type { i32, i32 }

@_ZL8SseModes = external hidden constant [4 x i32], align 16
@_ZL13RoundingModes = external hidden constant [4 x i32], align 16
@.str.17 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [26 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: mustprogress uwtable
declare dso_local void @_Z11ReportErrorPKciS0_S0_(ptr noundef, i32 noundef, ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z10SetSseModei(i32 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z15SetRoundingModei(i32 noundef) #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(8)) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z26TestArenaFpuEnvPersistencei(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %class.RoundingModeCheckBody, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = srem i32 %11, 4
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = srem i32 %16, 4
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %21

21:                                               ; preds = %59, %1
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp slt i32 %22, 4
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = srem i32 %28, 4
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  store i32 %32, ptr %7, align 4, !tbaa !5
  %33 = load i32, ptr %7, align 4, !tbaa !5
  call void @_Z10SetSseModei(i32 noundef %33)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %55, %25
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 4
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %58

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %39, %40
  %42 = srem i32 %41, 4
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %43
  %45 = load i32, ptr %44, align 4, !tbaa !5
  store i32 %45, ptr %9, align 4, !tbaa !5
  %46 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z15SetRoundingModei(i32 noundef %46)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  call void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %10, i32 noundef %47, i32 noundef %48)
  call void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef 0, i32 noundef 500000, i32 noundef 1, ptr noundef nonnull align 4 dereferenceable(8) %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %49 = call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = icmp eq i32 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %38
  br label %54

53:                                               ; preds = %38
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 106, ptr noundef @.str.18, ptr noundef null)
  br label %54

54:                                               ; preds = %53, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %55

55:                                               ; preds = %54
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !5
  br label %34, !llvm.loop !9

58:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %5, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %5, align 4, !tbaa !5
  br label %21, !llvm.loop !11

62:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress 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 #4 = { inlinehint mustprogress 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 #5 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

%class.RoundingModeCheckBody = type { i32, i32 }

@_ZL8SseModes = external hidden local_unnamed_addr constant [4 x i32], align 16
@_ZL13RoundingModes = external hidden local_unnamed_addr constant [4 x i32], align 16
@.str.17 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [26 x i8], align 1

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z10SetSseModei(i32 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z15SetRoundingModei(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef, i32 noundef, i32 noundef, ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8), i32 noundef, i32 noundef) unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z26TestArenaFpuEnvPersistencei(i32 noundef %0) local_unnamed_addr #1 {
  %2 = alloca %class.RoundingModeCheckBody, align 4
  %3 = srem i32 %0, 4
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %4
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add nsw i32 %0, 1
  %10 = srem i32 %9, 4
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %11
  %13 = add nsw i32 %0, 2
  %14 = srem i32 %13, 4
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %15
  %17 = add nsw i32 %0, 3
  %18 = srem i32 %17, 4
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %19
  br label %22

21:                                               ; preds = %46
  ret void

22:                                               ; preds = %1, %46
  %.017 = phi i32 [ 0, %1 ], [ %47, %46 ]
  %23 = add nsw i32 %.017, %0
  %24 = srem i32 %23, 4
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  call void @_Z10SetSseModei(i32 noundef %27)
  call void @_Z15SetRoundingModei(i32 noundef %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef %6, i32 noundef %8)
  call void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef 0, i32 noundef 500000, i32 noundef 1, ptr noundef nonnull align 4 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %28 = call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %29 = icmp eq i32 %28, %6
  br i1 %29, label %31, label %30

30:                                               ; preds = %22
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 106, ptr noundef nonnull @.str.18, ptr noundef null)
  br label %31

31:                                               ; preds = %22, %30
  %32 = load i32, ptr %12, align 4, !tbaa !5
  call void @_Z15SetRoundingModei(i32 noundef %32)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef %6, i32 noundef %8)
  call void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef 0, i32 noundef 500000, i32 noundef 1, ptr noundef nonnull align 4 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %33 = call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %34 = icmp eq i32 %33, %32
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 106, ptr noundef nonnull @.str.18, ptr noundef null)
  br label %36

36:                                               ; preds = %35, %31
  %37 = load i32, ptr %16, align 4, !tbaa !5
  call void @_Z15SetRoundingModei(i32 noundef %37)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef %6, i32 noundef %8)
  call void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef 0, i32 noundef 500000, i32 noundef 1, ptr noundef nonnull align 4 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %38 = call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %39 = icmp eq i32 %38, %37
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 106, ptr noundef nonnull @.str.18, ptr noundef null)
  br label %41

41:                                               ; preds = %40, %36
  %42 = load i32, ptr %20, align 4, !tbaa !5
  call void @_Z15SetRoundingModei(i32 noundef %42)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  call void @_ZN21RoundingModeCheckBodyC2Eii(ptr noundef nonnull align 4 dereferenceable(8) %2, i32 noundef %6, i32 noundef %8)
  call void @_ZN3tbb10strict_ppl12parallel_forIi21RoundingModeCheckBodyEEvT_S3_S3_RKT0_(i32 noundef 0, i32 noundef 500000, i32 noundef 1, ptr noundef nonnull align 4 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %43 = call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %44 = icmp eq i32 %43, %42
  br i1 %44, label %46, label %45

45:                                               ; preds = %41
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 106, ptr noundef nonnull @.str.18, ptr noundef null)
  br label %46

46:                                               ; preds = %45, %41
  %47 = add nuw nsw i32 %.017, 1
  %exitcond.not = icmp eq i32 %47, 4
  br i1 %exitcond.not, label %21, label %22, !llvm.loop !9
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress 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 #4 = { inlinehint mustprogress 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 #5 = { 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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass