; LLVM IR from turi-code/SFrame :: cxxtest/cxxtest/RealDescriptions.ll (ZN7CxxTest20RealWorldDescription8tearDownEv)

; 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.3 = external hidden unnamed_addr constant [25 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

declare noundef ptr @_ZN7CxxTest13GlobalFixture17lastGlobalFixtureEv() #1

declare noundef ptr @_ZN7CxxTest13GlobalFixture17prevGlobalFixtureEv(ptr noundef nonnull align 8 dereferenceable(25)) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7CxxTest20RealWorldDescription11reportErrorEPKc(ptr noundef) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7CxxTest20RealWorldDescription8tearDownEv(ptr noundef nonnull align 8 dereferenceable(25) %0) #2 align 2 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i8, align 1
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %8 = call noundef ptr @_ZN7CxxTest13GlobalFixture17lastGlobalFixtureEv()
  store ptr %8, ptr %4, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %27, %1
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp ne ptr %10, null
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %5, align 4
  br label %30

13:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #3
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = getelementptr inbounds ptr, ptr %15, i64 3
  %17 = load ptr, ptr %16, align 8
  %18 = call noundef zeroext i1 %17(ptr noundef nonnull align 8 dereferenceable(25) %14)
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %6, align 1, !tbaa !11
  %20 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  br i1 %21, label %23, label %22

22:                                               ; preds = %13
  call void @_ZN7CxxTest20RealWorldDescription11reportErrorEPKc(ptr noundef @.str.3)
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %24

23:                                               ; preds = %13
  store i32 0, ptr %5, align 4
  br label %24

24:                                               ; preds = %23, %22
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #3
  %25 = load i32, ptr %5, align 4
  switch i32 %25, label %30 [
    i32 0, label %26
  ]

26:                                               ; preds = %24
  br label %27

27:                                               ; preds = %26
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call noundef ptr @_ZN7CxxTest13GlobalFixture17prevGlobalFixtureEv(ptr noundef nonnull align 8 dereferenceable(25) %28)
  store ptr %29, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !15

30:                                               ; preds = %24, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %31 = load i32, ptr %5, align 4
  switch i32 %31, label %35 [
    i32 2, label %32
    i32 1, label %33
  ]

32:                                               ; preds = %30
  store i1 true, ptr %2, align 1
  br label %33

33:                                               ; preds = %32, %30
  %34 = load i1, ptr %2, align 1
  ret i1 %34

35:                                               ; preds = %30
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@.str.3 = external hidden unnamed_addr constant [25 x i8], align 1

declare noundef ptr @_ZN7CxxTest13GlobalFixture17lastGlobalFixtureEv() local_unnamed_addr #0

declare noundef ptr @_ZN7CxxTest13GlobalFixture17prevGlobalFixtureEv(ptr noundef nonnull align 8 dereferenceable(25)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN7CxxTest20RealWorldDescription11reportErrorEPKc(ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN7CxxTest20RealWorldDescription8tearDownEv(ptr nocapture noundef nonnull readnone align 8 dereferenceable(25) %0) local_unnamed_addr #1 align 2 {
  %2 = tail call noundef ptr @_ZN7CxxTest13GlobalFixture17lastGlobalFixtureEv()
  %.not12 = icmp eq ptr %2, null
  br i1 %.not12, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.critedge
  %.0913 = phi ptr [ %8, %.critedge ], [ %2, %1 ]
  %3 = load ptr, ptr %.0913, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 24
  %5 = load ptr, ptr %4, align 8
  %6 = tail call noundef zeroext i1 %5(ptr noundef nonnull align 8 dereferenceable(25) %.0913)
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %.lr.ph
  tail call void @_ZN7CxxTest20RealWorldDescription11reportErrorEPKc(ptr noundef nonnull @.str.3)
  br label %.loopexit

.critedge:                                        ; preds = %.lr.ph
  %8 = tail call noundef ptr @_ZN7CxxTest13GlobalFixture17prevGlobalFixtureEv(ptr noundef nonnull align 8 dereferenceable(25) %.0913)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !8

.loopexit:                                        ; preds = %.critedge, %1, %7
  %.not11 = phi i1 [ false, %7 ], [ true, %1 ], [ true, %.critedge ]
  ret i1 %.not11
}

attributes #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 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass