; LLVM IR from aap/librw :: src/skin.ll (ZN2rw4Skin13findUsedBonesEi)

; 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.rw::Skin" = type { i32, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, ptr, ptr, ptr, i32 }

; 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: mustprogress nounwind uwtable
define dso_local void @_ZN2rw4Skin13findUsedBonesEi(ptr noundef nonnull align 8 dereferenceable(112) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [256 x i8], align 16
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %10 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 256, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = getelementptr inbounds %"struct.rw::Skin", ptr %10, i32 0, i32 5
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = getelementptr inbounds %"struct.rw::Skin", ptr %10, i32 0, i32 6
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %15, i8 0, i64 256, i1 false)
  br label %16

16:                                               ; preds = %60, %2
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr %4, align 4, !tbaa !9
  %19 = icmp ne i32 %17, 0
  br i1 %19, label %20, label %65

20:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %57, %20
  %22 = load i32, ptr %8, align 4, !tbaa !9
  %23 = getelementptr inbounds %"struct.rw::Skin", ptr %10, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = icmp slt i32 %22, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %60

27:                                               ; preds = %21
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i32, ptr %8, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds float, ptr %28, i64 %30
  %32 = load float, ptr %31, align 4, !tbaa !15
  %33 = fcmp oeq float %32, 0.000000e+00
  br i1 %33, label %34, label %35

34:                                               ; preds = %27
  br label %57

35:                                               ; preds = %27
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = load i32, ptr %8, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i8, ptr %36, i64 %38
  %40 = load i8, ptr %39, align 1, !tbaa !17
  %41 = zext i8 %40 to i64
  %42 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !17
  %44 = zext i8 %43 to i32
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %56

46:                                               ; preds = %35
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  %51 = load i8, ptr %50, align 1, !tbaa !17
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !17
  %55 = add i8 %54, 1
  store i8 %55, ptr %53, align 1, !tbaa !17
  br label %56

56:                                               ; preds = %46, %35
  br label %57

57:                                               ; preds = %56, %34
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %8, align 4, !tbaa !9
  br label %21, !llvm.loop !18

60:                                               ; preds = %26
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 4
  store ptr %62, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds float, ptr %63, i64 4
  store ptr %64, ptr %7, align 8, !tbaa !5
  br label %16, !llvm.loop !20

65:                                               ; preds = %16
  %66 = getelementptr inbounds %"struct.rw::Skin", ptr %10, i32 0, i32 1
  store i32 0, ptr %66, align 4, !tbaa !21
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %88, %65
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = icmp slt i32 %68, 256
  br i1 %69, label %71, label %70

70:                                               ; preds = %67
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %91

71:                                               ; preds = %67
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [256 x i8], ptr %5, i64 0, i64 %73
  %75 = load i8, ptr %74, align 1, !tbaa !17
  %76 = icmp ne i8 %75, 0
  br i1 %76, label %77, label %87

77:                                               ; preds = %71
  %78 = load i32, ptr %9, align 4, !tbaa !9
  %79 = trunc i32 %78 to i8
  %80 = getelementptr inbounds %"struct.rw::Skin", ptr %10, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !22
  %82 = getelementptr inbounds %"struct.rw::Skin", ptr %10, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !21
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %82, align 4, !tbaa !21
  %85 = sext i32 %83 to i64
  %86 = getelementptr inbounds i8, ptr %81, i64 %85
  store i8 %79, ptr %86, align 1, !tbaa !17
  br label %87

87:                                               ; preds = %77, %71
  br label %88

88:                                               ; preds = %87
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = add nsw i32 %89, 1
  store i32 %90, ptr %9, align 4, !tbaa !9
  br label %67, !llvm.loop !23

91:                                               ; preds = %70
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 256, ptr %5) #3
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !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, !6, i64 32}
!12 = !{!"_ZTSN2rw4SkinE", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !10, i64 48, !10, i64 52, !10, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !10, i64 104}
!13 = !{!12, !6, i64 40}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !7, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = distinct !{!20, !19}
!21 = !{!12, !10, i64 4}
!22 = !{!12, !6, i64 16}
!23 = distinct !{!23, !19}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN2rw4Skin13findUsedBonesEi(ptr nocapture noundef nonnull align 8 dereferenceable(112) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca [256 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 256, ptr nonnull %3) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(256) %3, i8 0, i64 256, i1 false)
  %.not21 = icmp eq i32 %1, 0
  br i1 %.not21, label %._crit_edge24, label %.preheader.lr.ph

.preheader.lr.ph:                                 ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = icmp sgt i32 %9, 0
  br i1 %10, label %.preheader.us.preheader, label %._crit_edge24

.preheader.us.preheader:                          ; preds = %.preheader.lr.ph
  %wide.trip.count = zext nneg i32 %9 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %11 = icmp eq i32 %9, 1
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.in = phi i32 [ %12, %._crit_edge.us ], [ %1, %.preheader.us.preheader ]
  %.01623.us = phi ptr [ %43, %._crit_edge.us ], [ %7, %.preheader.us.preheader ]
  %.01722.us = phi ptr [ %42, %._crit_edge.us ], [ %5, %.preheader.us.preheader ]
  %12 = add nsw i32 %.in, -1
  br i1 %11, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %32
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %32 ], [ 0, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %32 ], [ 0, %.preheader.us ]
  %13 = getelementptr inbounds float, ptr %.01623.us, i64 %indvars.iv
  %14 = load float, ptr %13, align 4, !tbaa !13
  %15 = fcmp oeq float %14, 0.000000e+00
  br i1 %15, label %22, label %16

