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

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

@.str.18 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.84 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.85 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.86 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.87 = external hidden unnamed_addr constant [58 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: mustprogress uwtable
define dso_local void @_Z14TestEndiannessv() #1 {
  %1 = alloca i8, align 1
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #3
  store i8 1, ptr %1, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #3
  store i8 1, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 50462976, ptr %3, align 4, !tbaa !9
  %7 = call noundef zeroext i1 @_ZN3tbb8internal10is_alignedIKjEEbPT_m(ptr noundef %3, i64 noundef 4)
  br i1 %7, label %8, label %9

8:                                                ; preds = %0
  br label %10

9:                                                ; preds = %0
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.18, i32 noundef 766, ptr noundef @.str.84, ptr noundef null)
  br label %10

10:                                               ; preds = %9, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store ptr %3, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !11
  store ptr %11, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %12, i64 4
  store ptr %13, ptr %6, align 8, !tbaa !11
  br label %14

14:                                               ; preds = %43, %10
  %15 = load ptr, ptr %5, align 8, !tbaa !11
  %16 = load ptr, ptr %6, align 8, !tbaa !11
  %17 = icmp ne ptr %15, %16
  br i1 %17, label %19, label %18

18:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %46

19:                                               ; preds = %14
  %20 = load ptr, ptr %5, align 8, !tbaa !11
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %22 = sext i8 %21 to i64
  %23 = load ptr, ptr %6, align 8, !tbaa !11
  %24 = getelementptr inbounds i8, ptr %23, i64 -1
  %25 = load ptr, ptr %5, align 8, !tbaa !11
  %26 = ptrtoint ptr %24 to i64
  %27 = ptrtoint ptr %25 to i64
  %28 = sub i64 %26, %27
  %29 = icmp ne i64 %22, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %19
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %31

31:                                               ; preds = %30, %19
  %32 = load ptr, ptr %5, align 8, !tbaa !11
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = sext i8 %33 to i64
  %35 = load ptr, ptr %5, align 8, !tbaa !11
  %36 = load ptr, ptr %4, align 8, !tbaa !11
  %37 = ptrtoint ptr %35 to i64
  %38 = ptrtoint ptr %36 to i64
  %39 = sub i64 %37, %38
  %40 = icmp ne i64 %34, %39
  br i1 %40, label %41, label %42

41:                                               ; preds = %31
  store i8 0, ptr %2, align 1, !tbaa !5
  br label %42

42:                                               ; preds = %41, %31
  br label %43

43:                                               ; preds = %42
  %44 = load ptr, ptr %5, align 8, !tbaa !11
  %45 = getelementptr inbounds i8, ptr %44, i32 1
  store ptr %45, ptr %5, align 8, !tbaa !11
  br label %14, !llvm.loop !14

46:                                               ; preds = %18
  %47 = load i8, ptr %1, align 1, !tbaa !5, !range !16, !noundef !17
  %48 = trunc i8 %47 to i1
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load i8, ptr %2, align 1, !tbaa !5, !range !16, !noundef !17
  %51 = trunc i8 %50 to i1
  br i1 %51, label %53, label %52

52:                                               ; preds = %49, %46
  br label %54

53:                                               ; preds = %49
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.18, i32 noundef 773, ptr noundef @.str.85, ptr noundef null)
  br label %54

54:                                               ; preds = %53, %52
  %55 = load i8, ptr %2, align 1, !tbaa !5, !range !16, !noundef !17
  %56 = trunc i8 %55 to i1
  br i1 %56, label %57, label %58

57:                                               ; preds = %54
  br label %59

58:                                               ; preds = %54
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef @.str.18, i32 noundef 779, ptr noundef @.str.86, ptr noundef @.str.87)
  br label %59

59:                                               ; preds = %58, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3tbb8internal10is_alignedIKjEEbPT_m(ptr noundef, i64 noundef) #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 = { 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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{i8 0, i8 2}
!17 = !{}


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

@.str.18 = external hidden unnamed_addr constant [87 x i8], align 1
@.str.84 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.86 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.87 = external hidden unnamed_addr constant [58 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: mustprogress uwtable
define dso_local void @_Z14TestEndiannessv() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  store i32 50462976, ptr %1, align 4, !tbaa !5
  %2 = call noundef zeroext i1 @_ZN3tbb8internal10is_alignedIKjEEbPT_m(ptr noundef nonnull %1, i64 noundef 4)
  br i1 %2, label %._crit_edge, label %3

3:                                                ; preds = %0
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.18, i32 noundef 766, ptr noundef nonnull @.str.84, ptr noundef null)
  br label %._crit_edge

._crit_edge:                                      ; preds = %0, %3
  %4 = load <4 x i8>, ptr %1, align 4, !tbaa !9
  %.fr = freeze <4 x i8> %4
  %.fr.scalar = bitcast <4 x i8> %.fr to i32
  %5 = icmp eq i32 %.fr.scalar, 50462976
  br i1 %5, label %7, label %6

6:                                                ; preds = %._crit_edge
  call void @_Z11ReportErrorPKciS0_S0_(ptr noundef nonnull @.str.18, i32 noundef 779, ptr noundef nonnull @.str.86, ptr noundef nonnull @.str.87)
  br label %7

7:                                                ; preds = %._crit_edge, %6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN3tbb8internal10is_alignedIKjEEbPT_m(ptr noundef, i64 noundef) local_unnamed_addr #2

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 = { 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 = !{!7, !7, i64 0}


; Effective O3 passes: ADCEPass,AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalDCEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass