; LLVM IR from ESPboy-edu/ESPboy_tinyphysicsengine :: programs (hello)

; 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.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%struct.TPE_Vec3 = type { i32, i32, i32 }
%struct.TPE_Body = type { ptr, i8, ptr, i8, i16, i16, i16, i8, i8 }
%struct.TPE_World = type { ptr, i16, ptr, ptr }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_joint(ptr dead_on_unwind noalias writable sret(%struct.TPE_Joint) align 4, i64, i32, i32 noundef) #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

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @TPE_vec3(i32 noundef, i32 noundef, i32 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodyInit(ptr noundef, ptr noundef, i8 noundef zeroext, ptr noundef, i8 noundef zeroext, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_worldInit(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_worldStep(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @environmentDistance(i64, i32, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca %struct.TPE_Body, align 8
  %3 = alloca %struct.TPE_World, align 8
  %4 = alloca %struct.TPE_Joint, align 4
  %5 = alloca i32, align 4
  %6 = alloca %struct.TPE_Joint, align 4
  %7 = alloca %struct.TPE_Vec3, align 4
  %8 = alloca { i64, i32 }, align 8
  %9 = alloca { i64, i32 }, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.TPE_Vec3, align 4
  %12 = alloca { i64, i32 }, align 8
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 40, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 20, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 20, ptr %6) #5
  %14 = call { i64, i32 } @TPE_vec3(i32 noundef 0, i32 noundef 4096, i32 noundef 0)
  store { i64, i32 } %14, ptr %8, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 8 %8, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %7, i64 12, i1 false)
  %15 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 0
  %16 = load i64, ptr %15, align 4
  %17 = getelementptr inbounds { i64, i32 }, ptr %9, i32 0, i32 1
  %18 = load i32, ptr %17, align 4
  call void @TPE_joint(ptr dead_on_unwind writable sret(%struct.TPE_Joint) align 4 %6, i64 %16, i32 %18, i32 noundef 512)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 4 %6, i64 20, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 20, ptr %6) #5
  call void @TPE_bodyInit(ptr noundef %2, ptr noundef %4, i8 noundef zeroext 1, ptr noundef null, i8 noundef zeroext 0, i32 noundef 1024)
  call void @TPE_worldInit(ptr noundef %3, ptr noundef %2, i16 noundef zeroext 1, ptr noundef @environmentDistance)
  br label %19

19:                                               ; preds = %44, %0
  %20 = call zeroext i8 @TPE_bodyIsActive(ptr noundef %2)
  %21 = icmp ne i8 %20, 0
  br i1 %21, label %22, label %47

22:                                               ; preds = %19
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = srem i32 %23, 6
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %44

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %27 = call { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef %2)
  store { i64, i32 } %27, ptr %12, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %12, i64 12, i1 false)
  %28 = getelementptr inbounds %struct.TPE_Vec3, ptr %11, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !11
  store i32 %29, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %39, %26
  %31 = load i32, ptr %13, align 4, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = mul nsw i32 %32, 4
  %34 = sdiv i32 %33, 512
  %35 = icmp slt i32 %31, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  br label %42

37:                                               ; preds = %30
  %38 = call i32 @putchar(i32 noundef 32)
  br label %39

39:                                               ; preds = %37
  %40 = load i32, ptr %13, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %13, align 4, !tbaa !5
  br label %30, !llvm.loop !13

42:                                               ; preds = %36
  %43 = call i32 @puts(ptr noundef @.str)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %44

44:                                               ; preds = %42, %22
  call void @TPE_bodyApplyGravity(ptr noundef %2, i32 noundef 5)
  call void @TPE_worldStep(ptr noundef %3)
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %5, align 4, !tbaa !5
  br label %19, !llvm.loop !15

47:                                               ; preds = %19
  %48 = call i32 @puts(ptr noundef @.str.1)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %2) #5
  ret i32 0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @TPE_bodyIsActive(ptr noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare i32 @putchar(i32 noundef) #3

declare i32 @puts(ptr noundef) #4

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


; 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.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%struct.TPE_Vec3 = type { i32, i32, i32 }
%struct.TPE_Body = type { ptr, i8, ptr, i8, i16, i16, i16, i8, i8 }
%struct.TPE_World = type { ptr, i16, ptr, ptr }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_joint(ptr dead_on_unwind noalias writable sret(%struct.TPE_Joint) align 4, i64, i32, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @TPE_vec3(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_bodyInit(ptr noundef, ptr noundef, i8 noundef zeroext, ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @TPE_worldInit(ptr noundef, ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local { i64, i32 } @environmentDistance(i64, i32, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %struct.TPE_Body, align 8
  %2 = alloca %struct.TPE_World, align 8
  %3 = alloca %struct.TPE_Joint, align 4
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %3) #5
  %4 = tail call { i64, i32 } @TPE_vec3(i32 noundef 0, i32 noundef 4096, i32 noundef 0)
  %.fca.0.extract7 = extractvalue { i64, i32 } %4, 0
  %.fca.1.extract8 = extractvalue { i64, i32 } %4, 1
  call void @TPE_joint(ptr dead_on_unwind nonnull writable sret(%struct.TPE_Joint) align 4 %3, i64 %.fca.0.extract7, i32 %.fca.1.extract8, i32 noundef 512)
  call void @TPE_bodyInit(ptr noundef nonnull %1, ptr noundef nonnull %3, i8 noundef zeroext 1, ptr noundef null, i8 noundef zeroext 0, i32 noundef 1024)
  call void @TPE_worldInit(ptr noundef nonnull %2, ptr noundef nonnull %1, i16 noundef zeroext 1, ptr noundef nonnull @environmentDistance)
  %5 = call zeroext i8 @TPE_bodyIsActive(ptr noundef nonnull %1)
  %.not17 = icmp eq i8 %5, 0
  br i1 %.not17, label %._crit_edge21, label %.lr.ph20

.lr.ph20:                                         ; preds = %0, %16
  %.01518 = phi i32 [ %17, %16 ], [ 0, %0 ]
  %6 = urem i32 %.01518, 6
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %16

8:                                                ; preds = %.lr.ph20
  %9 = call { i64, i32 } @TPE_bodyGetCenterOfMass(ptr noundef nonnull %1)
  %.fca.0.extract = extractvalue { i64, i32 } %9, 0
  %sh.diff = lshr i64 %.fca.0.extract, 30
  %tr.sh.diff = trunc i64 %sh.diff to i32
  %10 = and i32 %tr.sh.diff, -4
  %11 = sdiv i32 %10, 512
  %12 = icmp sgt i32 %10, 511
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %8
  %13 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str)
  br label %16

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.016 = phi i32 [ %15, %.lr.ph ], [ 0, %8 ]
  %14 = call i32 @putchar(i32 noundef 32)
  %15 = add nuw nsw i32 %.016, 1
  %exitcond.not = icmp eq i32 %15, %11
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

16:                                               ; preds = %._crit_edge, %.lr.ph20
  call void @TPE_bodyApplyGravity(ptr noundef nonnull %1, i32 noundef 5)
  call void @TPE_worldStep(ptr noundef nonnull %2)
  %17 = add nuw nsw i32 %.01518, 1
  %18 = call zeroext i8 @TPE_bodyIsActive(ptr noundef nonnull %1)
  %.not = icmp eq i8 %18, 0
  br i1 %.not, label %._crit_edge21, label %.lr.ph20, !llvm.loop !7

._crit_edge21:                                    ; preds = %16, %0
  %19 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %1) #5
  ret i32 0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i8 @TPE_bodyIsActive(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nofree nounwind uwtable
declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #4

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 = { 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 #3 = { inlinehint nofree 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 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


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