16:                                               ; preds = %.preheader.us.new
  %17 = getelementptr inbounds i8, ptr %.01722.us, i64 %indvars.iv
  %18 = load i8, ptr %17, align 1, !tbaa !15
  %19 = zext i8 %18 to i64
  %20 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 %19
  %21 = load i8, ptr %20, align 1, !tbaa !15
  %spec.store.select.us = tail call i8 @llvm.umax.i8(i8 %21, i8 1)
  store i8 %spec.store.select.us, ptr %20, align 1
  br label %22

22:                                               ; preds = %16, %.preheader.us.new
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %23 = getelementptr inbounds float, ptr %.01623.us, i64 %indvars.iv.next
  %24 = load float, ptr %23, align 4, !tbaa !13
  %25 = fcmp oeq float %24, 0.000000e+00
  br i1 %25, label %32, label %26

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %.01722.us, i64 %indvars.iv.next
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = zext i8 %28 to i64
  %30 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !15
  %spec.store.select.us.1 = tail call i8 @llvm.umax.i8(i8 %31, i8 1)
  store i8 %spec.store.select.us.1, ptr %30, align 1
  br label %32

32:                                               ; preds = %26, %22
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !16

._crit_edge.us.unr-lcssa:                         ; preds = %32, %.preheader.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next.1, %32 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %33 = getelementptr inbounds float, ptr %.01623.us, i64 %indvars.iv.unr
  %34 = load float, ptr %33, align 4, !tbaa !13
  %35 = fcmp oeq float %34, 0.000000e+00
  br i1 %35, label %._crit_edge.us, label %36

36:                                               ; preds = %.epil.preheader
  %37 = getelementptr inbounds i8, ptr %.01722.us, i64 %indvars.iv.unr
  %38 = load i8, ptr %37, align 1, !tbaa !15
  %39 = zext i8 %38 to i64
  %40 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !15
  %spec.store.select.us.epil = tail call i8 @llvm.umax.i8(i8 %41, i8 1)
  store i8 %spec.store.select.us.epil, ptr %40, align 1
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %36, %._crit_edge.us.unr-lcssa
  %42 = getelementptr inbounds i8, ptr %.01722.us, i64 4
  %43 = getelementptr inbounds i8, ptr %.01623.us, i64 16
  %.not.us = icmp eq i32 %12, 0
  br i1 %.not.us, label %._crit_edge24, label %.preheader.us, !llvm.loop !18

._crit_edge24:                                    ; preds = %._crit_edge.us, %.preheader.lr.ph, %2
  %44 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 0, ptr %44, align 4, !tbaa !19
  %45 = getelementptr inbounds i8, ptr %0, i64 16
  br label %47

46:                                               ; preds = %67
  call void @llvm.lifetime.end.p0(i64 256, ptr nonnull %3) #4
  ret void

47:                                               ; preds = %67, %._crit_edge24
  %indvars.iv28 = phi i64 [ 0, %._crit_edge24 ], [ %indvars.iv.next29.1, %67 ]
  %48 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 %indvars.iv28
  %49 = load i8, ptr %48, align 2, !tbaa !15
  %.not19 = icmp eq i8 %49, 0
  br i1 %.not19, label %57, label %50

50:                                               ; preds = %47
  %51 = trunc i64 %indvars.iv28 to i8
  %52 = load ptr, ptr %45, align 8, !tbaa !20
  %53 = load i32, ptr %44, align 4, !tbaa !19
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %44, align 4, !tbaa !19
  %55 = sext i32 %53 to i64
  %56 = getelementptr inbounds i8, ptr %52, i64 %55
  store i8 %51, ptr %56, align 1, !tbaa !15
  br label %57

57:                                               ; preds = %47, %50
  %indvars.iv.next29 = or disjoint i64 %indvars.iv28, 1
  %58 = getelementptr inbounds [256 x i8], ptr %3, i64 0, i64 %indvars.iv.next29
  %59 = load i8, ptr %58, align 1, !tbaa !15
  %.not19.1 = icmp eq i8 %59, 0
  br i1 %.not19.1, label %67, label %60

60:                                               ; preds = %57
  %61 = trunc i64 %indvars.iv.next29 to i8
  %62 = load ptr, ptr %45, align 8, !tbaa !20
  %63 = load i32, ptr %44, align 4, !tbaa !19
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %44, align 4, !tbaa !19
  %65 = sext i32 %63 to i64
  %66 = getelementptr inbounds i8, ptr %62, i64 %65
  store i8 %61, ptr %66, align 1, !tbaa !15
  br label %67

67:                                               ; preds = %60, %57
  %indvars.iv.next29.1 = add nuw nsw i64 %indvars.iv28, 2
  %exitcond31.not.1 = icmp eq i64 %indvars.iv.next29.1, 256
  br i1 %exitcond31.not.1, label %46, label %47, !llvm.loop !21
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, 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" }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 32}
!6 = !{!"_ZTSN2rw4SkinE", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !7, i64 48, !7, i64 52, !7, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !7, i64 104}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 40}
!12 = !{!6, !7, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !8, i64 0}
!15 = !{!8, !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!6, !7, i64 4}
!20 = !{!6, !10, i64 16}
!21 = distinct !{!21, !17}


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