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

; 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.anim_t = type { i32, i32, i32 }
%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 }

@_ZN9CMD2Model8animlistE = external dso_local global [21 x %struct.anim_t], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN9CMD2Model7SetAnimEi(ptr noundef nonnull align 8 dereferenceable(84) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8
  %6 = load i32, ptr %4, align 4, !tbaa !9
  %7 = icmp slt i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %2
  %9 = load i32, ptr %4, align 4, !tbaa !9
  %10 = icmp sgt i32 %9, 20
  br i1 %10, label %11, label %12

11:                                               ; preds = %8, %2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %11, %8
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [21 x %struct.anim_t], ptr @_ZN9CMD2Model8animlistE, i64 0, i64 %14
  %16 = getelementptr inbounds %struct.anim_t, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 4, !tbaa !11
  %18 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %19 = getelementptr inbounds %struct.animState_t, ptr %18, i32 0, i32 0
  store i32 %17, ptr %19, align 4, !tbaa !13
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [21 x %struct.anim_t], ptr @_ZN9CMD2Model8animlistE, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.anim_t, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %25 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %26 = getelementptr inbounds %struct.animState_t, ptr %25, i32 0, i32 1
  store i32 %24, ptr %26, align 4, !tbaa !18
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [21 x %struct.anim_t], ptr @_ZN9CMD2Model8animlistE, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.anim_t, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !11
  %32 = add nsw i32 %31, 1
  %33 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %34 = getelementptr inbounds %struct.animState_t, ptr %33, i32 0, i32 8
  store i32 %32, ptr %34, align 4, !tbaa !19
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [21 x %struct.anim_t], ptr @_ZN9CMD2Model8animlistE, i64 0, i64 %36
  %38 = getelementptr inbounds %struct.anim_t, ptr %37, i32 0, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !20
  %40 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %41 = getelementptr inbounds %struct.animState_t, ptr %40, i32 0, i32 2
  store i32 %39, ptr %41, align 4, !tbaa !21
  %42 = load i32, ptr %4, align 4, !tbaa !9
  %43 = getelementptr inbounds %class.CMD2Model, ptr %5, i32 0, i32 8
  %44 = getelementptr inbounds %struct.animState_t, ptr %43, i32 0, i32 6
  store i32 %42, ptr %44, 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 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"_ZTS6anim_t", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!14, !10, i64 44}
!14 = !{!"_ZTS9CMD2Model", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !15, i64 44, !16, i64 80}
!15 = !{!"_ZTS11animState_t", !10, i64 0, !10, i64 4, !10, i64 8, !16, i64 12, !16, i64 16, !16, i64 20, !10, i64 24, !10, i64 28, !10, i64 32}
!16 = !{!"float", !7, i64 0}
!17 = !{!12, !10, i64 4}
!18 = !{!14, !10, i64 48}
!19 = !{!14, !10, i64 76}
!20 = !{!12, !10, i64 8}
!21 = !{!14, !10, i64 52}
!22 = !{!14, !10, i64 68}


; 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.anim_t = type { i32, i32, i32 }

@_ZN9CMD2Model8animlistE = external dso_local local_unnamed_addr global [21 x %struct.anim_t], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @_ZN9CMD2Model7SetAnimEi(ptr nocapture noundef nonnull writeonly align 8 dereferenceable(84) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %or.cond = icmp ugt i32 %1, 20
  %spec.store.select = select i1 %or.cond, i32 0, i32 %1
  %3 = zext nneg i32 %spec.store.select to i64
  %4 = getelementptr inbounds [21 x %struct.anim_t], ptr @_ZN9CMD2Model8animlistE, i64 0, i64 %3
  %5 = getelementptr inbounds i8, ptr %0, i64 44
  %6 = load <2 x i32>, ptr %4, align 4, !tbaa !5
  store <2 x i32> %6, ptr %5, align 4, !tbaa !5
  %7 = extractelement <2 x i32> %6, i64 0
  %8 = add nsw i32 %7, 1
  %9 = getelementptr inbounds i8, ptr %0, i64 76
  store i32 %8, ptr %9, align 4, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %4, i64 8
  %11 = load i32, ptr %10, align 4, !tbaa !14
  %12 = getelementptr inbounds i8, ptr %0, i64 52
  store i32 %11, ptr %12, align 4, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %0, i64 68
  store i32 %spec.store.select, ptr %13, align 4, !tbaa !17
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: write, inaccessiblemem: 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 76}
!10 = !{!"_ZTS9CMD2Model", !6, i64 0, !6, i64 4, !6, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !12, i64 44, !13, i64 80}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"_ZTS11animState_t", !6, i64 0, !6, i64 4, !6, i64 8, !13, i64 12, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 28, !6, i64 32}
!13 = !{!"float", !7, i64 0}
!14 = !{!15, !6, i64 8}
!15 = !{!"_ZTS6anim_t", !6, i64 0, !6, i64 4, !6, i64 8}
!16 = !{!10, !6, i64 52}
!17 = !{!10, !6, i64 68}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass