; LLVM IR from erincatto/box2d :: src (contact)

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

; 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: nounwind uwtable
define dso_local zeroext i1 @b2ShouldShapesCollide(ptr noundef byval(%struct.b2Filter) align 8 %0, ptr noundef byval(%struct.b2Filter) align 8 %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca i8, align 1
  %5 = getelementptr inbounds %struct.b2Filter, ptr %0, i32 0, i32 2
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 2
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp eq i32 %6, %8
  br i1 %9, label %10, label %18

10:                                               ; preds = %2
  %11 = getelementptr inbounds %struct.b2Filter, ptr %0, i32 0, i32 2
  %12 = load i32, ptr %11, align 8, !tbaa !5
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %18

14:                                               ; preds = %10
  %15 = getelementptr inbounds %struct.b2Filter, ptr %0, i32 0, i32 2
  %16 = load i32, ptr %15, align 8, !tbaa !5
  %17 = icmp sgt i32 %16, 0
  store i1 %17, ptr %3, align 1
  br label %37

18:                                               ; preds = %10, %2
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %19 = getelementptr inbounds %struct.b2Filter, ptr %0, i32 0, i32 1
  %20 = load i64, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 0
  %22 = load i64, ptr %21, align 8, !tbaa !12
  %23 = and i64 %20, %22
  %24 = icmp ne i64 %23, 0
  br i1 %24, label %25, label %32

25:                                               ; preds = %18
  %26 = getelementptr inbounds %struct.b2Filter, ptr %0, i32 0, i32 0
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = and i64 %27, %29
  %31 = icmp ne i64 %30, 0
  br label %32

32:                                               ; preds = %25, %18
  %33 = phi i1 [ false, %18 ], [ %31, %25 ]
  %34 = zext i1 %33 to i8
  store i8 %34, ptr %4, align 1, !tbaa !13
  %35 = load i8, ptr %4, align 1, !tbaa !13, !range !15, !noundef !16
  %36 = trunc i8 %35 to i1
  store i1 %36, ptr %3, align 1
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  br label %37

37:                                               ; preds = %32, %14
  %38 = load i1, ptr %3, align 1
  ret i1 %38
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !10, i64 16}
!6 = !{!"b2Filter", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}


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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local zeroext i1 @b2ShouldShapesCollide(ptr nocapture noundef readonly byval(%struct.b2Filter) align 8 %0, ptr nocapture noundef readonly byval(%struct.b2Filter) align 8 %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i32, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr %1, i64 16
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %4, %6
  %8 = icmp ne i32 %4, 0
  %or.cond = and i1 %8, %7
  br i1 %or.cond, label %9, label %11

9:                                                ; preds = %2
  %10 = icmp sgt i32 %4, 0
  br label %23

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = load i64, ptr %1, align 8, !tbaa !12
  %15 = and i64 %14, %13
  %16 = icmp ne i64 %15, 0
  %17 = load i64, ptr %0, align 8
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load i64, ptr %18, align 8
  %20 = and i64 %19, %17
  %21 = icmp ne i64 %20, 0
  %22 = select i1 %16, i1 %21, i1 false
  br label %23

23:                                               ; preds = %11, %9
  %.0 = phi i1 [ %10, %9 ], [ %22, %11 ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !10, i64 16}
!6 = !{!"b2Filter", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass