; LLVM IR from PyCee/NUS_library :: src/model (NUS_animation)

; 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.NUS_animation = type { ptr, [64 x i8], float, i32, ptr, ptr }
%struct.NUS_skeleton = type { i32, ptr }
%struct.NUS_keyframe = type { ptr }

; Function Attrs: nounwind uwtable
define dso_local void @nus_animation_build(ptr dead_on_unwind noalias writable sret(%struct.NUS_animation) align 8 %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store ptr %1, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 0
  store ptr %9, ptr %10, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 1
  %12 = getelementptr inbounds [64 x i8], ptr %11, i64 0, i64 0
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.NUS_animation, ptr %13, i32 0, i32 1
  %15 = getelementptr inbounds [64 x i8], ptr %14, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %15, i64 64, i1 false)
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.NUS_animation, ptr %16, i32 0, i32 2
  %18 = load float, ptr %17, align 8, !tbaa !13
  %19 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 2
  store float %18, ptr %19, align 8, !tbaa !13
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.NUS_animation, ptr %20, i32 0, i32 3
  %22 = load i32, ptr %21, align 4, !tbaa !14
  %23 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 3
  store i32 %22, ptr %23, align 4, !tbaa !14
  %24 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 3
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = zext i32 %25 to i64
  %27 = mul i64 4, %26
  store i64 %27, ptr %8, align 8, !tbaa !15
  %28 = load i64, ptr %8, align 8, !tbaa !15
  %29 = call noalias ptr @malloc(i64 noundef %28) #5
  %30 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 4
  store ptr %29, ptr %30, align 8, !tbaa !17
  %31 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.NUS_animation, ptr %33, i32 0, i32 4
  %35 = load ptr, ptr %34, align 8, !tbaa !17
  %36 = load i64, ptr %8, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %32, ptr align 4 %35, i64 %36, i1 false)
  %37 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 3
  %38 = load i32, ptr %37, align 4, !tbaa !14
  %39 = zext i32 %38 to i64
  %40 = mul i64 8, %39
  %41 = call noalias ptr @malloc(i64 noundef %40) #5
  %42 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 5
  store ptr %41, ptr %42, align 8, !tbaa !18
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.NUS_skeleton, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 8, !tbaa !19
  %46 = zext i32 %45 to i64
  %47 = mul i64 80, %46
  store i64 %47, ptr %7, align 8, !tbaa !15
  store i32 0, ptr %6, align 4, !tbaa !21
  br label %48

48:                                               ; preds = %78, %3
  %49 = load i32, ptr %6, align 4, !tbaa !21
  %50 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 3
  %51 = load i32, ptr %50, align 4, !tbaa !14
  %52 = icmp ult i32 %49, %51
  br i1 %52, label %53, label %81

53:                                               ; preds = %48
  %54 = load i64, ptr %7, align 8, !tbaa !15
  %55 = call noalias ptr @malloc(i64 noundef %54) #5
  %56 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 5
  %57 = load ptr, ptr %56, align 8, !tbaa !18
  %58 = load i32, ptr %6, align 4, !tbaa !21
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds %struct.NUS_keyframe, ptr %57, i64 %59
  %61 = getelementptr inbounds %struct.NUS_keyframe, ptr %60, i32 0, i32 0
  store ptr %55, ptr %61, align 8, !tbaa !22
  %62 = getelementptr inbounds %struct.NUS_animation, ptr %0, i32 0, i32 5
  %63 = load ptr, ptr %62, align 8, !tbaa !18
  %64 = load i32, ptr %6, align 4, !tbaa !21
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.NUS_keyframe, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.NUS_keyframe, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !22
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.NUS_animation, ptr %69, i32 0, i32 5
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  %72 = load i32, ptr %6, align 4, !tbaa !21
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds %struct.NUS_keyframe, ptr %71, i64 %73
  %75 = getelementptr inbounds %struct.NUS_keyframe, ptr %74, i32 0, i32 0
  %76 = load ptr, ptr %75, align 8, !tbaa !22
  %77 = load i64, ptr %7, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %68, ptr align 8 %76, i64 %77, i1 false)
  br label %78

78:                                               ; preds = %53
  %79 = load i32, ptr %6, align 4, !tbaa !21
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %6, align 4, !tbaa !21
  br label %48, !llvm.loop !24

81:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  ret void
}

; 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 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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

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 allocsize(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 }
attributes #5 = { nounwind allocsize(0) }

!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, !6, i64 0}
!10 = !{!"NUS_animation", !6, i64 0, !7, i64 8, !11, i64 72, !12, i64 76, !6, i64 80, !6, i64 88}
!11 = !{!"float", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 72}
!14 = !{!10, !12, i64 76}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!10, !6, i64 80}
!18 = !{!10, !6, i64 88}
!19 = !{!20, !12, i64 0}
!20 = !{!"NUS_skeleton", !12, i64 0, !6, i64 8}
!21 = !{!12, !12, i64 0}
!22 = !{!23, !6, i64 0}
!23 = !{!"NUS_keyframe", !6, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"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.NUS_animation = type { ptr, [64 x i8], float, i32, ptr, ptr }
%struct.NUS_keyframe = type { ptr }

; Function Attrs: nofree nounwind uwtable
define dso_local void @nus_animation_build(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.NUS_animation) align 8 %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  store ptr %1, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = getelementptr inbounds i8, ptr %2, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %4, ptr noundef nonnull align 8 dereferenceable(64) %5, i64 64, i1 false)
  %6 = getelementptr inbounds i8, ptr %2, i64 72
  %7 = load float, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  store float %7, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %2, i64 76
  %10 = load i32, ptr %9, align 4, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %0, i64 76
  store i32 %10, ptr %11, align 4, !tbaa !13
  %12 = zext i32 %10 to i64
  %13 = shl nuw nsw i64 %12, 2
  %14 = tail call noalias ptr @malloc(i64 noundef %13) #3
  %15 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %14, ptr %15, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %2, i64 80
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %17, i64 %13, i1 false)
  %18 = shl nuw nsw i64 %12, 3
  %19 = tail call noalias ptr @malloc(i64 noundef %18) #3
  %20 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %19, ptr %20, align 8, !tbaa !15
  %21 = load i32, ptr %1, align 8, !tbaa !16
  %22 = zext i32 %21 to i64
  %23 = mul nuw nsw i64 %22, 80
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %24 = getelementptr inbounds i8, ptr %2, i64 88
  %25 = load ptr, ptr %24, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %.lr.ph, %26
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %26 ]
  %27 = tail call noalias ptr @malloc(i64 noundef %23) #3
  %28 = getelementptr inbounds %struct.NUS_keyframe, ptr %19, i64 %indvars.iv
  store ptr %27, ptr %28, align 8, !tbaa !18
  %29 = getelementptr inbounds %struct.NUS_keyframe, ptr %25, i64 %indvars.iv
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 8 %27, ptr align 8 %30, i64 %23, i1 false)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %12
  br i1 %exitcond.not, label %._crit_edge, label %26, !llvm.loop !20

._crit_edge:                                      ; preds = %26, %3
  ret void
}

; Function Attrs: mustprogress 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) #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0) }

!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 = !{!"NUS_animation", !7, i64 0, !8, i64 8, !10, i64 72, !11, i64 76, !7, i64 80, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !10, i64 72}
!13 = !{!6, !11, i64 76}
!14 = !{!6, !7, i64 80}
!15 = !{!6, !7, i64 88}
!16 = !{!17, !11, i64 0}
!17 = !{!"NUS_skeleton", !11, i64 0, !7, i64 8}
!18 = !{!19, !7, i64 0}
!19 = !{!"NUS_keyframe", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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