; LLVM IR from MikeMirzayanov/testlib :: checkers/acmp.ll (Z11setTestCasei)

; 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.InStream = type { ptr, i32, %"class.std::__cxx11::basic_string", i32, i8, i8, i8, i32, %"class.std::__cxx11::basic_string", i32, i64, i64, i64 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@__testlib_hasTestCase = external dso_local global i8, align 1
@__testlib_testCase = external dso_local global i32, align 4
@inf = external dso_local global %struct.InStream, align 8
@testlibMode = external dso_local global i32, align 4
@_ZZ11setTestCaseiE9first_run = external hidden global i8, align 1
@_ZZ11setTestCaseiE10zero_based = external hidden global i8, align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8InStream11setTestCaseEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11setTestCasei(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %3 = load i8, ptr @_ZZ11setTestCaseiE9first_run, align 1, !tbaa !9, !range !11, !noundef !12
  %4 = trunc i8 %3 to i1
  br i1 %4, label %5, label %9

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

8:                                                ; preds = %5
  store i8 1, ptr @_ZZ11setTestCaseiE10zero_based, align 1, !tbaa !9
  br label %9

9:                                                ; preds = %8, %5, %1
  %10 = load i8, ptr @_ZZ11setTestCaseiE10zero_based, align 1, !tbaa !9, !range !11, !noundef !12
  %11 = trunc i8 %10 to i1
  br i1 %11, label %12, label %15

12:                                               ; preds = %9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr %2, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %12, %9
  store i8 1, ptr @__testlib_hasTestCase, align 1, !tbaa !9
  %16 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %16, ptr @__testlib_testCase, align 4, !tbaa !5
  %17 = load i32, ptr @testlibMode, align 4, !tbaa !13
  %18 = icmp eq i32 %17, 2
  br i1 %18, label %19, label %21

19:                                               ; preds = %15
  %20 = load i32, ptr %2, align 4, !tbaa !5
  call void @_ZN8InStream11setTestCaseEi(ptr noundef nonnull align 8 dereferenceable(128) @inf, i32 noundef %20)
  br label %21

21:                                               ; preds = %19, %15
  store i8 0, ptr @_ZZ11setTestCaseiE9first_run, align 1, !tbaa !9
  ret void
}

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

!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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS12TTestlibMode", !7, i64 0}


; 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.InStream = type { ptr, i32, %"class.std::__cxx11::basic_string", i32, i8, i8, i8, i32, %"class.std::__cxx11::basic_string", i32, i64, i64, i64 }
%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@__testlib_hasTestCase = external dso_local local_unnamed_addr global i8, align 1
@__testlib_testCase = external dso_local local_unnamed_addr global i32, align 4
@inf = external dso_local global %struct.InStream, align 8
@testlibMode = external dso_local local_unnamed_addr global i32, align 4
@_ZZ11setTestCaseiE9first_run = external hidden local_unnamed_addr global i8, align 1
@_ZZ11setTestCaseiE10zero_based = external hidden local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN8InStream11setTestCaseEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_Z11setTestCasei(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i8, ptr @_ZZ11setTestCaseiE9first_run, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  %4 = icmp eq i32 %0, 0
  %or.cond = and i1 %4, %3
  br i1 %or.cond, label %6, label %._crit_edge

._crit_edge:                                      ; preds = %1
  %.pre = load i8, ptr @_ZZ11setTestCaseiE10zero_based, align 1, !tbaa !5, !range !9
  %5 = zext nneg i8 %.pre to i32
  br label %7

6:                                                ; preds = %1
  store i8 1, ptr @_ZZ11setTestCaseiE10zero_based, align 1, !tbaa !5
  br label %7

7:                                                ; preds = %._crit_edge, %6
  %8 = phi i32 [ %5, %._crit_edge ], [ 1, %6 ]
  %spec.select = add nsw i32 %8, %0
  store i8 1, ptr @__testlib_hasTestCase, align 1, !tbaa !5
  store i32 %spec.select, ptr @__testlib_testCase, align 4, !tbaa !11
  %9 = load i32, ptr @testlibMode, align 4, !tbaa !13
  %10 = icmp eq i32 %9, 2
  br i1 %10, label %11, label %12

11:                                               ; preds = %7
  tail call void @_ZN8InStream11setTestCaseEi(ptr noundef nonnull align 8 dereferenceable(128) @inf, i32 noundef %spec.select)
  br label %12

12:                                               ; preds = %11, %7
  store i8 0, ptr @_ZZ11setTestCaseiE9first_run, align 1, !tbaa !5
  ret void
}

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

!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 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_ZTS12TTestlibMode", !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass