; 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_Body = type { ptr, i8, ptr, i8, i16, i16, i16, i8, i8 }
%struct.TPE_Connection = type { i8, i8, i16 }
%struct.TPE_Joint = type { %struct.TPE_Vec3, [3 x i16], i8 }
%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: 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: nounwind uwtable
define dso_local void @TPE_bodyInit(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3, i8 noundef zeroext %4, i32 noundef %5) #2 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca { i64, i32 }, align 4
  %16 = alloca { i64, i32 }, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i8 %2, ptr %9, align 1, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i8 %4, ptr %11, align 1, !tbaa !9
  store i32 %5, ptr %12, align 4, !tbaa !10
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TPE_Body, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !12
  %20 = load i8, ptr %9, align 1, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TPE_Body, ptr %21, i32 0, i32 1
  store i8 %20, ptr %22, align 8, !tbaa !15
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TPE_Body, ptr %24, i32 0, i32 2
  store ptr %23, ptr %25, align 8, !tbaa !16
  %26 = load i8, ptr %11, align 1, !tbaa !9
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TPE_Body, ptr %27, i32 0, i32 3
  store i8 %26, ptr %28, align 8, !tbaa !17
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.TPE_Body, ptr %29, i32 0, i32 8
  store i8 0, ptr %30, align 1, !tbaa !18
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TPE_Body, ptr %31, i32 0, i32 5
  store i16 256, ptr %32, align 4, !tbaa !19
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.TPE_Body, ptr %33, i32 0, i32 6
  store i16 256, ptr %34, align 2, !tbaa !20
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TPE_Body, ptr %35, i32 0, i32 7
  store i8 0, ptr %36, align 8, !tbaa !21
  %37 = load i32, ptr %12, align 4, !tbaa !10
  %38 = load i8, ptr %9, align 1, !tbaa !9
  %39 = zext i8 %38 to i32
  %40 = sdiv i32 %37, %39
  %41 = call i32 @TPE_nonZero(i32 noundef %40)
  %42 = trunc i32 %41 to i16
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TPE_Body, ptr %43, i32 0, i32 4
  store i16 %42, ptr %44, align 2, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !10
  br label %45

45:                                               ; preds = %98, %6
  %46 = load i32, ptr %13, align 4, !tbaa !10
  %47 = load i8, ptr %11, align 1, !tbaa !9
  %48 = zext i8 %47 to i32
  %49 = icmp ult i32 %46, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %101

51:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load i32, ptr %13, align 4, !tbaa !10
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds %struct.TPE_Connection, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.TPE_Connection, ptr %56, i32 0, i32 0
  %58 = load i8, ptr %57, align 2, !tbaa !23
  %59 = zext i8 %58 to i64
  %60 = getelementptr inbounds %struct.TPE_Joint, ptr %52, i64 %59
  %61 = getelementptr inbounds %struct.TPE_Joint, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = load i32, ptr %13, align 4, !tbaa !10
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds %struct.TPE_Connection, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.TPE_Connection, ptr %66, i32 0, i32 1
  %68 = load i8, ptr %67, align 1, !tbaa !25
  %69 = zext i8 %68 to i64
  %70 = getelementptr inbounds %struct.TPE_Joint, ptr %62, i64 %69
  %71 = getelementptr inbounds %struct.TPE_Joint, ptr %70, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %61, i64 12, i1 false)
  %72 = getelementptr inbounds { i64, i32 }, ptr %15, i32 0, i32 0
  %73 = load i64, ptr %72, align 4
  %74 = getelementptr inbounds { i64, i32 }, ptr %15, i32 0, i32 1
  %75 = load i32, ptr %74, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %71, i64 12, i1 false)
  %76 = getelementptr inbounds { i64, i32 }, ptr %16, i32 0, i32 0
  %77 = load i64, ptr %76, align 4
  %78 = getelementptr inbounds { i64, i32 }, ptr %16, i32 0, i32 1
  %79 = load i32, ptr %78, align 4
  %80 = call i32 @TPE_dist(i64 %73, i32 %75, i64 %77, i32 %79)
  store i32 %80, ptr %14, align 4, !tbaa !10
  %81 = load i32, ptr %14, align 4, !tbaa !10
  %82 = icmp sgt i32 %81, 65535
  br i1 %82, label %83, label %84

83:                                               ; preds = %51
  br label %84

84:                                               ; preds = %83, %51
  %85 = load i32, ptr %14, align 4, !tbaa !10
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %89

87:                                               ; preds = %84
  %88 = load i32, ptr %14, align 4, !tbaa !10
  br label %90

89:                                               ; preds = %84
  br label %90

90:                                               ; preds = %89, %87
  %91 = phi i32 [ %88, %87 ], [ 1, %89 ]
  %92 = trunc i32 %91 to i16
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = load i32, ptr %13, align 4, !tbaa !10
  %95 = zext i32 %94 to i64
  %96 = getelementptr inbounds %struct.TPE_Connection, ptr %93, i64 %95
  %97 = getelementptr inbounds %struct.TPE_Connection, ptr %96, i32 0, i32 2
  store i16 %92, ptr %97, align 2, !tbaa !26
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %98

98:                                               ; preds = %90
  %99 = load i32, ptr %13, align 4, !tbaa !10
  %100 = add i32 %99, 1
  store i32 %100, ptr %13, align 4, !tbaa !10
  br label %45, !llvm.loop !27

101:                                              ; preds = %50
  ret void
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_dist(i64, i32, i64, i32) #3

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 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 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !7, i64 8, !6, i64 16, !7, i64 24, !14, i64 26, !14, i64 28, !14, i64 30, !7, i64 32, !7, i64 33}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !7, i64 8}
!16 = !{!13, !6, i64 16}
!17 = !{!13, !7, i64 24}
!18 = !{!13, !7, i64 33}
!19 = !{!13, !14, i64 28}
!20 = !{!13, !14, i64 30}
!21 = !{!13, !7, i64 32}
!22 = !{!13, !14, i64 26}
!23 = !{!24, !7, i64 0}
!24 = !{!"", !7, i64 0, !7, i64 1, !14, i64 2}
!25 = !{!24, !7, i64 1}
!26 = !{!24, !14, i64 2}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}


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

; Function Attrs: nounwind uwtable
define dso_local void @TPE_bodyInit(ptr nocapture noundef writeonly %0, ptr noundef %1, i8 noundef zeroext %2, ptr noundef %3, i8 noundef zeroext %4, i32 noundef %5) local_unnamed_addr #0 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 %2, ptr %7, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %3, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  store i8 %4, ptr %9, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %0, i64 33
  store i8 0, ptr %10, align 1, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %0, i64 28
  store i16 256, ptr %11, align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %0, i64 30
  store i16 256, ptr %12, align 2, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 32
  store i8 0, ptr %13, align 8, !tbaa !17
  %14 = zext i8 %2 to i32
  %15 = sdiv i32 %5, %14
  %16 = tail call i32 @TPE_nonZero(i32 noundef %15)
  %17 = trunc i32 %16 to i16
  %18 = getelementptr inbounds i8, ptr %0, i64 26
  store i16 %17, ptr %18, align 2, !tbaa !18
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %6
  %wide.trip.count = zext i8 %4 to i64
  br label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %6
  ret void

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %19 = getelementptr inbounds %struct.TPE_Connection, ptr %3, i64 %indvars.iv
  %20 = load i8, ptr %19, align 2, !tbaa !19
  %21 = zext i8 %20 to i64
  %22 = getelementptr inbounds %struct.TPE_Joint, ptr %1, i64 %21
  %23 = getelementptr inbounds i8, ptr %19, i64 1
  %24 = load i8, ptr %23, align 1, !tbaa !21
  %25 = zext i8 %24 to i64
  %26 = getelementptr inbounds %struct.TPE_Joint, ptr %1, i64 %25
  %.sroa.01.0.copyload = load i64, ptr %22, align 4
  %.sroa.22.0..sroa_idx = getelementptr inbounds i8, ptr %22, i64 8
  %.sroa.22.0.copyload = load i32, ptr %.sroa.22.0..sroa_idx, align 4
  %.sroa.0.0.copyload = load i64, ptr %26, align 4
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %26, i64 8
  %.sroa.2.0.copyload = load i32, ptr %.sroa.2.0..sroa_idx, align 4
  %27 = tail call i32 @TPE_dist(i64 %.sroa.01.0.copyload, i32 %.sroa.22.0.copyload, i64 %.sroa.0.0.copyload, i32 %.sroa.2.0.copyload)
  %28 = tail call i32 @llvm.umax.i32(i32 %27, i32 1)
  %29 = trunc i32 %28 to i16
  %30 = getelementptr inbounds i8, ptr %19, i64 2
  store i16 %29, ptr %30, align 2, !tbaa !22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !23
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_nonZero(i32 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @TPE_dist(i64, i32, i64, i32) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #2

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 = { 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 #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !7, i64 0}
!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, !8, i64 8}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !8, i64 24}
!14 = !{!6, !8, i64 33}
!15 = !{!6, !10, i64 28}
!16 = !{!6, !10, i64 30}
!17 = !{!6, !8, i64 32}
!18 = !{!6, !10, i64 26}
!19 = !{!20, !8, i64 0}
!20 = !{!"", !8, i64 0, !8, i64 1, !10, i64 2}
!21 = !{!20, !8, i64 1}
!22 = !{!20, !10, i64 2}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


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