; 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: 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 i32 @TPE_vec3LenApprox(i64 %0, i32 %1) #2 {
  %3 = alloca %struct.TPE_Vec3, align 4
  %4 = alloca { i64, i32 }, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 0
  store i64 %0, ptr %10, align 4
  %11 = getelementptr inbounds { i64, i32 }, ptr %4, i32 0, i32 1
  store i32 %1, ptr %11, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %3, ptr align 4 %4, i64 12, i1 false)
  %12 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %19

15:                                               ; preds = %2
  %16 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = mul nsw i32 %17, -1
  store i32 %18, ptr %16, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %15, %2
  %20 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %21 = load i32, ptr %20, align 4, !tbaa !10
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  %24 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !10
  %26 = mul nsw i32 %25, -1
  store i32 %26, ptr %24, align 4, !tbaa !10
  br label %27

27:                                               ; preds = %23, %19
  %28 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !11
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %31, label %35

31:                                               ; preds = %27
  %32 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !11
  %34 = mul nsw i32 %33, -1
  store i32 %34, ptr %32, align 4, !tbaa !11
  br label %35

35:                                               ; preds = %31, %27
  %36 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !10
  %40 = icmp slt i32 %37, %39
  br i1 %40, label %41, label %86

41:                                               ; preds = %35
  %42 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !11
  %46 = icmp slt i32 %43, %45
  br i1 %46, label %47, label %77

47:                                               ; preds = %41
  %48 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !10
  %50 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %51 = load i32, ptr %50, align 4, !tbaa !11
  %52 = icmp slt i32 %49, %51
  br i1 %52, label %53, label %61

53:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %54 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %55 = load i32, ptr %54, align 4, !tbaa !5
  store i32 %55, ptr %5, align 4, !tbaa !12
  %56 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %57 = load i32, ptr %56, align 4, !tbaa !11
  %58 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  store i32 %57, ptr %58, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !12
  %60 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  store i32 %59, ptr %60, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %76

61:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %62 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !5
  store i32 %63, ptr %6, align 4, !tbaa !12
  %64 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %65 = load i32, ptr %64, align 4, !tbaa !10
  %66 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  store i32 %65, ptr %66, align 4, !tbaa !5
  %67 = load i32, ptr %6, align 4, !tbaa !12
  %68 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  store i32 %67, ptr %68, align 4, !tbaa !10
  %69 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %70 = load i32, ptr %69, align 4, !tbaa !11
  store i32 %70, ptr %6, align 4, !tbaa !12
  %71 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !10
  %73 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  store i32 %72, ptr %73, align 4, !tbaa !11
  %74 = load i32, ptr %6, align 4, !tbaa !12
  %75 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  store i32 %74, ptr %75, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %76

76:                                               ; preds = %61, %53
  br label %85

77:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %78 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %79 = load i32, ptr %78, align 4, !tbaa !5
  store i32 %79, ptr %7, align 4, !tbaa !12
  %80 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %81 = load i32, ptr %80, align 4, !tbaa !10
  %82 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  store i32 %81, ptr %82, align 4, !tbaa !5
  %83 = load i32, ptr %7, align 4, !tbaa !12
  %84 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  store i32 %83, ptr %84, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %85

85:                                               ; preds = %77, %76
  br label %123

86:                                               ; preds = %35
  %87 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !10
  %89 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %90 = load i32, ptr %89, align 4, !tbaa !11
  %91 = icmp slt i32 %88, %90
  br i1 %91, label %92, label %122

92:                                               ; preds = %86
  %93 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %96 = load i32, ptr %95, align 4, !tbaa !11
  %97 = icmp slt i32 %94, %96
  br i1 %97, label %98, label %113

98:                                               ; preds = %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %99 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !10
  store i32 %100, ptr %8, align 4, !tbaa !12
  %101 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %102 = load i32, ptr %101, align 4, !tbaa !11
  %103 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  store i32 %102, ptr %103, align 4, !tbaa !10
  %104 = load i32, ptr %8, align 4, !tbaa !12
  %105 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  store i32 %104, ptr %105, align 4, !tbaa !11
  %106 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %107 = load i32, ptr %106, align 4, !tbaa !5
  store i32 %107, ptr %8, align 4, !tbaa !12
  %108 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !10
  %110 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  store i32 %109, ptr %110, align 4, !tbaa !5
  %111 = load i32, ptr %8, align 4, !tbaa !12
  %112 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  store i32 %111, ptr %112, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %121

