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

; 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.b2BodyId = type { i32, i16, i16 }
%struct.b2BodySim = type { %struct.b2Transform, %struct.b2Vec2, %struct.b2Rot, %struct.b2Vec2, %struct.b2Vec2, %struct.b2Vec2, float, float, float, float, float, float, float, float, i32, i8, i8, i8, i8, i8 }
%struct.b2Transform = type { %struct.b2Vec2, %struct.b2Rot }
%struct.b2Rot = type { float, float }
%struct.b2Vec2 = type { float, float }

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodyFullId(ptr noundef, i64) #0

declare zeroext i1 @b2Body_IsValid(i64) #1

declare i32 @b2InternalAssertFcn(ptr noundef, ptr noundef, i32 noundef) #1

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodySim(ptr noundef, ptr noundef) #0

declare zeroext i1 @b2IsValidFloat(float noundef) #1

declare ptr @b2GetWorldLocked(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @b2Body_SetGravityScale(i64 %0, float noundef %1) #0 {
  %3 = alloca %struct.b2BodyId, align 4
  %4 = alloca float, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store i64 %0, ptr %3, align 4
  store float %1, ptr %4, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %2
  %10 = load i64, ptr %3, align 4
  %11 = call zeroext i1 @b2Body_IsValid(i64 %10)
  br i1 %11, label %16, label %12

12:                                               ; preds = %9
  %13 = call i32 @b2InternalAssertFcn(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 1440)
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  call void @llvm.trap()
  br label %16

16:                                               ; preds = %15, %12, %9
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  %19 = load float, ptr %4, align 4, !tbaa !5
  %20 = call zeroext i1 @b2IsValidFloat(float noundef %19)
  br i1 %20, label %25, label %21

21:                                               ; preds = %18
  %22 = call i32 @b2InternalAssertFcn(ptr noundef @.str.37, ptr noundef @.str.1, i32 noundef 1441)
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  call void @llvm.trap()
  br label %25

25:                                               ; preds = %24, %21, %18
  br label %26

26:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %27 = getelementptr inbounds %struct.b2BodyId, ptr %3, i32 0, i32 1
  %28 = load i16, ptr %27, align 4, !tbaa !9
  %29 = zext i16 %28 to i32
  %30 = call ptr @b2GetWorldLocked(i32 noundef %29)
  store ptr %30, ptr %5, align 8, !tbaa !13
  %31 = load ptr, ptr %5, align 8, !tbaa !13
  %32 = icmp eq ptr %31, null
  br i1 %32, label %33, label %34

33:                                               ; preds = %26
  store i32 1, ptr %6, align 4
  br label %44

34:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %35 = load ptr, ptr %5, align 8, !tbaa !13
  %36 = load i64, ptr %3, align 4
  %37 = call ptr @b2GetBodyFullId(ptr noundef %35, i64 %36)
  store ptr %37, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %38 = load ptr, ptr %5, align 8, !tbaa !13
  %39 = load ptr, ptr %7, align 8, !tbaa !13
  %40 = call ptr @b2GetBodySim(ptr noundef %38, ptr noundef %39)
  store ptr %40, ptr %8, align 8, !tbaa !13
  %41 = load float, ptr %4, align 4, !tbaa !5
  %42 = load ptr, ptr %8, align 8, !tbaa !13
  %43 = getelementptr inbounds %struct.b2BodySim, ptr %42, i32 0, i32 13
  store float %41, ptr %43, align 4, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  store i32 0, ptr %6, align 4
  br label %44

44:                                               ; preds = %34, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %45 = load i32, ptr %6, align 4
  switch i32 %45, label %47 [
    i32 0, label %46
    i32 1, label %46
  ]

46:                                               ; preds = %44, %44
  ret void

47:                                               ; preds = %44
  unreachable
}

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 = { "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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 4}
!10 = !{!"b2BodyId", !11, i64 0, !12, i64 4, !12, i64 6}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = !{!16, !6, i64 84}
!16 = !{!"b2BodySim", !17, i64 0, !18, i64 16, !19, i64 24, !18, i64 32, !18, i64 40, !18, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !6, i64 68, !6, i64 72, !6, i64 76, !6, i64 80, !6, i64 84, !11, i64 88, !20, i64 92, !20, i64 93, !20, i64 94, !20, i64 95, !20, i64 96}
!17 = !{!"b2Transform", !18, i64 0, !19, i64 8}
!18 = !{!"b2Vec2", !6, i64 0, !6, i64 4}
!19 = !{!"b2Rot", !6, i64 0, !6, i64 4}
!20 = !{!"_Bool", !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"

@.str = external hidden unnamed_addr constant [25 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [60 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [31 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodyFullId(ptr noundef, i64) local_unnamed_addr #0

declare zeroext i1 @b2Body_IsValid(i64) local_unnamed_addr #1

declare i32 @b2InternalAssertFcn(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: cold noreturn nounwind memory(inaccessiblemem: write)
declare void @llvm.trap() #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @b2GetBodySim(ptr noundef, ptr noundef) local_unnamed_addr #0

declare zeroext i1 @b2IsValidFloat(float noundef) local_unnamed_addr #1

declare ptr @b2GetWorldLocked(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @b2Body_SetGravityScale(i64 %0, float noundef %1) local_unnamed_addr #0 {
  %.sroa.3.0.extract.shift = lshr i64 %0, 32
  %.sroa.3.0.extract.trunc = trunc nuw i64 %.sroa.3.0.extract.shift to i32
  %3 = tail call zeroext i1 @b2Body_IsValid(i64 %0) #3
  br i1 %3, label %7, label %4

4:                                                ; preds = %2
  %5 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 1440) #3
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %7, label %6

6:                                                ; preds = %4
  tail call void @llvm.trap()
  unreachable

7:                                                ; preds = %4, %2
  %8 = tail call zeroext i1 @b2IsValidFloat(float noundef %1) #3
  br i1 %8, label %12, label %9

9:                                                ; preds = %7
  %10 = tail call i32 @b2InternalAssertFcn(ptr noundef nonnull @.str.37, ptr noundef nonnull @.str.1, i32 noundef 1441) #3
  %.not21 = icmp eq i32 %10, 0
  br i1 %.not21, label %12, label %11

11:                                               ; preds = %9
  tail call void @llvm.trap()
  unreachable

12:                                               ; preds = %7, %9
  %13 = and i32 %.sroa.3.0.extract.trunc, 65535
  %14 = tail call ptr @b2GetWorldLocked(i32 noundef %13) #3
  %15 = icmp eq ptr %14, null
  br i1 %15, label %20, label %16

16:                                               ; preds = %12
  %17 = tail call ptr @b2GetBodyFullId(ptr noundef nonnull %14, i64 %0)
  %18 = tail call ptr @b2GetBodySim(ptr noundef nonnull %14, ptr noundef %17)
  %19 = getelementptr inbounds i8, ptr %18, i64 84
  store float %1, ptr %19, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %12, %16
  ret void
}

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 = { "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 = { cold noreturn nounwind memory(inaccessiblemem: write) }
attributes #3 = { 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, !9, i64 84}
!6 = !{!"b2BodySim", !7, i64 0, !8, i64 16, !12, i64 24, !8, i64 32, !8, i64 40, !8, i64 48, !9, i64 56, !9, i64 60, !9, i64 64, !9, i64 68, !9, i64 72, !9, i64 76, !9, i64 80, !9, i64 84, !13, i64 88, !14, i64 92, !14, i64 93, !14, i64 94, !14, i64 95, !14, i64 96}
!7 = !{!"b2Transform", !8, i64 0, !12, i64 8}
!8 = !{!"b2Vec2", !9, i64 0, !9, i64 4}
!9 = !{!"float", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!"b2Rot", !9, i64 0, !9, i64 4}
!13 = !{!"int", !10, i64 0}
!14 = !{!"_Bool", !10, i64 0}


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