; LLVM IR from attractivechaos/klib :: test (kavl_test)

; 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.kavl_itr_my = type { [64 x ptr], ptr }
%struct.my_node = type { i32, %struct.anon }
%struct.anon = type { [2 x ptr], i8, 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
define dso_local i32 @kavl_itr_find_my(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %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 i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %7, align 8, !tbaa !5
  %11 = load ptr, ptr %6, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.kavl_itr_my, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [64 x ptr], ptr %12, i64 0, i64 0
  %14 = getelementptr inbounds ptr, ptr %13, i64 -1
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.kavl_itr_my, ptr %15, i32 0, i32 1
  store ptr %14, ptr %16, align 8, !tbaa !9
  br label %17

17:                                               ; preds = %65, %3
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %66

20:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.kavl_itr_my, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds ptr, ptr %24, i32 1
  store ptr %25, ptr %23, align 8, !tbaa !9
  store ptr %21, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.my_node, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 8, !tbaa !11
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.my_node, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = icmp sgt i32 %28, %31
  %33 = zext i1 %32 to i32
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.my_node, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.my_node, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !11
  %40 = icmp slt i32 %36, %39
  %41 = zext i1 %40 to i32
  %42 = sub nsw i32 %33, %41
  store i32 %42, ptr %8, align 4, !tbaa !15
  %43 = load i32, ptr %8, align 4, !tbaa !15
  %44 = icmp slt i32 %43, 0
  br i1 %44, label %45, label %51

45:                                               ; preds = %20
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.my_node, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.anon, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [2 x ptr], ptr %48, i64 0, i64 0
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  store ptr %50, ptr %7, align 8, !tbaa !5
  br label %62

51:                                               ; preds = %20
  %52 = load i32, ptr %8, align 4, !tbaa !15
  %53 = icmp sgt i32 %52, 0
  br i1 %53, label %54, label %60

54:                                               ; preds = %51
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.my_node, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.anon, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [2 x ptr], ptr %57, i64 0, i64 1
  %59 = load ptr, ptr %58, align 8, !tbaa !5
  store ptr %59, ptr %7, align 8, !tbaa !5
  br label %61

60:                                               ; preds = %51
  store i32 3, ptr %9, align 4
  br label %63

61:                                               ; preds = %54
  br label %62

62:                                               ; preds = %61, %45
  store i32 0, ptr %9, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %64 = load i32, ptr %9, align 4
  switch i32 %64, label %71 [
    i32 0, label %65
    i32 3, label %66
  ]

65:                                               ; preds = %63
  br label %17, !llvm.loop !16

66:                                               ; preds = %63, %17
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = icmp ne ptr %67, null
  %69 = zext i1 %68 to i64
  %70 = select i1 %68, i32 1, i32 0
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 %70

71:                                               ; preds = %63
  unreachable
}

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, !6, i64 512}
!10 = !{!"kavl_itr_my", !7, i64 0, !6, i64 512}
!11 = !{!12, !13, i64 0}
!12 = !{!"my_node", !13, i64 0, !14, i64 8}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !7, i64 0, !7, i64 16, !13, i64 20}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @kavl_itr_find_my(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 -8
  %5 = getelementptr inbounds i8, ptr %2, i64 512
  store ptr %4, ptr %5, align 8, !tbaa !5
  %.not22 = icmp eq ptr %0, null
  br i1 %.not22, label %.thread, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = load i32, ptr %1, align 8, !tbaa !10
  br label %7

7:                                                ; preds = %.lr.ph, %17
  %.01523 = phi ptr [ %0, %.lr.ph ], [ %.1, %17 ]
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  store ptr %9, ptr %5, align 8, !tbaa !5
  store ptr %.01523, ptr %9, align 8, !tbaa !14
  %10 = load i32, ptr %.01523, align 8, !tbaa !10
  %11 = icmp sgt i32 %6, %10
  %12 = zext i1 %11 to i32
  %13 = icmp slt i32 %6, %10
  %.neg = sext i1 %13 to i32
  %14 = add nsw i32 %.neg, %12
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %17, label %16

16:                                               ; preds = %7
  %.not17 = icmp eq i32 %14, 0
  br i1 %.not17, label %.thread, label %17

17:                                               ; preds = %16, %7
  %.sink = phi i64 [ 8, %7 ], [ 16, %16 ]
  %18 = getelementptr inbounds i8, ptr %.01523, i64 %.sink
  %.1 = load ptr, ptr %18, align 8, !tbaa !14
  %.not = icmp eq ptr %.1, null
  br i1 %.not, label %.thread, label %7

.thread:                                          ; preds = %17, %16, %3
  %.015.lcssa = phi i32 [ 0, %3 ], [ 1, %16 ], [ 0, %17 ]
  ret i32 %.015.lcssa
}

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

!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, !9, i64 512}
!6 = !{!"kavl_itr_my", !7, i64 0, !9, i64 512}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"my_node", !12, i64 0, !13, i64 8}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 16, !12, i64 20}
!14 = !{!9, !9, i64 0}


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