; LLVM IR from jordan4ibanez/tinyphysicsengine :: old/test.ll (TPE_getCapsuleCyllinderEndpoints)

; 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_Vec4 = type { i32, i32, i32, i32 }
%struct.TPE_Body = type { i8, [3 x i32], [2 x ptr], i8, i32, %struct.TPE_Vec4, %struct.TPE_Vec4, %struct.TPE_RotationState, i32, i8 }
%struct.TPE_RotationState = type { %struct.TPE_Vec4, %struct.TPE_Vec4, i32 }

; Function Attrs: nounwind uwtable
declare dso_local { i64, i64 } @TPE_vec4(i32 noundef, 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) #1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @_TPE_getCapsuleCyllinderEndpoints(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.TPE_Vec4, align 4
  %8 = alloca %struct.TPE_Vec4, align 4
  %9 = alloca %struct.TPE_Vec4, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call { i64, i64 } @TPE_bodyGetOrientation(ptr noundef %10)
  %12 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %13 = extractvalue { i64, i64 } %11, 0
  store i64 %13, ptr %12, align 4
  %14 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %15 = extractvalue { i64, i64 } %11, 1
  store i64 %15, ptr %14, align 4
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TPE_Body, ptr %17, i32 0, i32 1
  %19 = getelementptr inbounds [3 x i32], ptr %18, i64 0, i64 1
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = sdiv i32 %20, 2
  %22 = call { i64, i64 } @TPE_vec4(i32 noundef 0, i32 noundef %21, i32 noundef 0, i32 noundef 0)
  %23 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %24 = extractvalue { i64, i64 } %22, 0
  store i64 %24, ptr %23, align 4
  %25 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %26 = extractvalue { i64, i64 } %22, 1
  store i64 %26, ptr %25, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %8, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.TPE_Vec4, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !12
  %31 = mul nsw i32 -1, %30
  %32 = call { i64, i64 } @TPE_vec4(i32 noundef 0, i32 noundef %31, i32 noundef 0, i32 noundef 0)
  %33 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 0
  %34 = extractvalue { i64, i64 } %32, 0
  store i64 %34, ptr %33, align 4
  %35 = getelementptr inbounds { i64, i64 }, ptr %9, i32 0, i32 1
  %36 = extractvalue { i64, i64 } %32, 1
  store i64 %36, ptr %35, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %27, ptr align 4 %9, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #3
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %39 = load i64, ptr %38, align 4
  %40 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %41 = load i64, ptr %40, align 4
  call void @TPE_rotatePoint(ptr noundef %37, i64 %39, i64 %41)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  %44 = load i64, ptr %43, align 4
  %45 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  %46 = load i64, ptr %45, align 4
  call void @TPE_rotatePoint(ptr noundef %42, i64 %44, i64 %46)
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TPE_Body, ptr %48, i32 0, i32 5
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds { i64, i64 }, ptr %47, i32 0, i32 0
  %52 = load i64, ptr %51, align 4
  %53 = getelementptr inbounds { i64, i64 }, ptr %47, i32 0, i32 1
  %54 = load i64, ptr %53, align 4
  %55 = getelementptr inbounds { i64, i64 }, ptr %49, i32 0, i32 0
  %56 = load i64, ptr %55, align 8
  %57 = getelementptr inbounds { i64, i64 }, ptr %49, i32 0, i32 1
  %58 = load i64, ptr %57, align 8
  call void @TPE_vec3Add(i64 %52, i64 %54, i64 %56, i64 %58, ptr noundef %50)
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.TPE_Body, ptr %60, i32 0, i32 5
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds { i64, i64 }, ptr %59, i32 0, i32 0
  %64 = load i64, ptr %63, align 4
  %65 = getelementptr inbounds { i64, i64 }, ptr %59, i32 0, i32 1
  %66 = load i64, ptr %65, align 4
  %67 = getelementptr inbounds { i64, i64 }, ptr %61, i32 0, i32 0
  %68 = load i64, ptr %67, align 8
  %69 = getelementptr inbounds { i64, i64 }, ptr %61, i32 0, i32 1
  %70 = load i64, ptr %69, align 8
  call void @TPE_vec3Add(i64 %64, i64 %66, i64 %68, i64 %70, ptr noundef %62)
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  ret void
}

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

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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree 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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9}
!12 = !{!13, !10, i64 4}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}


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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @_TPE_getCapsuleCyllinderEndpoints(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call { i64, i64 } @TPE_bodyGetOrientation(ptr noundef %0)
  %5 = extractvalue { i64, i64 } %4, 0
  %6 = extractvalue { i64, i64 } %4, 1
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sdiv i32 %8, 2
  %10 = tail call { i64, i64 } @TPE_vec4(i32 noundef 0, i32 noundef %9, i32 noundef 0, i32 noundef 0)
  %11 = extractvalue { i64, i64 } %10, 0
  %12 = extractvalue { i64, i64 } %10, 1
  store i64 %11, ptr %1, align 4
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %1, i64 8
  store i64 %12, ptr %.sroa.42.0..sroa_idx, align 4
  %13 = lshr i64 %11, 32
  %14 = trunc nuw i64 %13 to i32
  %15 = sub nsw i32 0, %14
  %16 = tail call { i64, i64 } @TPE_vec4(i32 noundef 0, i32 noundef %15, i32 noundef 0, i32 noundef 0)
  %17 = extractvalue { i64, i64 } %16, 0
  %18 = extractvalue { i64, i64 } %16, 1
  store i64 %17, ptr %2, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  store i64 %18, ptr %.sroa.4.0..sroa_idx, align 4
  tail call void @TPE_rotatePoint(ptr noundef nonnull %1, i64 %5, i64 %6)
  tail call void @TPE_rotatePoint(ptr noundef nonnull %2, i64 %5, i64 %6)
  %19 = getelementptr inbounds i8, ptr %0, i64 40
  %20 = load i64, ptr %1, align 4
  %21 = load i64, ptr %.sroa.42.0..sroa_idx, align 4
  %22 = load i64, ptr %19, align 8
  %23 = getelementptr inbounds i8, ptr %0, i64 48
  %24 = load i64, ptr %23, align 8
  tail call void @TPE_vec3Add(i64 %20, i64 %21, i64 %22, i64 %24, ptr noundef nonnull %1)
  %25 = load i64, ptr %2, align 4
  %26 = load i64, ptr %.sroa.4.0..sroa_idx, align 4
  %27 = load i64, ptr %19, align 8
  %28 = load i64, ptr %23, align 8
  tail call void @TPE_vec3Add(i64 %25, i64 %26, i64 %27, i64 %28, ptr noundef nonnull %2)
  ret void
}

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

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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SCCPPass,SROAPass,TailCallElimPass