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

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

@nus_unbind_binding = external global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local void @nus_model_free(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.NUS_model, ptr %4, i32 0, i32 8
  call void @nus_bind_binding(ptr noundef %5)
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.NUS_model, ptr %6, i32 0, i32 0
  call void @nus_memory_map_free(ptr noundef %7)
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.NUS_model, ptr %8, i32 0, i32 1
  call void @nus_memory_map_free(ptr noundef %9)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.NUS_model, ptr %10, i32 0, i32 5
  %12 = load i32, ptr %11, align 8, !tbaa !9
  %13 = icmp eq i32 %12, 1
  br i1 %13, label %14, label %17

14:                                               ; preds = %1
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.NUS_model, ptr %15, i32 0, i32 2
  call void @nus_texture_free(ptr noundef %16)
  br label %17

17:                                               ; preds = %14, %1
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.NUS_model, ptr %18, i32 0, i32 6
  %20 = load i32, ptr %19, align 4, !tbaa !17
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %25

22:                                               ; preds = %17
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.NUS_model, ptr %23, i32 0, i32 3
  call void @nus_skeleton_free(ptr noundef %24)
  br label %25

25:                                               ; preds = %22, %17
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.NUS_model, ptr %26, i32 0, i32 7
  %28 = load i32, ptr %27, align 8, !tbaa !18
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %52

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !19
  br label %31

31:                                               ; preds = %45, %30
  %32 = load i32, ptr %3, align 4, !tbaa !19
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.NUS_model, ptr %33, i32 0, i32 7
  %35 = load i32, ptr %34, align 8, !tbaa !18
  %36 = icmp ult i32 %32, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %48

38:                                               ; preds = %31
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.NUS_model, ptr %39, i32 0, i32 4
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  %42 = load i32, ptr %3, align 4, !tbaa !19
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds %struct.NUS_animation, ptr %41, i64 %43
  call void @nus_animation_free(ptr noundef %44)
  br label %45

45:                                               ; preds = %38
  %46 = load i32, ptr %3, align 4, !tbaa !19
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !19
  br label %31, !llvm.loop !21

48:                                               ; preds = %37
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.NUS_model, ptr %49, i32 0, i32 4
  %51 = load ptr, ptr %50, align 8, !tbaa !20
  call void @free(ptr noundef %51) #4
  br label %52

52:                                               ; preds = %48, %25
  %53 = load ptr, ptr @nus_unbind_binding, align 8, !tbaa !5
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.NUS_model, ptr %54, i32 0, i32 8
  call void %53(ptr noundef %55)
  ret void
}

declare void @nus_bind_binding(ptr noundef) #2

declare void @nus_memory_map_free(ptr noundef) #2

declare void @nus_texture_free(ptr noundef) #2

declare void @nus_skeleton_free(ptr noundef) #2

declare void @nus_animation_free(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync 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 = { "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 "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 = !{!10, !14, i64 208}
!10 = !{!"NUS_model", !11, i64 0, !11, i64 56, !15, i64 112, !16, i64 184, !6, i64 200, !14, i64 208, !14, i64 212, !14, i64 216, !13, i64 224}
!11 = !{!"NUS_memory_map", !6, i64 0, !6, i64 8, !12, i64 16, !13, i64 24}
!12 = !{!"long", !7, i64 0}
!13 = !{!"NUS_binding", !6, i64 0, !6, i64 8, !6, i64 16, !14, i64 24}
!14 = !{!"int", !7, i64 0}
!15 = !{!"NUS_texture", !6, i64 0, !6, i64 8, !14, i64 16, !14, i64 20, !14, i64 24, !14, i64 28, !14, i64 32, !13, i64 40}
!16 = !{!"NUS_skeleton", !14, i64 0, !6, i64 8}
!17 = !{!10, !14, i64 212}
!18 = !{!10, !14, i64 216}
!19 = !{!14, !14, i64 0}
!20 = !{!10, !6, i64 200}
!21 = distinct !{!21, !22}
!22 = !{!"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 }

@nus_unbind_binding = external local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local void @nus_model_free(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 224
  tail call void @nus_bind_binding(ptr noundef nonnull %2) #3
  tail call void @nus_memory_map_free(ptr noundef %0) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 56
  tail call void @nus_memory_map_free(ptr noundef nonnull %3) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 208
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 1
  br i1 %6, label %7, label %9

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 112
  tail call void @nus_texture_free(ptr noundef nonnull %8) #3
  br label %9

9:                                                ; preds = %7, %1
  %10 = getelementptr inbounds i8, ptr %0, i64 212
  %11 = load i32, ptr %10, align 4, !tbaa !16
  %12 = icmp eq i32 %11, 1
  br i1 %12, label %13, label %15

13:                                               ; preds = %9
  %14 = getelementptr inbounds i8, ptr %0, i64 184
  tail call void @nus_skeleton_free(ptr noundef nonnull %14) #3
  br label %15

15:                                               ; preds = %13, %9
  %16 = getelementptr inbounds i8, ptr %0, i64 216
  %17 = load i32, ptr %16, align 8, !tbaa !17
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %27, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %18 = getelementptr inbounds i8, ptr %0, i64 200
  br label %21

._crit_edge:                                      ; preds = %21
  %19 = getelementptr inbounds i8, ptr %0, i64 200
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  tail call void @free(ptr noundef %20) #3
  br label %27

21:                                               ; preds = %.lr.ph, %21
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %21 ]
  %22 = load ptr, ptr %18, align 8, !tbaa !18
  %23 = getelementptr inbounds %struct.NUS_animation, ptr %22, i64 %indvars.iv
  tail call void @nus_animation_free(ptr noundef %23) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr %16, align 8, !tbaa !17
  %25 = zext i32 %24 to i64
  %26 = icmp ult i64 %indvars.iv.next, %25
  br i1 %26, label %21, label %._crit_edge, !llvm.loop !19

27:                                               ; preds = %._crit_edge, %15
  %28 = load ptr, ptr @nus_unbind_binding, align 8, !tbaa !21
  tail call void %28(ptr noundef nonnull %2) #3
  ret void
}

declare void @nus_bind_binding(ptr noundef) local_unnamed_addr #1

declare void @nus_memory_map_free(ptr noundef) local_unnamed_addr #1

declare void @nus_texture_free(ptr noundef) local_unnamed_addr #1

declare void @nus_skeleton_free(ptr noundef) local_unnamed_addr #1

declare void @nus_animation_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 }

!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, !13, i64 208}
!6 = !{!"NUS_model", !7, i64 0, !7, i64 56, !14, i64 112, !15, i64 184, !8, i64 200, !13, i64 208, !13, i64 212, !13, i64 216, !12, i64 224}
!7 = !{!"NUS_memory_map", !8, i64 0, !8, i64 8, !11, i64 16, !12, i64 24}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"long", !9, i64 0}
!12 = !{!"NUS_binding", !8, i64 0, !8, i64 8, !8, i64 16, !13, i64 24}
!13 = !{!"int", !9, i64 0}
!14 = !{!"NUS_texture", !8, i64 0, !8, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !12, i64 40}
!15 = !{!"NUS_skeleton", !13, i64 0, !8, i64 8}
!16 = !{!6, !13, i64 212}
!17 = !{!6, !13, i64 216}
!18 = !{!6, !8, i64 200}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!8, !8, i64 0}


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