113:                                              ; preds = %92
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %114 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %115 = load i32, ptr %114, align 4, !tbaa !10
  store i32 %115, ptr %9, align 4, !tbaa !12
  %116 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %117 = load i32, ptr %116, align 4, !tbaa !11
  %118 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  store i32 %117, ptr %118, align 4, !tbaa !10
  %119 = load i32, ptr %9, align 4, !tbaa !12
  %120 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  store i32 %119, ptr %120, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %121

121:                                              ; preds = %113, %98
  br label %122

122:                                              ; preds = %121, %86
  br label %123

123:                                              ; preds = %122, %85
  %124 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 0
  %125 = load i32, ptr %124, align 4, !tbaa !5
  %126 = mul nsw i32 893, %125
  %127 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 1
  %128 = load i32, ptr %127, align 4, !tbaa !10
  %129 = mul nsw i32 446, %128
  %130 = add nsw i32 %126, %129
  %131 = getelementptr inbounds %struct.TPE_Vec3, ptr %3, i32 0, i32 2
  %132 = load i32, ptr %131, align 4, !tbaa !11
  %133 = mul nsw i32 223, %132
  %134 = add nsw i32 %130, %133
  %135 = sdiv i32 %134, 1024
  ret i32 %135
}

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


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local range(i32 0, 2097152) i32 @TPE_vec3LenApprox(i64 %0, i32 %1) local_unnamed_addr #0 {
  %.sroa.07.0.extract.trunc = trunc i64 %0 to i32
  %.sroa.16.0.extract.shift = lshr i64 %0, 32
  %.sroa.16.0.extract.trunc = trunc nuw i64 %.sroa.16.0.extract.shift to i32
  %spec.select = tail call i32 @llvm.abs.i32(i32 %.sroa.07.0.extract.trunc, i1 true)
  %3 = icmp slt i64 %0, 0
  %4 = sub nsw i32 0, %.sroa.16.0.extract.trunc
  %.sroa.16.0 = select i1 %3, i32 %4, i32 %.sroa.16.0.extract.trunc
  %.sroa.35.0 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  %5 = icmp slt i32 %spec.select, %.sroa.16.0
  br i1 %5, label %6, label %11

6:                                                ; preds = %2
  %7 = icmp ult i32 %spec.select, %.sroa.35.0
  br i1 %7, label %8, label %14

8:                                                ; preds = %6
  %9 = tail call i32 @llvm.umax.i32(i32 %.sroa.16.0, i32 %.sroa.35.0)
  %10 = tail call i32 @llvm.umin.i32(i32 %.sroa.16.0, i32 %.sroa.35.0)
  br label %14

11:                                               ; preds = %2
  %12 = icmp slt i32 %.sroa.16.0, %.sroa.35.0
  br i1 %12, label %13, label %14

13:                                               ; preds = %11
  %.sroa.35.0.spec.select = tail call i32 @llvm.umax.i32(i32 %spec.select, i32 %.sroa.35.0)
  %spec.select..sroa.35.0 = tail call i32 @llvm.umin.i32(i32 %spec.select, i32 %.sroa.35.0)
  br label %14

14:                                               ; preds = %13, %6, %8, %11
  %.sroa.07.1 = phi i32 [ %spec.select, %11 ], [ %9, %8 ], [ %.sroa.16.0, %6 ], [ %.sroa.35.0.spec.select, %13 ]
  %.sroa.16.1 = phi i32 [ %.sroa.16.0, %11 ], [ %10, %8 ], [ %spec.select, %6 ], [ %spec.select..sroa.35.0, %13 ]
  %.sroa.35.1 = phi i32 [ %.sroa.35.0, %11 ], [ %spec.select, %8 ], [ %.sroa.35.0, %6 ], [ %.sroa.16.0, %13 ]
  %15 = mul nsw i32 %.sroa.07.1, 893
  %16 = mul nsw i32 %.sroa.16.1, 446
  %17 = add nuw nsw i32 %16, %15
  %18 = mul nsw i32 %.sroa.35.1, 223
  %19 = add nuw nsw i32 %17, %18
  %20 = lshr i32 %19, 10
  ret i32 %20
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #1

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

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 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)"}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass