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

; 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
declare dso_local { i64, i32 } @TPE_vec3(i32 noundef, i32 noundef, i32 noundef) #1

; 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 { i64, i32 } @TPE_vec3Plus(i64, i32, i64, i32) #1

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @TPE_bodyGetLinearVelocity(ptr noundef %0) #1 {
  %2 = alloca %struct.TPE_Vec3, align 4
  %3 = alloca ptr, align 8
  %4 = alloca { i64, i32 }, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca %struct.TPE_Vec3, align 4
  %8 = alloca %struct.TPE_Vec3, align 4
  %9 = alloca { i64, i32 }, align 8
  %10 = alloca { i64, i32 }, align 4
  %11 = alloca { i64, i32 }, align 4
  %12 = alloca { i64, i32 }, align 8
  %13 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %14 = call { i64, i32 } @TPE_vec3(i32 noundef 0, i32 noundef 0, i32 noundef 0)
  store { i64, i32 } %14, ptr %4, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 8 %4, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  store i16 0, ptr %5, align 2, !tbaa !9
  br label %15

15:                                               ; preds = %55, %1
  %16 = load i16, ptr %5, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TPE_Body, ptr %18, i32 0, i32 1
  %20 = load i8, ptr %19, align 8, !tbaa !11
  %21 = zext i8 %20 to i32
  %22 = icmp slt i32 %17, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  br label %58

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.TPE_Body, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !13
  %28 = load i16, ptr %5, align 2, !tbaa !9
  %29 = zext i16 %28 to i64
  %30 = getelementptr inbounds %struct.TPE_Joint, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.TPE_Joint, ptr %30, i32 0, i32 1
  %32 = getelementptr inbounds [3 x i16], ptr %31, i64 0, i64 0
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #3
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds i16, ptr %33, i64 0
  %35 = load i16, ptr %34, align 2, !tbaa !9
  %36 = sext i16 %35 to i32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds i16, ptr %37, i64 1
  %39 = load i16, ptr %38, align 2, !tbaa !9
  %40 = sext i16 %39 to i32
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds i16, ptr %41, i64 2
  %43 = load i16, ptr %42, align 2, !tbaa !9
  %44 = sext i16 %43 to i32
  %45 = call { i64, i32 } @TPE_vec3(i32 noundef %36, i32 noundef %40, i32 noundef %44)
  store { i64, i32 } %45, ptr %9, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 8 %9, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 4 %2, i64 12, i1 false)
  %46 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  %47 = load i64, ptr %46, align 4
  %48 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  %49 = load i32, ptr %48, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %8, i64 12, i1 false)
  %50 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 0
  %51 = load i64, ptr %50, align 4
  %52 = getelementptr inbounds { i64, i32 }, ptr %11, i32 0, i32 1
  %53 = load i32, ptr %52, align 4
  %54 = call { i64, i32 } @TPE_vec3Plus(i64 %47, i32 %49, i64 %51, i32 %53)
  store { i64, i32 } %54, ptr %12, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 8 %12, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 %7, i64 12, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %55

55:                                               ; preds = %24
  %56 = load i16, ptr %5, align 2, !tbaa !9
  %57 = add i16 %56, 1
  store i16 %57, ptr %5, align 2, !tbaa !9
  br label %15, !llvm.loop !17

58:                                               ; preds = %23
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.TPE_Body, ptr %59, i32 0, i32 1
  %61 = load i8, ptr %60, align 8, !tbaa !11
  %62 = zext i8 %61 to i32
  %63 = getelementptr inbounds %struct.TPE_Vec3, ptr %2, i32 0, i32 0
  %64 = load i32, ptr %63, align 4, !tbaa !19
  %65 = sdiv i32 %64, %62
  store i32 %65, ptr %63, align 4, !tbaa !19
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.TPE_Body, ptr %66, i32 0, i32 1
  %68 = load i8, ptr %67, align 8, !tbaa !11
  %69 = zext i8 %68 to i32
  %70 = getelementptr inbounds %struct.TPE_Vec3, ptr %2, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !21
  %72 = sdiv i32 %71, %69
  store i32 %72, ptr %70, align 4, !tbaa !21
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.TPE_Body, ptr %73, i32 0, i32 1
  %75 = load i8, ptr %74, align 8, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = getelementptr inbounds %struct.TPE_Vec3, ptr %2, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !22
  %79 = sdiv i32 %78, %76
  store i32 %79, ptr %77, align 4, !tbaa !22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %13, ptr align 4 %2, i64 12, i1 false)
  %80 = load { i64, i32 }, ptr %13, align 8
  ret { i64, i32 } %80
}

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" }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !7, i64 32, !7, i64 33}
!13 = !{!12, !6, i64 0}
!14 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15}
!15 = !{!16, !16, i64 0}
!16 = !{!"int", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !16, i64 0}
!20 = !{!"", !16, i64 0, !16, i64 4, !16, i64 8}
!21 = !{!20, !16, i64 4}
!22 = !{!20, !16, i64 8}


