; LLVM IR from venumb/ZSPACE :: cpp/depends/alglib/cpp/tests/test_c.ll (Z15tester_functionPv)

; 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._s_testrecord = type { ptr, ptr }

@global_failure_flag = external dso_local global i32, align 4
@tests_lock = external dso_local global ptr, align 8
@print_lock = external dso_local global ptr, align 8
@unittests_processed = external dso_local global i32, align 4
@unittests = external dso_local global [88 x %struct._s_testrecord], align 16
@.str.856 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.857 = external hidden unnamed_addr constant [14 x i8], align 1
@stdout = external global ptr, align 8

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

declare i32 @printf(ptr noundef, ...) #1

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z13call_unittestPFbbPN11alglib_impl8ae_stateEEPi(ptr noundef, ptr noundef) #3

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

5:                                                ; preds = %40, %1
  call void @_Z12acquire_lockPPv(ptr noundef @tests_lock)
  %6 = load i32, ptr @unittests_processed, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [88 x %struct._s_testrecord], ptr @unittests, i64 0, i64 %7
  %9 = getelementptr inbounds %struct._s_testrecord, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 16, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %5
  call void @_Z12release_lockPPv(ptr noundef @tests_lock)
  br label %43

13:                                               ; preds = %5
  %14 = load i32, ptr @unittests_processed, align 4, !tbaa !9
  store i32 %14, ptr %3, align 4, !tbaa !9
  %15 = load i32, ptr @unittests_processed, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @unittests_processed, align 4, !tbaa !9
  call void @_Z12release_lockPPv(ptr noundef @tests_lock)
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [88 x %struct._s_testrecord], ptr @unittests, i64 0, i64 %18
  %20 = getelementptr inbounds %struct._s_testrecord, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = call noundef zeroext i1 @_Z13call_unittestPFbbPN11alglib_impl8ae_stateEEPi(ptr noundef %21, ptr noundef @global_failure_flag)
  %23 = zext i1 %22 to i8
  store i8 %23, ptr %4, align 1, !tbaa !14
  call void @_Z12acquire_lockPPv(ptr noundef @print_lock)
  %24 = load i8, ptr %4, align 1, !tbaa !14, !range !16, !noundef !17
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %33

26:                                               ; preds = %13
  %27 = load i32, ptr %3, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [88 x %struct._s_testrecord], ptr @unittests, i64 0, i64 %28
  %30 = getelementptr inbounds %struct._s_testrecord, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 16, !tbaa !11
  %32 = call i32 (ptr, ...) @printf(ptr noundef @.str.856, ptr noundef %31)
  br label %40

33:                                               ; preds = %13
  %34 = load i32, ptr %3, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [88 x %struct._s_testrecord], ptr @unittests, i64 0, i64 %35
  %37 = getelementptr inbounds %struct._s_testrecord, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 16, !tbaa !11
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.857, ptr noundef %38)
  br label %40

40:                                               ; preds = %33, %26
  %41 = load ptr, ptr @stdout, align 8, !tbaa !5
  %42 = call i32 @fflush(ptr noundef %41)
  call void @_Z12release_lockPPv(ptr noundef @print_lock)
  br label %5, !llvm.loop !18

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

declare i32 @fflush(ptr noundef) #1

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 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 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 = !{!"any pointer", !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, !6, i64 0}
!12 = !{!"_ZTS13_s_testrecord", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct._s_testrecord = type { ptr, ptr }

@global_failure_flag = external dso_local global i32, align 4
@tests_lock = external dso_local global ptr, align 8
@print_lock = external dso_local global ptr, align 8
@unittests_processed = external dso_local local_unnamed_addr global i32, align 4
@unittests = external dso_local local_unnamed_addr global [88 x %struct._s_testrecord], align 16
@.str.856 = external hidden unnamed_addr constant [10 x i8], align 1
@.str.857 = external hidden unnamed_addr constant [14 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z12acquire_lockPPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z12release_lockPPv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z13call_unittestPFbbPN11alglib_impl8ae_stateEEPi(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z15tester_functionPv(ptr nocapture noundef readnone %0) local_unnamed_addr #2 {
  tail call void @_Z12acquire_lockPPv(ptr noundef nonnull @tests_lock)
  %2 = load i32, ptr @unittests_processed, align 4, !tbaa !5
  %3 = sext i32 %2 to i64
  %4 = getelementptr inbounds [88 x %struct._s_testrecord], ptr @unittests, i64 0, i64 %3
  %5 = load ptr, ptr %4, align 16, !tbaa !9
  %6 = icmp eq ptr %5, null
  br i1 %6, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %1
  tail call void @_Z12release_lockPPv(ptr noundef nonnull @tests_lock)
  ret void

.lr.ph:                                           ; preds = %1, %.lr.ph
  %7 = phi ptr [ %19, %.lr.ph ], [ %4, %1 ]
  %8 = phi i32 [ %17, %.lr.ph ], [ %2, %1 ]
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @unittests_processed, align 4, !tbaa !5
  tail call void @_Z12release_lockPPv(ptr noundef nonnull @tests_lock)
  %10 = getelementptr inbounds i8, ptr %7, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = tail call noundef zeroext i1 @_Z13call_unittestPFbbPN11alglib_impl8ae_stateEEPi(ptr noundef %11, ptr noundef nonnull @global_failure_flag)
  tail call void @_Z12acquire_lockPPv(ptr noundef nonnull @print_lock)
  %13 = load ptr, ptr %7, align 16, !tbaa !9
  %.str.856..str.857 = select i1 %12, ptr @.str.856, ptr @.str.857
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) %.str.856..str.857, ptr noundef %13)
  %15 = load ptr, ptr @stdout, align 8, !tbaa !13
  %16 = tail call i32 @fflush(ptr noundef %15)
  tail call void @_Z12release_lockPPv(ptr noundef nonnull @print_lock)
  tail call void @_Z12acquire_lockPPv(ptr noundef nonnull @tests_lock)
  %17 = load i32, ptr @unittests_processed, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [88 x %struct._s_testrecord], ptr @unittests, i64 0, i64 %18
  %20 = load ptr, ptr %19, align 16, !tbaa !9
  %21 = icmp eq ptr %20, null
  br i1 %21, label %._crit_edge, label %.lr.ph, !llvm.loop !14
}

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #0

attributes #0 = { nofree nounwind "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 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 = { 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 = !{!10, !11, i64 0}
!10 = !{!"_ZTS13_s_testrecord", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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