; LLVM IR from madmann91/TheBox :: src/collision (tbPairs)

; 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.tbPairTable_s = type { ptr, i32, ptr, ptr, i32, i32 }
%struct.tbIndexList_s = type { i32, i32 }
%struct.tbPair_s = type { i32, 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: nounwind uwtable
declare hidden i32 @tbHashPair(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @tbGetPair(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = call i32 @tbHashPair(ptr noundef %10, ptr noundef %11)
  store i32 %12, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.tbPairTable_s, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = zext i32 %16 to i64
  %18 = getelementptr inbounds i32, ptr %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %19, ptr %7, align 4, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp sge i32 %20, 0
  br i1 %21, label %22, label %84

22:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.tbPairTable_s, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds %struct.tbIndexList_s, ptr %25, i64 %27
  store ptr %28, ptr %8, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %79, %22
  br label %30

30:                                               ; preds = %29
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.tbPairTable_s, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.tbIndexList_s, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !15
  %37 = zext i32 %36 to i64
  %38 = getelementptr inbounds %struct.tbPair_s, ptr %33, i64 %37
  %39 = getelementptr inbounds %struct.tbPair_s, ptr %38, i32 0, i32 0
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.tbPair_s, ptr %41, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !17
  %44 = icmp eq i32 %40, %43
  br i1 %44, label %45, label %64

45:                                               ; preds = %30
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.tbPairTable_s, ptr %46, i32 0, i32 2
  %48 = load ptr, ptr %47, align 8, !tbaa !14
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.tbIndexList_s, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 4, !tbaa !15
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds %struct.tbPair_s, ptr %48, i64 %52
  %54 = getelementptr inbounds %struct.tbPair_s, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 4, !tbaa !19
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.tbPair_s, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 4, !tbaa !19
  %59 = icmp eq i32 %55, %58
  br i1 %59, label %60, label %64

60:                                               ; preds = %45
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.tbIndexList_s, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 4, !tbaa !15
  store i32 %63, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %81

64:                                               ; preds = %45, %30
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.tbIndexList_s, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 4, !tbaa !20
  %68 = icmp sgt i32 %67, 0
  br i1 %68, label %69, label %78

69:                                               ; preds = %64
  %70 = load ptr, ptr %4, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.tbPairTable_s, ptr %70, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.tbIndexList_s, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 4, !tbaa !20
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds %struct.tbIndexList_s, ptr %72, i64 %76
  store ptr %77, ptr %8, align 8, !tbaa !5
  br label %79

78:                                               ; preds = %64
  br label %80

79:                                               ; preds = %69
  br label %29

80:                                               ; preds = %78
  store i32 0, ptr %9, align 4
  br label %81

81:                                               ; preds = %80, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %82 = load i32, ptr %9, align 4
  switch i32 %82, label %85 [
    i32 0, label %83
  ]

83:                                               ; preds = %81
  br label %84

84:                                               ; preds = %83, %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %85

85:                                               ; preds = %84, %81
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %86 = load i32, ptr %3, align 4
  ret i32 %86
}

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 }

!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, !6, i64 0}
!12 = !{!"tbPairTable_s", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !10, i64 36}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !6, i64 16}
!15 = !{!16, !10, i64 4}
!16 = !{!"tbIndexList_s", !10, i64 0, !10, i64 4}
!17 = !{!18, !10, i64 0}
!18 = !{!"tbPair_s", !10, i64 0, !10, i64 4}
!19 = !{!18, !10, i64 4}
!20 = !{!16, !10, i64 0}


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

; Function Attrs: nounwind uwtable
declare hidden i32 @tbHashPair(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @tbGetPair(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @tbHashPair(ptr noundef %0, ptr noundef %1)
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = zext i32 %3 to i64
  %6 = getelementptr inbounds i32, ptr %4, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = icmp sgt i32 %7, -1
  br i1 %8, label %9, label %.critedge

9:                                                ; preds = %2
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = load i32, ptr %1, align 4, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %1, i64 4
  br label %16

16:                                               ; preds = %28, %9
  %.pn.in = phi i32 [ %7, %9 ], [ %29, %28 ]
  %.pn = zext nneg i32 %.pn.in to i64
  %.018 = getelementptr inbounds %struct.tbIndexList_s, ptr %11, i64 %.pn
  %17 = getelementptr inbounds i8, ptr %.018, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !16
  %19 = zext i32 %18 to i64
  %20 = getelementptr inbounds %struct.tbPair_s, ptr %13, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = icmp eq i32 %21, %14
  br i1 %22, label %23, label %28

23:                                               ; preds = %16
  %24 = getelementptr inbounds i8, ptr %20, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !18
  %26 = load i32, ptr %15, align 4, !tbaa !18
  %27 = icmp eq i32 %25, %26
  br i1 %27, label %.critedge, label %28

28:                                               ; preds = %23, %16
  %29 = load i32, ptr %.018, align 4, !tbaa !19
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %16, label %.critedge

.critedge:                                        ; preds = %23, %28, %2
  %.1 = phi i32 [ -1, %2 ], [ %18, %23 ], [ -1, %28 ]
  ret i32 %.1
}

attributes #0 = { 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, !7, i64 0}
!6 = !{!"tbPairTable_s", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !10, i64 36}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 16}
!14 = !{!15, !10, i64 0}
!15 = !{!"tbPair_s", !10, i64 0, !10, i64 4}
!16 = !{!17, !10, i64 4}
!17 = !{!"tbIndexList_s", !10, i64 0, !10, i64 4}
!18 = !{!15, !10, i64 4}
!19 = !{!17, !10, i64 0}


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