; 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 }

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

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

; Function Attrs: nounwind uwtable
define dso_local { i64, i32 } @TPE_bodyGetLinearVelocity(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = tail call { i64, i32 } @TPE_vec3(i32 noundef 0, i32 noundef 0, i32 noundef 0)
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.8.042 = extractvalue { i64, i32 } %2, 1
  %.sroa.027.0.in43 = extractvalue { i64, i32 } %2, 0
  %4 = load i8, ptr %3, align 8, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %5 = zext i8 %21 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %1
  %.sroa.8.0.lcssa = phi i32 [ %.sroa.8.042, %1 ], [ %.sroa.8.0, %._crit_edge.loopexit ]
  %.sroa.027.0.in.lcssa = phi i64 [ %.sroa.027.0.in43, %1 ], [ %.sroa.027.0.in, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ 0, %1 ], [ %5, %._crit_edge.loopexit ]
  %.sroa.027.0 = trunc i64 %.sroa.027.0.in.lcssa to i32
  %.sroa.6.0.in = lshr i64 %.sroa.027.0.in.lcssa, 32
  %.sroa.6.0 = trunc nuw i64 %.sroa.6.0.in to i32
  %6 = sdiv i32 %.sroa.027.0, %.lcssa
  %7 = sdiv i32 %.sroa.6.0, %.lcssa
  %8 = sdiv i32 %.sroa.8.0.lcssa, %.lcssa
  %.sroa.6.0.insert.ext = zext i32 %7 to i64
  %.sroa.6.0.insert.shift = shl nuw i64 %.sroa.6.0.insert.ext, 32
  %.sroa.027.0.insert.ext = zext i32 %6 to i64
  %.sroa.027.0.insert.insert = or disjoint i64 %.sroa.6.0.insert.shift, %.sroa.027.0.insert.ext
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.027.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %8, 1
  ret { i64, i32 } %.fca.1.insert

.lr.ph:                                           ; preds = %1, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %1 ]
  %.sroa.027.0.in46 = phi i64 [ %.sroa.027.0.in, %.lr.ph ], [ %.sroa.027.0.in43, %1 ]
  %.sroa.8.045 = phi i32 [ %.sroa.8.0, %.lr.ph ], [ %.sroa.8.042, %1 ]
  %9 = load ptr, ptr %0, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.TPE_Joint, ptr %9, i64 %indvars.iv, i32 1
  %11 = load i16, ptr %10, align 2, !tbaa !12
  %12 = sext i16 %11 to i32
  %13 = getelementptr inbounds i8, ptr %10, i64 2
  %14 = load i16, ptr %13, align 2, !tbaa !12
  %15 = sext i16 %14 to i32
  %16 = getelementptr inbounds i8, ptr %10, i64 4
  %17 = load i16, ptr %16, align 2, !tbaa !12
  %18 = sext i16 %17 to i32
  %19 = tail call { i64, i32 } @TPE_vec3(i32 noundef %12, i32 noundef %15, i32 noundef %18)
  %.fca.0.extract7 = extractvalue { i64, i32 } %19, 0
  %.fca.1.extract8 = extractvalue { i64, i32 } %19, 1
  %20 = tail call { i64, i32 } @TPE_vec3Plus(i64 %.sroa.027.0.in46, i32 %.sroa.8.045, i64 %.fca.0.extract7, i32 %.fca.1.extract8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %.sroa.8.0 = extractvalue { i64, i32 } %20, 1
  %.sroa.027.0.in = extractvalue { i64, i32 } %20, 0
  %21 = load i8, ptr %3, align 8, !tbaa !5
  %22 = zext i8 %21 to i64
  %23 = icmp ult i64 %indvars.iv.next, %22
  br i1 %23, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !13
}

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" }

!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, !8, i64 8}
!6 = !{!"", !7, i64 0, !8, i64 8, !7, i64 16, !8, i64 24, !10, i64 26, !10, i64 28, !10, i64 30, !8, i64 32, !8, i64 33}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass