; LLVM IR from aap/librw :: src/geometry.ll (ZN2rw8Geometry18hasColoredMaterialEv)

; 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::Geometry" = type { %"struct.rw::Object", i32, i16, i32, i32, i32, i32, ptr, ptr, [8 x ptr], ptr, %"struct.rw::MaterialList", ptr, ptr, i32 }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::MaterialList" = type { ptr, i32, i32 }
%"struct.rw::Material" = type { ptr, %"struct.rw::RGBA", %"struct.rw::SurfaceProperties", ptr, i32 }
%"struct.rw::RGBA" = type { i8, i8, i8, i8 }
%"struct.rw::SurfaceProperties" = type { float, float, float }

; 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 noundef i32 @_ZN2rw8Geometry18hasColoredMaterialEv(ptr noundef nonnull align 8 dereferenceable(168) %0) #1 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %68, %1
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = getelementptr inbounds %"struct.rw::Geometry", ptr %6, i32 0, i32 11
  %10 = getelementptr inbounds %"struct.rw::MaterialList", ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !11
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  store i32 2, ptr %5, align 4
  br label %71

14:                                               ; preds = %7
  %15 = getelementptr inbounds %"struct.rw::Geometry", ptr %6, i32 0, i32 11
  %16 = getelementptr inbounds %"struct.rw::MaterialList", ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = load i32, ptr %4, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds ptr, ptr %17, i64 %19
  %21 = load ptr, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds %"struct.rw::Material", ptr %21, i32 0, i32 1
  %23 = getelementptr inbounds %"struct.rw::RGBA", ptr %22, i32 0, i32 0
  %24 = load i8, ptr %23, align 8, !tbaa !17
  %25 = zext i8 %24 to i32
  %26 = icmp ne i32 %25, 255
  br i1 %26, label %66, label %27

27:                                               ; preds = %14
  %28 = getelementptr inbounds %"struct.rw::Geometry", ptr %6, i32 0, i32 11
  %29 = getelementptr inbounds %"struct.rw::MaterialList", ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = load i32, ptr %4, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds ptr, ptr %30, i64 %32
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds %"struct.rw::Material", ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %"struct.rw::RGBA", ptr %35, i32 0, i32 1
  %37 = load i8, ptr %36, align 1, !tbaa !22
  %38 = zext i8 %37 to i32
  %39 = icmp ne i32 %38, 255
  br i1 %39, label %66, label %40

40:                                               ; preds = %27
  %41 = getelementptr inbounds %"struct.rw::Geometry", ptr %6, i32 0, i32 11
  %42 = getelementptr inbounds %"struct.rw::MaterialList", ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !16
  %44 = load i32, ptr %4, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds ptr, ptr %43, i64 %45
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = getelementptr inbounds %"struct.rw::Material", ptr %47, i32 0, i32 1
  %49 = getelementptr inbounds %"struct.rw::RGBA", ptr %48, i32 0, i32 2
  %50 = load i8, ptr %49, align 2, !tbaa !23
  %51 = zext i8 %50 to i32
  %52 = icmp ne i32 %51, 255
  br i1 %52, label %66, label %53

53:                                               ; preds = %40
  %54 = getelementptr inbounds %"struct.rw::Geometry", ptr %6, i32 0, i32 11
  %55 = getelementptr inbounds %"struct.rw::MaterialList", ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !16
  %57 = load i32, ptr %4, align 4, !tbaa !9
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds ptr, ptr %56, i64 %58
  %60 = load ptr, ptr %59, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.rw::Material", ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds %"struct.rw::RGBA", ptr %61, i32 0, i32 3
  %63 = load i8, ptr %62, align 1, !tbaa !24
  %64 = zext i8 %63 to i32
  %65 = icmp ne i32 %64, 255
  br i1 %65, label %66, label %67

66:                                               ; preds = %53, %40, %27, %14
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %71

67:                                               ; preds = %53
  br label %68

68:                                               ; preds = %67
  %69 = load i32, ptr %4, align 4, !tbaa !9
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %4, align 4, !tbaa !9
  br label %7, !llvm.loop !25

71:                                               ; preds = %66, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %72 = load i32, ptr %5, align 4
  switch i32 %72, label %76 [
    i32 2, label %73
    i32 1, label %74
  ]

73:                                               ; preds = %71
  store i32 0, ptr %2, align 4
  br label %74

74:                                               ; preds = %73, %71
  %75 = load i32, ptr %2, align 4
  ret i32 %75

76:                                               ; preds = %71
  unreachable
}

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 = { 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, !10, i64 136}
!12 = !{!"_ZTSN2rw8GeometryE", !13, i64 0, !10, i64 16, !14, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !7, i64 56, !6, i64 120, !15, i64 128, !6, i64 144, !6, i64 152, !10, i64 160}
!13 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!"_ZTSN2rw12MaterialListE", !6, i64 0, !10, i64 8, !10, i64 12}
!16 = !{!12, !6, i64 128}
!17 = !{!18, !7, i64 8}
!18 = !{!"_ZTSN2rw8MaterialE", !6, i64 0, !19, i64 8, !20, i64 12, !6, i64 24, !10, i64 32}
!19 = !{!"_ZTSN2rw4RGBAE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3}
!20 = !{!"_ZTSN2rw17SurfacePropertiesE", !21, i64 0, !21, i64 4, !21, i64 8}
!21 = !{!"float", !7, i64 0}
!22 = !{!18, !7, i64 9}
!23 = !{!18, !7, i64 10}
!24 = !{!18, !7, i64 11}
!25 = distinct !{!25, !26}
!26 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN2rw8Geometry18hasColoredMaterialEv(ptr nocapture noundef nonnull readonly align 8 dereferenceable(168) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 136
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %.not1314 = icmp sgt i32 %3, 0
  br i1 %.not1314, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %4 = getelementptr inbounds i8, ptr %0, i64 128
  %5 = load ptr, ptr %4, align 8, !tbaa !14
  %6 = zext nneg i32 %3 to i64
  %wide.trip.count = zext nneg i32 %3 to i64
  %7 = load ptr, ptr %5, align 8, !tbaa !15
  %8 = getelementptr inbounds i8, ptr %7, i64 8
  %9 = load i8, ptr %8, align 8, !tbaa !16
  %.not25 = icmp eq i8 %9, -1
  br i1 %.not25, label %.lr.ph28, label %._crit_edge

10:                                               ; preds = %22
  %indvars.iv.next = add nuw nsw i64 %indvars.iv26, 1
  %.not13 = icmp ult i64 %indvars.iv.next, %6
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.loopexit.loopexit, label %11, !llvm.loop !21

11:                                               ; preds = %10
  %12 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.next
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  %15 = load i8, ptr %14, align 8, !tbaa !16
  %.not = icmp eq i8 %15, -1
  br i1 %.not, label %.lr.ph28, label %._crit_edge.loopexit.loopexit, !llvm.loop !21

.lr.ph28:                                         ; preds = %.lr.ph, %11
  %16 = phi ptr [ %13, %11 ], [ %7, %.lr.ph ]
  %.not131627 = phi i1 [ %.not13, %11 ], [ true, %.lr.ph ]
  %indvars.iv26 = phi i64 [ %indvars.iv.next, %11 ], [ 0, %.lr.ph ]
  %17 = getelementptr inbounds i8, ptr %16, i64 9
  %18 = load i8, ptr %17, align 1, !tbaa !23
  %.not10 = icmp eq i8 %18, -1
  br i1 %.not10, label %19, label %._crit_edge.loopexit.loopexit

19:                                               ; preds = %.lr.ph28
  %20 = getelementptr inbounds i8, ptr %16, i64 10
  %21 = load i8, ptr %20, align 2, !tbaa !24
  %.not11 = icmp eq i8 %21, -1
  br i1 %.not11, label %22, label %._crit_edge.loopexit.loopexit

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %16, i64 11
  %24 = load i8, ptr %23, align 1, !tbaa !25
  %.not12 = icmp eq i8 %24, -1
  br i1 %.not12, label %10, label %._crit_edge.loopexit.loopexit

._crit_edge.loopexit.loopexit:                    ; preds = %11, %.lr.ph28, %19, %22, %10
  %.not13.lcssa.ph.ph = phi i1 [ %.not13, %10 ], [ %.not131627, %22 ], [ %.not131627, %19 ], [ %.not131627, %.lr.ph28 ], [ %.not13, %11 ]
  %25 = zext i1 %.not13.lcssa.ph.ph to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %._crit_edge.loopexit.loopexit, %1
  %.not13.lcssa = phi i32 [ 0, %1 ], [ 1, %.lr.ph ], [ %25, %._crit_edge.loopexit.loopexit ]
  ret i32 %.not13.lcssa
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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, !11, i64 136}
!6 = !{!"_ZTSN2rw8GeometryE", !7, i64 0, !11, i64 16, !12, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !10, i64 40, !10, i64 48, !8, i64 56, !10, i64 120, !13, i64 128, !10, i64 144, !10, i64 152, !11, i64 160}
!7 = !{!"_ZTSN2rw6ObjectE", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3, !10, i64 8}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"short", !8, i64 0}
!13 = !{!"_ZTSN2rw12MaterialListE", !10, i64 0, !11, i64 8, !11, i64 12}
!14 = !{!6, !10, i64 128}
!15 = !{!10, !10, i64 0}
!16 = !{!17, !8, i64 8}
!17 = !{!"_ZTSN2rw8MaterialE", !10, i64 0, !18, i64 8, !19, i64 12, !10, i64 24, !11, i64 32}
!18 = !{!"_ZTSN2rw4RGBAE", !8, i64 0, !8, i64 1, !8, i64 2, !8, i64 3}
!19 = !{!"_ZTSN2rw17SurfacePropertiesE", !20, i64 0, !20, i64 4, !20, i64 8}
!20 = !{!"float", !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!17, !8, i64 9}
!24 = !{!17, !8, i64 10}
!25 = !{!17, !8, i64 11}


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