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

; 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 }
%struct.b2ShapeId = type { i32, i16, i16 }
%struct.b2Shape = type { i32, i32, i32, i32, i32, i32, float, float, float, float, float, i32, %struct.b2AABB, %struct.b2AABB, %struct.b2Vec2, i32, %struct.b2Filter, ptr, i32, %union.anon.0, i16, i8, i8, i8, i8, i8 }
%struct.b2AABB = type { %struct.b2Vec2, %struct.b2Vec2 }
%struct.b2Vec2 = type { float, float }
%union.anon.0 = type { %struct.b2Polygon }
%struct.b2Polygon = type { [8 x %struct.b2Vec2], [8 x %struct.b2Vec2], %struct.b2Vec2, float, 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare ptr @b2GetWorldLocked(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @b2GetShape(ptr noundef, i64) #3

; Function Attrs: nounwind uwtable
define dso_local void @b2Shape_SetFilter(i64 %0, ptr noundef byval(%struct.b2Filter) align 8 %1) #3 {
  %3 = alloca %struct.b2ShapeId, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i8, align 1
  store i64 %0, ptr %3, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %9 = getelementptr inbounds %struct.b2ShapeId, ptr %3, i32 0, i32 1
  %10 = load i16, ptr %9, align 4, !tbaa !5
  %11 = zext i16 %10 to i32
  %12 = call ptr @b2GetWorldLocked(i32 noundef %11)
  store ptr %12, ptr %4, align 8, !tbaa !11
  %13 = load ptr, ptr %4, align 8, !tbaa !11
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store i32 1, ptr %5, align 4
  br label %62

16:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %17 = load ptr, ptr %4, align 8, !tbaa !11
  %18 = load i64, ptr %3, align 4
  %19 = call ptr @b2GetShape(ptr noundef %17, i64 %18)
  store ptr %19, ptr %6, align 8, !tbaa !11
  %20 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = load ptr, ptr %6, align 8, !tbaa !11
  %23 = getelementptr inbounds %struct.b2Shape, ptr %22, i32 0, i32 16
  %24 = getelementptr inbounds %struct.b2Filter, ptr %23, i32 0, i32 1
  %25 = load i64, ptr %24, align 8, !tbaa !16
  %26 = icmp eq i64 %21, %25
  br i1 %26, label %27, label %44

27:                                               ; preds = %16
  %28 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !22
  %30 = load ptr, ptr %6, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.b2Shape, ptr %30, i32 0, i32 16
  %32 = getelementptr inbounds %struct.b2Filter, ptr %31, i32 0, i32 0
  %33 = load i64, ptr %32, align 8, !tbaa !23
  %34 = icmp eq i64 %29, %33
  br i1 %34, label %35, label %44

35:                                               ; preds = %27
  %36 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 2
  %37 = load i32, ptr %36, align 8, !tbaa !24
  %38 = load ptr, ptr %6, align 8, !tbaa !11
  %39 = getelementptr inbounds %struct.b2Shape, ptr %38, i32 0, i32 16
  %40 = getelementptr inbounds %struct.b2Filter, ptr %39, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !25
  %42 = icmp eq i32 %37, %41
  br i1 %42, label %43, label %44

43:                                               ; preds = %35
  store i32 1, ptr %5, align 4
  br label %61

44:                                               ; preds = %35, %27, %16
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  %45 = getelementptr inbounds %struct.b2Filter, ptr %1, i32 0, i32 0
  %46 = load i64, ptr %45, align 8, !tbaa !22
  %47 = load ptr, ptr %6, align 8, !tbaa !11
  %48 = getelementptr inbounds %struct.b2Shape, ptr %47, i32 0, i32 16
  %49 = getelementptr inbounds %struct.b2Filter, ptr %48, i32 0, i32 0
  %50 = load i64, ptr %49, align 8, !tbaa !23
  %51 = icmp ne i64 %46, %50
  %52 = zext i1 %51 to i8
  store i8 %52, ptr %7, align 1, !tbaa !26
  %53 = load ptr, ptr %6, align 8, !tbaa !11
  %54 = getelementptr inbounds %struct.b2Shape, ptr %53, i32 0, i32 16
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %54, ptr align 8 %1, i64 24, i1 false), !tbaa.struct !27
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #5
  store i8 1, ptr %8, align 1, !tbaa !26
  %55 = load ptr, ptr %4, align 8, !tbaa !11
  %56 = load ptr, ptr %6, align 8, !tbaa !11
  %57 = load i8, ptr %8, align 1, !tbaa !26, !range !30, !noundef !31
  %58 = trunc i8 %57 to i1
  %59 = load i8, ptr %7, align 1, !tbaa !26, !range !30, !noundef !31
  %60 = trunc i8 %59 to i1
  call void @b2ResetProxy(ptr noundef %55, ptr noundef %56, i1 noundef zeroext %58, i1 noundef zeroext %60)
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  store i32 0, ptr %5, align 4
  br label %61

61:                                               ; preds = %44, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  br label %62

62:                                               ; preds = %61, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %63 = load i32, ptr %5, align 4
  switch i32 %63, label %65 [
    i32 0, label %64
    i32 1, label %64
  ]

64:                                               ; preds = %62, %62
  ret void

65:                                               ; preds = %62
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden void @b2ResetProxy(ptr noundef, ptr noundef, i1 noundef zeroext, i1 noundef zeroext) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree 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 = { 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 #4 = { nounwind uwtable "min-legal-vector-width"="64" "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 = { 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 4}
!6 = !{!"b2ShapeId", !7, i64 0, !10, i64 4, !10, i64 6}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!14, !15, i64 8}
!14 = !{!"b2Filter", !15, i64 0, !15, i64 8, !7, i64 16}
!15 = !{!"long", !8, i64 0}
!16 = !{!17, !15, i64 104}
!17 = !{!"b2Shape", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !18, i64 24, !18, i64 28, !18, i64 32, !18, i64 36, !18, i64 40, !7, i64 44, !19, i64 48, !19, i64 64, !20, i64 80, !7, i64 88, !14, i64 96, !12, i64 120, !7, i64 128, !8, i64 132, !10, i64 276, !21, i64 278, !21, i64 279, !21, i64 280, !21, i64 281, !21, i64 282}
!18 = !{!"float", !8, i64 0}
!19 = !{!"b2AABB", !20, i64 0, !20, i64 8}
!20 = !{!"b2Vec2", !18, i64 0, !18, i64 4}
!21 = !{!"_Bool", !8, i64 0}
!22 = !{!14, !15, i64 0}
!23 = !{!17, !15, i64 96}
!24 = !{!14, !7, i64 16}
!25 = !{!17, !7, i64 112}
!26 = !{!21, !21, i64 0}
!27 = !{i64 0, i64 8, !28, i64 8, i64 8, !28, i64 16, i64 4, !29}
!28 = !{!15, !15, i64 0}
!29 = !{!7, !7, i64 0}
!30 = !{i8 0, i8 2}
!31 = !{}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

declare ptr @b2GetWorldLocked(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @b2GetShape(ptr noundef, i64) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @b2Shape_SetFilter(i64 %0, ptr nocapture noundef readonly byval(%struct.b2Filter) align 8 %1) local_unnamed_addr #2 {
  %.sroa.2.0.extract.shift = lshr i64 %0, 32
  %3 = trunc nuw i64 %.sroa.2.0.extract.shift to i32
  %4 = and i32 %3, 65535
  %5 = tail call ptr @b2GetWorldLocked(i32 noundef %4) #4
  %6 = icmp eq ptr %5, null
  br i1 %6, label %24, label %7

7:                                                ; preds = %2
  %8 = tail call ptr @b2GetShape(ptr noundef nonnull %5, i64 %0)
  %9 = getelementptr inbounds i8, ptr %1, i64 8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %8, i64 96
  %12 = getelementptr inbounds i8, ptr %8, i64 104
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = icmp eq i64 %10, %13
  %.pre = load i64, ptr %1, align 8, !tbaa !19
  %.pre10 = load i64, ptr %11, align 8, !tbaa !20
  %15 = icmp eq i64 %.pre, %.pre10
  %or.cond = select i1 %14, i1 %15, i1 false
  br i1 %or.cond, label %16, label %22

16:                                               ; preds = %7
  %17 = getelementptr inbounds i8, ptr %1, i64 16
  %18 = load i32, ptr %17, align 8, !tbaa !21
  %19 = getelementptr inbounds i8, ptr %8, i64 112
  %20 = load i32, ptr %19, align 8, !tbaa !22
  %21 = icmp eq i32 %18, %20
  br i1 %21, label %24, label %22

22:                                               ; preds = %16, %7
  %23 = icmp ne i64 %.pre, %.pre10
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %11, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 24, i1 false), !tbaa.struct !23
  tail call void @b2ResetProxy(ptr noundef nonnull %5, ptr noundef nonnull %8, i1 noundef zeroext true, i1 noundef zeroext %23)
  br label %24

24:                                               ; preds = %22, %16, %2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @b2ResetProxy(ptr noundef, ptr noundef, i1 noundef zeroext, i1 noundef zeroext) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree 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 = { 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 = { nounwind uwtable "min-legal-vector-width"="64" "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, !7, i64 8}
!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 = !{!12, !7, i64 104}
!12 = !{!"b2Shape", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !10, i64 44, !14, i64 48, !14, i64 64, !15, i64 80, !10, i64 88, !6, i64 96, !16, i64 120, !10, i64 128, !8, i64 132, !17, i64 276, !18, i64 278, !18, i64 279, !18, i64 280, !18, i64 281, !18, i64 282}
!13 = !{!"float", !8, i64 0}
!14 = !{!"b2AABB", !15, i64 0, !15, i64 8}
!15 = !{!"b2Vec2", !13, i64 0, !13, i64 4}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"short", !8, i64 0}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{!6, !7, i64 0}
!20 = !{!12, !7, i64 96}
!21 = !{!6, !10, i64 16}
!22 = !{!12, !10, i64 112}
!23 = !{i64 0, i64 8, !24, i64 8, i64 8, !24, i64 16, i64 4, !25}
!24 = !{!7, !7, i64 0}
!25 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass