; LLVM IR from evanxg852000/rockstartdev :: clox (table)

; 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.Table = type { i32, i32, ptr }
%struct.Entry = type { ptr, %struct.Value }
%struct.Value = type { i32, %union.anon }
%union.anon = type { double }
%struct.sObjString = type { %struct.sObj, i32, ptr, i32 }
%struct.sObj = type { i32, i8, ptr }

; 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 ptr @tableFindString(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Table, ptr %13, i32 0, i32 0
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  br label %86

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Table, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = urem i32 %19, %22
  store i32 %23, ptr %10, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %84, %18
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.Table, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %struct.Entry, ptr %27, i64 %29
  store ptr %30, ptr %11, align 8, !tbaa !5
  %31 = load ptr, ptr %11, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Entry, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %43

35:                                               ; preds = %24
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Entry, ptr %36, i32 0, i32 1
  %38 = getelementptr inbounds %struct.Value, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !18
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store ptr null, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

42:                                               ; preds = %35
  br label %75

43:                                               ; preds = %24
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.Entry, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !15
  %47 = getelementptr inbounds %struct.sObjString, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = icmp eq i32 %48, %49
  br i1 %50, label %51, label %74

51:                                               ; preds = %43
  %52 = load ptr, ptr %11, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.Entry, ptr %52, i32 0, i32 0
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = getelementptr inbounds %struct.sObjString, ptr %54, i32 0, i32 3
  %56 = load i32, ptr %55, align 8, !tbaa !23
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = icmp eq i32 %56, %57
  br i1 %58, label %59, label %74

59:                                               ; preds = %51
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Entry, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !15
  %63 = getelementptr inbounds %struct.sObjString, ptr %62, i32 0, i32 2
  %64 = load ptr, ptr %63, align 8, !tbaa !24
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = call i32 @memcmp(ptr noundef %64, ptr noundef %65, i64 noundef %67) #4
  %69 = icmp eq i32 %68, 0
  br i1 %69, label %70, label %74

70:                                               ; preds = %59
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.Entry, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !15
  store ptr %73, ptr %5, align 8
  store i32 1, ptr %12, align 4
  br label %82

74:                                               ; preds = %59, %51, %43
  br label %75

75:                                               ; preds = %74, %42
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = add i32 %76, 1
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Table, ptr %78, i32 0, i32 1
  %80 = load i32, ptr %79, align 4, !tbaa !13
  %81 = urem i32 %77, %80
  store i32 %81, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %82

82:                                               ; preds = %75, %70, %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %83 = load i32, ptr %12, align 4
  switch i32 %83, label %85 [
    i32 0, label %84
  ]

84:                                               ; preds = %82
  br label %24

85:                                               ; preds = %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %86

86:                                               ; preds = %85, %17
  %87 = load ptr, ptr %5, align 8
  ret ptr %87
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @memcmp(ptr noundef, ptr noundef, i64 noundef) #2

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 = { nounwind willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !17, i64 8}
!17 = !{!"", !10, i64 0, !7, i64 8}
!18 = !{!16, !10, i64 8}
!19 = !{!20, !10, i64 16}
!20 = !{!"sObjString", !21, i64 0, !10, i64 16, !6, i64 24, !10, i64 32}
!21 = !{!"sObj", !10, i64 0, !22, i64 4, !6, i64 8}
!22 = !{!"_Bool", !7, i64 0}
!23 = !{!20, !10, i64 32}
!24 = !{!20, !6, i64 24}


; 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.Entry = type { ptr, %struct.Value }
%struct.Value = type { i32, %union.anon }
%union.anon = type { double }

; Function Attrs: nofree nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @tableFindString(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %.thread, label %7

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = sext i32 %2 to i64
  br label %13

13:                                               ; preds = %34, %7
  %.pn = phi i32 [ %3, %7 ], [ %35, %34 ]
  %.019 = urem i32 %.pn, %9
  %14 = zext i32 %.019 to i64
  %15 = getelementptr inbounds %struct.Entry, ptr %11, i64 %14
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %22

18:                                               ; preds = %13
  %19 = getelementptr inbounds i8, ptr %15, i64 8
  %20 = load i32, ptr %19, align 8, !tbaa !16
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %.thread, label %34

22:                                               ; preds = %13
  %23 = getelementptr inbounds i8, ptr %16, i64 16
  %24 = load i32, ptr %23, align 8, !tbaa !17
  %25 = icmp eq i32 %24, %2
  br i1 %25, label %26, label %34

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %16, i64 32
  %28 = load i32, ptr %27, align 8, !tbaa !21
  %29 = icmp eq i32 %28, %3
  br i1 %29, label %30, label %34

30:                                               ; preds = %26
  %31 = getelementptr inbounds i8, ptr %16, i64 24
  %32 = load ptr, ptr %31, align 8, !tbaa !22
  %bcmp = tail call i32 @bcmp(ptr %32, ptr %1, i64 %12)
  %33 = icmp eq i32 %bcmp, 0
  br i1 %33, label %.thread, label %34

34:                                               ; preds = %18, %30, %26, %22
  %35 = add nuw i32 %.019, 1
  br label %13

.thread:                                          ; preds = %30, %18, %4
  %.2 = phi ptr [ null, %4 ], [ null, %18 ], [ %16, %30 ]
  ret ptr %.2
}

; Function Attrs: nofree nounwind willreturn memory(argmem: read)
declare i32 @bcmp(ptr nocapture, ptr nocapture, i64) local_unnamed_addr #1

attributes #0 = { nofree nounwind 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" }
attributes #1 = { nofree nounwind willreturn memory(argmem: read) }

!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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !10, i64 8}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !15, i64 8}
!15 = !{!"", !7, i64 0, !8, i64 8}
!16 = !{!14, !7, i64 8}
!17 = !{!18, !7, i64 16}
!18 = !{!"sObjString", !19, i64 0, !7, i64 16, !10, i64 24, !7, i64 32}
!19 = !{!"sObj", !7, i64 0, !20, i64 4, !10, i64 8}
!20 = !{!"_Bool", !8, i64 0}
!21 = !{!18, !7, i64 32}
!22 = !{!18, !10, i64 24}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass