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

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

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

16:                                               ; preds = %1
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 12, ptr %5) #3
  %18 = call { i64, i32 } @TPE_vec3(i32 noundef 512, i32 noundef 0, i32 noundef 0)
  store { i64, i32 } %18, ptr %6, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %5, ptr align 8 %6, i64 12, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %5, i64 12, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 12, ptr %5) #3
  br label %66

19:                                               ; preds = %1
  %20 = load i32, ptr %3, align 4, !tbaa !9
  %21 = icmp slt i32 %20, 16
  br i1 %21, label %22, label %41

22:                                               ; preds = %19
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TPE_Vec3, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %26 = mul nsw i32 %25, 8
  store i32 %26, ptr %24, align 4, !tbaa !12
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TPE_Vec3, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %30 = mul nsw i32 %29, 8
  store i32 %30, ptr %28, align 4, !tbaa !14
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TPE_Vec3, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !15
  %34 = mul nsw i32 %33, 8
  store i32 %34, ptr %32, align 4, !tbaa !15
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %35, i64 12, i1 false)
  %36 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 0
  %37 = load i64, ptr %36, align 4
  %38 = getelementptr inbounds { i64, i32 }, ptr %7, i32 0, i32 1
  %39 = load i32, ptr %38, align 4
  %40 = call i32 @TPE_vec3Len(i64 %37, i32 %39)
  store i32 %40, ptr %3, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %22, %19
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.TPE_Vec3, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !12
  %45 = mul nsw i32 %44, 512
  %46 = load i32, ptr %3, align 4, !tbaa !9
  %47 = sdiv i32 %45, %46
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.TPE_Vec3, ptr %48, i32 0, i32 0
  store i32 %47, ptr %49, align 4, !tbaa !12
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TPE_Vec3, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !14
  %53 = mul nsw i32 %52, 512
  %54 = load i32, ptr %3, align 4, !tbaa !9
  %55 = sdiv i32 %53, %54
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.TPE_Vec3, ptr %56, i32 0, i32 1
  store i32 %55, ptr %57, align 4, !tbaa !14
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.TPE_Vec3, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !15
  %61 = mul nsw i32 %60, 512
  %62 = load i32, ptr %3, align 4, !tbaa !9
  %63 = sdiv i32 %61, %62
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.TPE_Vec3, ptr %64, i32 0, i32 2
  store i32 %63, ptr %65, align 4, !tbaa !15
  br label %66

66:                                               ; preds = %41, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret void
}

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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9}
!12 = !{!13, !10, i64 0}
!13 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!14 = !{!13, !10, i64 4}
!15 = !{!13, !10, 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"

; 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 i32 @TPE_vec3Len(i64, i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @TPE_vec3Normalize(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %.sroa.04.0.copyload = load i64, ptr %0, align 4
  %.sroa.25.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.25.0.copyload = load i32, ptr %.sroa.25.0..sroa_idx, align 4
  %2 = tail call i32 @TPE_vec3Len(i64 %.sroa.04.0.copyload, i32 %.sroa.25.0.copyload)
  %3 = icmp eq i32 %2, 0
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call { i64, i32 } @TPE_vec3(i32 noundef 512, i32 noundef 0, i32 noundef 0)
  %.fca.0.extract = extractvalue { i64, i32 } %5, 0
  %.fca.1.extract = extractvalue { i64, i32 } %5, 1
  store i64 %.fca.0.extract, ptr %0, align 4
  br label %25

6:                                                ; preds = %1
  %7 = icmp slt i32 %2, 16
  br i1 %7, label %8, label %14

8:                                                ; preds = %6
  %9 = load <2 x i32>, ptr %0, align 4, !tbaa !5
  %10 = shl nsw <2 x i32> %9, <i32 3, i32 3>
  store <2 x i32> %10, ptr %0, align 4, !tbaa !5
  %11 = load i32, ptr %.sroa.25.0..sroa_idx, align 4, !tbaa !9
  %12 = shl nsw i32 %11, 3
  store i32 %12, ptr %.sroa.25.0..sroa_idx, align 4, !tbaa !9
  %.sroa.0.0.copyload.cast = bitcast <2 x i32> %10 to i64
  %13 = tail call i32 @TPE_vec3Len(i64 %.sroa.0.0.copyload.cast, i32 %12)
  br label %14

14:                                               ; preds = %8, %6
  %.0 = phi i32 [ %13, %8 ], [ %2, %6 ]
  %15 = load i32, ptr %0, align 4, !tbaa !11
  %16 = shl nsw i32 %15, 9
  %17 = sdiv i32 %16, %.0
  store i32 %17, ptr %0, align 4, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %0, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = shl nsw i32 %19, 9
  %21 = sdiv i32 %20, %.0
  store i32 %21, ptr %18, align 4, !tbaa !12
  %22 = load i32, ptr %.sroa.25.0..sroa_idx, align 4, !tbaa !9
  %23 = shl nsw i32 %22, 9
  %24 = sdiv i32 %23, %.0
  br label %25

25:                                               ; preds = %14, %4
  %storemerge = phi i32 [ %24, %14 ], [ %.fca.1.extract, %4 ]
  store i32 %storemerge, ptr %.sroa.25.0..sroa_idx, align 4, !tbaa !5
  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" }

!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 = !{!10, !6, i64 8}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass