; LLVM IR from jdeokkim/ferox :: src (world)

; 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.frContextNode_ = type { i32, ptr }
%struct.frWorld_ = type { %struct.anon, %struct.anon.0, ptr, ptr, float, float, %struct.frCollisionHandler_, %struct.frVector2_ }
%struct.anon = type { ptr, i64, i64 }
%struct.anon.0 = type { ptr, i64, i32, i32 }
%struct.frCollisionHandler_ = type { ptr, ptr }
%struct.frVector2_ = type { float, float }

; 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) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @frAddBodyToWorld(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.frContextNode_, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %18, label %9

9:                                                ; preds = %2
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %18, label %12

12:                                               ; preds = %9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.frWorld_, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.anon, ptr %14, i32 0, i32 1
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = icmp uge i64 %16, 2048
  br i1 %17, label %18, label %19

18:                                               ; preds = %12, %9, %2
  store i1 false, ptr %3, align 1
  br label %72

19:                                               ; preds = %12
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.frWorld_, ptr %20, i32 0, i32 1
  %22 = getelementptr inbounds %struct.anon.0, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !18
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.frWorld_, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.anon.0, ptr %27, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !19
  %30 = sub i64 %29, 1
  %31 = and i64 %25, %30
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.frWorld_, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %struct.anon.0, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !20
  %36 = sext i32 %35 to i64
  %37 = icmp ne i64 %31, %36
  br i1 %37, label %38, label %68

38:                                               ; preds = %19
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.frWorld_, ptr %39, i32 0, i32 1
  %41 = getelementptr inbounds %struct.anon.0, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.frWorld_, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds %struct.anon.0, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 8, !tbaa !18
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.frContextNode_, ptr %42, i64 %47
  %49 = getelementptr inbounds %struct.frContextNode_, ptr %6, i32 0, i32 0
  store i32 1, ptr %49, align 8, !tbaa !22
  %50 = getelementptr inbounds %struct.frContextNode_, ptr %6, i32 0, i32 1
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %51, ptr %50, align 8, !tbaa !24
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %48, ptr align 8 %6, i64 16, i1 false), !tbaa.struct !25
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.frWorld_, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.anon.0, ptr %53, i32 0, i32 2
  %55 = load i32, ptr %54, align 8, !tbaa !18
  %56 = add nsw i32 %55, 1
  %57 = sext i32 %56 to i64
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.frWorld_, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.anon.0, ptr %59, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !19
  %62 = sub i64 %61, 1
  %63 = and i64 %57, %62
  %64 = trunc i64 %63 to i32
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.frWorld_, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.anon.0, ptr %66, i32 0, i32 2
  store i32 %64, ptr %67, align 8, !tbaa !18
  br label %69

68:                                               ; preds = %19
  br label %69

69:                                               ; preds = %68, %38
  %70 = phi i32 [ 1, %38 ], [ 0, %68 ]
  %71 = icmp ne i32 %70, 0
  store i1 %71, ptr %3, align 1
  br label %72

72:                                               ; preds = %69, %18
  %73 = load i1, ptr %3, align 1
  ret i1 %73
}

attributes #0 = { nocallback nofree 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" }

!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/C++ TBAA"}
!9 = !{!10, !12, i64 8}
!10 = !{!"frWorld_", !11, i64 0, !13, i64 24, !6, i64 48, !6, i64 56, !15, i64 64, !15, i64 68, !16, i64 72, !17, i64 88}
!11 = !{!"", !6, i64 0, !12, i64 8, !12, i64 16}
!12 = !{!"long", !7, i64 0}
!13 = !{!"", !6, i64 0, !12, i64 8, !14, i64 16, !14, i64 20}
!14 = !{!"int", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!"frCollisionHandler_", !6, i64 0, !6, i64 8}
!17 = !{!"frVector2_", !15, i64 0, !15, i64 4}
!18 = !{!10, !14, i64 40}
!19 = !{!10, !12, i64 32}
!20 = !{!10, !14, i64 44}
!21 = !{!10, !6, i64 24}
!22 = !{!23, !14, i64 0}
!23 = !{!"frContextNode_", !14, i64 0, !6, i64 8}
!24 = !{!23, !6, i64 8}
!25 = !{i64 0, i64 4, !26, i64 8, i64 8, !5}
!26 = !{!14, !14, 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.frContextNode_ = type { i32, ptr }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @frAddBodyToWorld(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = icmp eq ptr %0, null
  %4 = icmp eq ptr %1, null
  %or.cond = or i1 %3, %4
  br i1 %or.cond, label %31, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = icmp ugt i64 %7, 2047
  br i1 %8, label %31, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 40
  %11 = load i32, ptr %10, align 8, !tbaa !17
  %12 = add nsw i32 %11, 1
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i64, ptr %14, align 8, !tbaa !18
  %16 = add i64 %15, -1
  %17 = and i64 %16, %13
  %18 = getelementptr inbounds i8, ptr %0, i64 44
  %19 = load i32, ptr %18, align 4, !tbaa !19
  %20 = sext i32 %19 to i64
  %.not.not = icmp eq i64 %17, %20
  br i1 %.not.not, label %31, label %21

21:                                               ; preds = %9
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = sext i32 %11 to i64
  %25 = getelementptr inbounds %struct.frContextNode_, ptr %23, i64 %24
  store i32 1, ptr %25, align 8, !tbaa !21
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %25, i64 8
  store ptr %1, ptr %.sroa.22.0..sroa_idx, align 8, !tbaa !22
  %26 = load i32, ptr %10, align 8, !tbaa !17
  %27 = add nsw i32 %26, 1
  %28 = trunc i64 %15 to i32
  %29 = add i32 %28, -1
  %30 = and i32 %27, %29
  store i32 %30, ptr %10, align 8, !tbaa !17
  br label %31

31:                                               ; preds = %21, %9, %2, %5
  %.0 = phi i1 [ false, %5 ], [ false, %2 ], [ false, %9 ], [ true, %21 ]
  ret i1 %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) 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, !11, i64 8}
!6 = !{!"frWorld_", !7, i64 0, !12, i64 24, !8, i64 48, !8, i64 56, !14, i64 64, !14, i64 68, !15, i64 72, !16, i64 88}
!7 = !{!"", !8, i64 0, !11, i64 8, !11, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"", !8, i64 0, !11, i64 8, !13, i64 16, !13, i64 20}
!13 = !{!"int", !9, i64 0}
!14 = !{!"float", !9, i64 0}
!15 = !{!"frCollisionHandler_", !8, i64 0, !8, i64 8}
!16 = !{!"frVector2_", !14, i64 0, !14, i64 4}
!17 = !{!6, !13, i64 40}
!18 = !{!6, !11, i64 32}
!19 = !{!6, !13, i64 44}
!20 = !{!6, !8, i64 24}
!21 = !{!13, !13, i64 0}
!22 = !{!8, !8, i64 0}


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