; LLVM IR from aap/librw :: src/texture.ll (ZN2rw13TexDictionary4findEPKc)

; 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::TexDictionary" = type { %"struct.rw::Object", %"struct.rw::LinkList", %"struct.rw::LLLink" }
%"struct.rw::Object" = type { i8, i8, i8, i8, ptr }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Texture" = type { ptr, ptr, %"struct.rw::LLLink", [32 x i8], [32 x i8], i32, i32, %"struct.rw::LLLink" }

; 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
declare dso_local noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw13TexDictionary4findEPKc(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %10 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %11 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %10, i32 0, i32 1
  %12 = getelementptr inbounds %"struct.rw::LinkList", ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds %"struct.rw::LLLink", ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  store ptr %14, ptr %7, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %39, %2
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = getelementptr inbounds %"struct.rw::LLLink", ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.rw::TexDictionary", ptr %10, i32 0, i32 1
  %21 = call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %20)
  %22 = icmp ne ptr %19, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %15
  store i32 2, ptr %8, align 4
  br label %41

24:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef %25)
  store ptr %26, ptr %9, align 8, !tbaa !5
  %27 = load ptr, ptr %9, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.rw::Texture", ptr %27, i32 0, i32 3
  %29 = getelementptr inbounds [32 x i8], ptr %28, i64 0, i64 0
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call noundef i32 @_ZN2rw10strncmp_ciEPKcS1_i(ptr noundef %29, ptr noundef %30, i32 noundef 32)
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %35

33:                                               ; preds = %24
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %34, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %36

35:                                               ; preds = %24
  store i32 0, ptr %8, align 4
  br label %36

36:                                               ; preds = %35, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %37 = load i32, ptr %8, align 4
  switch i32 %37, label %41 [
    i32 0, label %38
  ]

38:                                               ; preds = %36
  br label %39

39:                                               ; preds = %38
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %40, ptr %7, align 8, !tbaa !5
  br label %15, !llvm.loop !15

41:                                               ; preds = %36, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %42 = load i32, ptr %8, align 4
  switch i32 %42, label %46 [
    i32 2, label %43
    i32 1, label %44
  ]

43:                                               ; preds = %41
  store ptr null, ptr %3, align 8
  br label %44

44:                                               ; preds = %43, %41
  %45 = load ptr, ptr %3, align 8
  ret ptr %45

46:                                               ; preds = %41
  unreachable
}

declare noundef i32 @_ZN2rw10strncmp_ciEPKcS1_i(ptr noundef, ptr noundef, i32 noundef) #3

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 = { mustprogress 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 #3 = { "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++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"_ZTSN2rw13TexDictionaryE", !11, i64 0, !12, i64 16, !13, i64 32}
!11 = !{!"_ZTSN2rw6ObjectE", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !6, i64 8}
!12 = !{!"_ZTSN2rw8LinkListE", !13, i64 0}
!13 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!14 = !{!13, !6, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"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 nounwind uwtable
declare dso_local noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN2rw13TexDictionary4findEPKc(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  br label %5

5:                                                ; preds = %8, %2
  %.012 = phi ptr [ %4, %2 ], [ %6, %8 ]
  %6 = load ptr, ptr %.012, align 8, !tbaa !13
  %7 = tail call noundef ptr @_ZN2rw8LinkList3endEv(ptr noundef nonnull align 8 dereferenceable(16) %3)
  %.not = icmp eq ptr %.012, %7
  br i1 %.not, label %12, label %8

8:                                                ; preds = %5
  %9 = tail call noundef ptr @_ZN2rw7Texture8fromDictEPNS_6LLLinkE(ptr noundef nonnull %.012)
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = tail call noundef i32 @_ZN2rw10strncmp_ciEPKcS1_i(ptr noundef nonnull %10, ptr noundef %1, i32 noundef 32)
  %.not13 = icmp eq i32 %11, 0
  br i1 %.not13, label %12, label %5, !llvm.loop !14

12:                                               ; preds = %5, %8
  %spec.select = phi ptr [ %9, %8 ], [ null, %5 ]
  ret ptr %spec.select
}

declare noundef i32 @_ZN2rw10strncmp_ciEPKcS1_i(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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" }
attributes #1 = { mustprogress 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" }

!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 16}
!6 = !{!"_ZTSN2rw13TexDictionaryE", !7, i64 0, !11, i64 16, !12, i64 32}
!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 = !{!"_ZTSN2rw8LinkListE", !12, i64 0}
!12 = !{!"_ZTSN2rw6LLLinkE", !10, i64 0, !10, i64 8}
!13 = !{!12, !10, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass