; LLVM IR from erincatto/box2d :: test (test_bitset)

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

@.str = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [68 x i8], align 1
@__PRETTY_FUNCTION__.BitSetTest = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @BitSetTest() #0 {
  %1 = alloca %struct.b2BitSet, align 8
  %2 = alloca [169 x i8], align 16
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 16, ptr %1) #6
  %8 = call { ptr, i64 } @b2CreateBitSet(i32 noundef 169)
  %9 = getelementptr inbounds { ptr, i64 }, ptr %1, i32 0, i32 0
  %10 = extractvalue { ptr, i64 } %8, 0
  store ptr %10, ptr %9, align 8
  %11 = getelementptr inbounds { ptr, i64 }, ptr %1, i32 0, i32 1
  %12 = extractvalue { ptr, i64 } %8, 1
  store i64 %12, ptr %11, align 8
  call void @b2SetBitCountAndClear(ptr noundef %1, i32 noundef 169)
  call void @llvm.lifetime.start.p0(i64 169, ptr %2) #6
  call void @llvm.memset.p0.i64(ptr align 16 %2, i8 0, i64 169, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 1, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %3, align 4, !tbaa !5
  call void @b2SetBit(ptr noundef %1, i32 noundef %13)
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [169 x i8], ptr %2, i64 0, i64 %15
  store i8 1, ptr %16, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %20, %0
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 169
  br i1 %19, label %20, label %30

20:                                               ; preds = %17
  %21 = load i32, ptr %4, align 4, !tbaa !5
  call void @b2SetBit(ptr noundef %1, i32 noundef %21)
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [169 x i8], ptr %2, i64 0, i64 %23
  store i8 1, ptr %24, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !5
  %27 = add nsw i32 %25, %26
  store i32 %27, ptr %5, align 4, !tbaa !5
  %28 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %28, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %29, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %17, !llvm.loop !11

30:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %57, %30
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = icmp slt i32 %32, 169
  br i1 %33, label %35, label %34

34:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %60

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #6
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = call zeroext i1 @b2GetBit(ptr noundef %1, i32 noundef %36)
  %38 = zext i1 %37 to i8
  store i8 %38, ptr %7, align 1, !tbaa !9
  br label %39

39:                                               ; preds = %35
  %40 = load i8, ptr %7, align 1, !tbaa !9, !range !13, !noundef !14
  %41 = trunc i8 %40 to i1
  %42 = zext i1 %41 to i32
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [169 x i8], ptr %2, i64 0, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !9, !range !13, !noundef !14
  %47 = trunc i8 %46 to i1
  %48 = zext i1 %47 to i32
  %49 = icmp eq i32 %42, %48
  %50 = zext i1 %49 to i32
  %51 = icmp eq i32 %50, 0
  br i1 %51, label %52, label %54

52:                                               ; preds = %39
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  call void @__assert_fail(ptr noundef @.str.1, ptr noundef @.str.2, i32 noundef 32, ptr noundef @__PRETTY_FUNCTION__.BitSetTest) #7
  unreachable

54:                                               ; preds = %39
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #6
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %6, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !5
  br label %31, !llvm.loop !15

60:                                               ; preds = %34
  call void @b2DestroyBitSet(ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 169, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %1) #6
  ret i32 0
}

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

declare { ptr, i64 } @b2CreateBitSet(i32 noundef) #2

declare void @b2SetBitCountAndClear(ptr noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @b2SetBit(ptr noundef, i32 noundef) #4

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @b2GetBit(ptr noundef, i32 noundef) #4

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #5

declare void @b2DestroyBitSet(ptr noundef) #2

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { noreturn 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 #6 = { nounwind }
attributes #7 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !12}


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

@.str = external hidden unnamed_addr constant [37 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [68 x i8], align 1
@__PRETTY_FUNCTION__.BitSetTest = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @BitSetTest() local_unnamed_addr #0 {
  %1 = alloca %struct.b2BitSet, align 8
  %2 = alloca [169 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %1) #7
  %3 = tail call { ptr, i64 } @b2CreateBitSet(i32 noundef 169) #7
  %4 = extractvalue { ptr, i64 } %3, 0
  store ptr %4, ptr %1, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 8
  %6 = extractvalue { ptr, i64 } %3, 1
  store i64 %6, ptr %5, align 8
  call void @b2SetBitCountAndClear(ptr noundef nonnull %1, i32 noundef 169) #7
  call void @llvm.lifetime.start.p0(i64 169, ptr nonnull %2) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(169) %2, i8 0, i64 169, i1 false)
  call void @b2SetBit(ptr noundef nonnull %1, i32 noundef 0)
  store i8 1, ptr %2, align 16, !tbaa !5
  br label %7

7:                                                ; preds = %0, %7
  %.017 = phi i32 [ 0, %0 ], [ %.01516, %7 ]
  %.01516 = phi i32 [ 1, %0 ], [ %10, %7 ]
  call void @b2SetBit(ptr noundef nonnull %1, i32 noundef %.01516)
  %8 = sext i32 %.01516 to i64
  %9 = getelementptr inbounds [169 x i8], ptr %2, i64 0, i64 %8
  store i8 1, ptr %9, align 1, !tbaa !5
  %10 = add nsw i32 %.017, %.01516
  %11 = icmp slt i32 %10, 169
  br i1 %11, label %7, label %.preheader, !llvm.loop !9

12:                                               ; preds = %.preheader
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 169
  br i1 %exitcond.not, label %13, label %.preheader, !llvm.loop !11

13:                                               ; preds = %12
  call void @b2DestroyBitSet(ptr noundef nonnull %1) #7
  call void @llvm.lifetime.end.p0(i64 169, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %1) #7
  ret i32 0

.preheader:                                       ; preds = %7, %12
  %indvars.iv = phi i64 [ %indvars.iv.next, %12 ], [ 0, %7 ]
  %14 = trunc nuw nsw i64 %indvars.iv to i32
  %15 = call zeroext i1 @b2GetBit(ptr noundef nonnull %1, i32 noundef %14)
  %16 = getelementptr inbounds [169 x i8], ptr %2, i64 0, i64 %indvars.iv
  %17 = load i8, ptr %16, align 1, !tbaa !5, !range !12, !noundef !13
  %18 = zext i1 %15 to i8
  %.not = icmp eq i8 %17, %18
  br i1 %.not, label %12, label %19

19:                                               ; preds = %.preheader
  %20 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  call void @__assert_fail(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, i32 noundef 32, ptr noundef nonnull @__PRETTY_FUNCTION__.BitSetTest) #8
  unreachable
}

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

declare { ptr, i64 } @b2CreateBitSet(i32 noundef) local_unnamed_addr #2

declare void @b2SetBitCountAndClear(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @b2SetBit(ptr noundef, i32 noundef) local_unnamed_addr #4

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @b2GetBit(ptr noundef, i32 noundef) local_unnamed_addr #4

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

declare void @b2DestroyBitSet(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { inlinehint 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 #5 = { 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 #6 = { noreturn 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 #7 = { nounwind }
attributes #8 = { noreturn 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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{i8 0, i8 2}
!13 = !{}


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