; LLVM IR from Dovyski/opengl-demos :: src/model-md2/md2.ll (ZN9CMD2Model7AnimateEf)

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

%class.CMD2Model = type <{ i32, i32, i32, [4 x i8], ptr, ptr, ptr, i32, %struct.animState_t, float, [4 x i8] }>
%struct.animState_t = type { i32, i32, i32, float, float, float, i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9CMD2Model7AnimateEf(ptr noundef nonnull align 8 dereferenceable(84) %0, float noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load float, ptr %4, align 4, !tbaa !9
  %7 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %8 = getelementptr inbounds %struct.animState_t, ptr %7, i32 0, i32 3
  store float %6, ptr %8, align 4, !tbaa !11
  %9 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %10 = getelementptr inbounds %struct.animState_t, ptr %9, i32 0, i32 3
  %11 = load float, ptr %10, align 4, !tbaa !11
  %12 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %13 = getelementptr inbounds %struct.animState_t, ptr %12, i32 0, i32 4
  %14 = load float, ptr %13, align 4, !tbaa !15
  %15 = fsub float %11, %14
  %16 = fpext float %15 to double
  %17 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %18 = getelementptr inbounds %struct.animState_t, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !16
  %20 = sitofp i32 %19 to double
  %21 = fdiv double 1.000000e+00, %20
  %22 = fcmp ogt double %16, %21
  br i1 %22, label %23, label %52

23:                                               ; preds = %2
  %24 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %25 = getelementptr inbounds %struct.animState_t, ptr %24, i32 0, i32 8
  %26 = load i32, ptr %25, align 4, !tbaa !17
  %27 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %28 = getelementptr inbounds %struct.animState_t, ptr %27, i32 0, i32 7
  store i32 %26, ptr %28, align 4, !tbaa !18
  %29 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %30 = getelementptr inbounds %struct.animState_t, ptr %29, i32 0, i32 8
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %30, align 4, !tbaa !17
  %33 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %34 = getelementptr inbounds %struct.animState_t, ptr %33, i32 0, i32 8
  %35 = load i32, ptr %34, align 4, !tbaa !17
  %36 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %37 = getelementptr inbounds %struct.animState_t, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 4, !tbaa !19
  %39 = icmp sgt i32 %35, %38
  br i1 %39, label %40, label %46

40:                                               ; preds = %23
  %41 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %42 = getelementptr inbounds %struct.animState_t, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !20
  %44 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %45 = getelementptr inbounds %struct.animState_t, ptr %44, i32 0, i32 8
  store i32 %43, ptr %45, align 4, !tbaa !17
  br label %46

46:                                               ; preds = %40, %23
  %47 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %48 = getelementptr inbounds %struct.animState_t, ptr %47, i32 0, i32 3
  %49 = load float, ptr %48, align 4, !tbaa !11
  %50 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %51 = getelementptr inbounds %struct.animState_t, ptr %50, i32 0, i32 4
  store float %49, ptr %51, align 4, !tbaa !15
  br label %52

52:                                               ; preds = %46, %2
  %53 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %54 = getelementptr inbounds %struct.animState_t, ptr %53, i32 0, i32 7
  %55 = load i32, ptr %54, align 4, !tbaa !18
  %56 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 0
  %57 = load i32, ptr %56, align 8, !tbaa !21
  %58 = sub nsw i32 %57, 1
  %59 = icmp sgt i32 %55, %58
  br i1 %59, label %60, label %63

60:                                               ; preds = %52
  %61 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %62 = getelementptr inbounds %struct.animState_t, ptr %61, i32 0, i32 7
  store i32 0, ptr %62, align 4, !tbaa !18
  br label %63

63:                                               ; preds = %60, %52
  %64 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %65 = getelementptr inbounds %struct.animState_t, ptr %64, i32 0, i32 8
  %66 = load i32, ptr %65, align 4, !tbaa !17
  %67 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 0
  %68 = load i32, ptr %67, align 8, !tbaa !21
  %69 = sub nsw i32 %68, 1
  %70 = icmp sgt i32 %66, %69
  br i1 %70, label %71, label %74

71:                                               ; preds = %63
  %72 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %73 = getelementptr inbounds %struct.animState_t, ptr %72, i32 0, i32 8
  store i32 0, ptr %73, align 4, !tbaa !17
  br label %74

74:                                               ; preds = %71, %63
  %75 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %76 = getelementptr inbounds %struct.animState_t, ptr %75, i32 0, i32 2
  %77 = load i32, ptr %76, align 4, !tbaa !16
  %78 = sitofp i32 %77 to float
  %79 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %80 = getelementptr inbounds %struct.animState_t, ptr %79, i32 0, i32 3
  %81 = load float, ptr %80, align 4, !tbaa !11
  %82 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %83 = getelementptr inbounds %struct.animState_t, ptr %82, i32 0, i32 4
  %84 = load float, ptr %83, align 4, !tbaa !15
  %85 = fsub float %81, %84
  %86 = fmul float %78, %85
  %87 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %88 = getelementptr inbounds %struct.animState_t, ptr %87, i32 0, i32 5
  store float %86, ptr %88, align 4, !tbaa !22
  ret void
}

attributes #0 = { mustprogress 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 56}
!12 = !{!"_ZTS9CMD2Model", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !14, i64 44, !10, i64 80}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS11animState_t", !13, i64 0, !13, i64 4, !13, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !13, i64 28, !13, i64 32}
!15 = !{!12, !10, i64 60}
!16 = !{!12, !13, i64 52}
!17 = !{!12, !13, i64 76}
!18 = !{!12, !13, i64 72}
!19 = !{!12, !13, i64 48}
!20 = !{!12, !13, i64 44}
!21 = !{!12, !13, i64 0}
!22 = !{!12, !10, i64 64}


; 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(argmem: readwrite) uwtable
define dso_local void @_ZN9CMD2Model7AnimateEf(ptr nocapture noundef nonnull align 8 dereferenceable(84) %0, float noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 44
  %4 = getelementptr inbounds i8, ptr %0, i64 56
  store float %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 60
  %6 = load float, ptr %5, align 4, !tbaa !13
  %7 = fsub float %1, %6
  %8 = fpext float %7 to double
  %9 = getelementptr inbounds i8, ptr %0, i64 52
  %10 = load i32, ptr %9, align 4, !tbaa !14
  %11 = sitofp i32 %10 to double
  %12 = fdiv double 1.000000e+00, %11
  %13 = fcmp olt double %12, %8
  br i1 %13, label %14, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 72
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !15
  br label %24

14:                                               ; preds = %2
  %15 = getelementptr inbounds i8, ptr %0, i64 76
  %16 = load i32, ptr %15, align 4, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 %16, ptr %17, align 8, !tbaa !15
  %18 = add nsw i32 %16, 1
  store i32 %18, ptr %15, align 4, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %0, i64 48
  %20 = load i32, ptr %19, align 8, !tbaa !17
  %.not = icmp slt i32 %16, %20
  br i1 %.not, label %23, label %21

21:                                               ; preds = %14
  %22 = load i32, ptr %3, align 4, !tbaa !18
  store i32 %22, ptr %15, align 4, !tbaa !16
  br label %23

23:                                               ; preds = %21, %14
  store float %1, ptr %5, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %._crit_edge, %23
  %25 = phi float [ %6, %._crit_edge ], [ %1, %23 ]
  %26 = phi i32 [ %.pre, %._crit_edge ], [ %16, %23 ]
  %27 = load i32, ptr %0, align 8, !tbaa !19
  %.not2 = icmp slt i32 %26, %27
  br i1 %.not2, label %30, label %28

28:                                               ; preds = %24
  %29 = getelementptr inbounds i8, ptr %0, i64 72
  store i32 0, ptr %29, align 8, !tbaa !15
  br label %30

30:                                               ; preds = %28, %24
  %31 = getelementptr inbounds i8, ptr %0, i64 76
  %32 = load i32, ptr %31, align 4, !tbaa !16
  %.not3 = icmp slt i32 %32, %27
  br i1 %.not3, label %34, label %33

33:                                               ; preds = %30
  store i32 0, ptr %31, align 4, !tbaa !16
  br label %34

34:                                               ; preds = %33, %30
  %35 = sitofp i32 %10 to float
  %36 = fsub float %1, %25
  %37 = fmul float %36, %35
  %38 = getelementptr inbounds i8, ptr %0, i64 64
  store float %37, ptr %38, align 8, !tbaa !20
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !12, i64 56}
!6 = !{!"_ZTS9CMD2Model", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !11, i64 44, !12, i64 80}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTS11animState_t", !7, i64 0, !7, i64 4, !7, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !7, i64 24, !7, i64 28, !7, i64 32}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !12, i64 60}
!14 = !{!6, !7, i64 52}
!15 = !{!6, !7, i64 72}
!16 = !{!6, !7, i64 76}
!17 = !{!6, !7, i64 48}
!18 = !{!6, !7, i64 44}
!19 = !{!6, !7, i64 0}
!20 = !{!6, !12, i64 64}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass