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

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

@_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.19 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [28 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: inlinehint mustprogress uwtable
declare dso_local noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16TestCpuCtlEnvApiv() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %44, %0
  %5 = load i32, ptr %1, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 4
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  store i32 2, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  br label %47

8:                                                ; preds = %4
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  call void @_Z10SetSseModei(i32 noundef %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %40, %8
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = icmp slt i32 %14, 4
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  store i32 5, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %43

17:                                               ; preds = %13
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  call void @_Z15SetRoundingModei(i32 noundef %21)
  %22 = call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x i32], ptr @_ZL13RoundingModes, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = icmp eq i32 %22, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %17
  br label %30

29:                                               ; preds = %17
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 135, ptr noundef @.str.19, ptr noundef null)
  br label %30

30:                                               ; preds = %29, %28
  %31 = call noundef i32 @_Z10GetSseModev()
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp eq i32 %31, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %30
  br label %39

38:                                               ; preds = %30
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.17, i32 noundef 136, ptr noundef @.str.20, ptr noundef null)
  br label %39

39:                                               ; preds = %38, %37
  br label %40

40:                                               ; preds = %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %3, align 4, !tbaa !5
  br label %13, !llvm.loop !9

43:                                               ; preds = %16
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %1, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %1, align 4, !tbaa !5
  br label %4, !llvm.loop !11

47:                                               ; preds = %7
  ret void
}

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

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 = { 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 #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++ 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"

@_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.19 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [28 x i8], align 1

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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16TestCpuCtlEnvApiv() local_unnamed_addr #0 {
  %.pre = load i32, ptr @_ZL13RoundingModes, align 16, !tbaa !5
  %1 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL13RoundingModes, i64 4), align 4
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL13RoundingModes, i64 8), align 8
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @_ZL13RoundingModes, i64 12), align 4
  br label %5

4:                                                ; preds = %39
  ret void

5:                                                ; preds = %0, %39
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %39 ]
  %6 = getelementptr inbounds [4 x i32], ptr @_ZL8SseModes, i64 0, i64 %indvars.iv
  %7 = load i32, ptr %6, align 4, !tbaa !5
  tail call void @_Z10SetSseModei(i32 noundef %7)
  tail call void @_Z15SetRoundingModei(i32 noundef %.pre)
  %8 = tail call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %9 = icmp eq i32 %8, %.pre
  br i1 %9, label %11, label %10

10:                                               ; preds = %5
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 135, ptr noundef nonnull @.str.19, ptr noundef null)
  br label %11

11:                                               ; preds = %5, %10
  %12 = tail call noundef i32 @_Z10GetSseModev()
  %13 = icmp eq i32 %12, %7
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 136, ptr noundef nonnull @.str.20, ptr noundef null)
  br label %15

15:                                               ; preds = %14, %11
  tail call void @_Z15SetRoundingModei(i32 noundef %1)
  %16 = tail call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %17 = icmp eq i32 %16, %1
  br i1 %17, label %19, label %18

18:                                               ; preds = %15
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 135, ptr noundef nonnull @.str.19, ptr noundef null)
  br label %19

19:                                               ; preds = %18, %15
  %20 = tail call noundef i32 @_Z10GetSseModev()
  %21 = icmp eq i32 %20, %7
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 136, ptr noundef nonnull @.str.20, ptr noundef null)
  br label %23

23:                                               ; preds = %22, %19
  tail call void @_Z15SetRoundingModei(i32 noundef %2)
  %24 = tail call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %25 = icmp eq i32 %24, %2
  br i1 %25, label %27, label %26

26:                                               ; preds = %23
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 135, ptr noundef nonnull @.str.19, ptr noundef null)
  br label %27

27:                                               ; preds = %26, %23
  %28 = tail call noundef i32 @_Z10GetSseModev()
  %29 = icmp eq i32 %28, %7
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 136, ptr noundef nonnull @.str.20, ptr noundef null)
  br label %31

31:                                               ; preds = %30, %27
  tail call void @_Z15SetRoundingModei(i32 noundef %3)
  %32 = tail call noundef i32 @_Z15GetRoundingModeb(i1 noundef zeroext true)
  %33 = icmp eq i32 %32, %3
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 135, ptr noundef nonnull @.str.19, ptr noundef null)
  br label %35

35:                                               ; preds = %34, %31
  %36 = tail call noundef i32 @_Z10GetSseModev()
  %37 = icmp eq i32 %36, %7
  br i1 %37, label %39, label %38

38:                                               ; preds = %35
  tail call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.17, i32 noundef 136, ptr noundef nonnull @.str.20, ptr noundef null)
  br label %39

39:                                               ; preds = %38, %35
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 4
  br i1 %exitcond.not, label %4, label %5, !llvm.loop !9
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z10GetSseModev() local_unnamed_addr #1

attributes #0 = { 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 #1 = { 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 #2 = { 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" }

!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,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,SROAPass,SimplifyCFGPass,TailCallElimPass