; LLVM IR from attractivechaos/klib :: test (kgraph_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.kh_g_s = type { i32, i32, i32, i32, ptr, ptr, ptr }
%struct.vertex_t = type { i32, ptr }
%struct.kh_e32_s = type { i32, i32, i32, i32, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @kh_destroy_e32(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @kh_get_e32(ptr noundef, i32 noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare dso_local void @kh_del_e32(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @kh_get_g(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @kh_del_g(ptr noundef, i32 noundef) #0

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

20:                                               ; preds = %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %106

21:                                               ; preds = %2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.kh_g_s, ptr %22, i32 0, i32 6
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = getelementptr inbounds %struct.vertex_t, ptr %24, i64 %26
  %28 = getelementptr inbounds %struct.vertex_t, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  store ptr %29, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %93, %21
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.kh_e32_s, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !16
  %35 = icmp ne i32 %31, %34
  br i1 %35, label %36, label %96

36:                                               ; preds = %30
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.kh_e32_s, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !18
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = lshr i32 %40, 4
  %42 = zext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr %39, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = and i32 %45, 15
  %47 = shl i32 %46, 1
  %48 = lshr i32 %44, %47
  %49 = and i32 %48, 3
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %92, label %51

51:                                               ; preds = %36
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.kh_e32_s, ptr %53, i32 0, i32 5
  %55 = load ptr, ptr %54, align 8, !tbaa !19
  %56 = load i32, ptr %6, align 4, !tbaa !9
  %57 = zext i32 %56 to i64
  %58 = getelementptr inbounds i32, ptr %55, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = lshr i32 %59, 2
  %61 = call i32 @kh_get_g(ptr noundef %52, i32 noundef %60)
  store i32 %61, ptr %8, align 4, !tbaa !9
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.kh_g_s, ptr %62, i32 0, i32 6
  %64 = load ptr, ptr %63, align 8, !tbaa !13
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds %struct.vertex_t, ptr %64, i64 %66
  %68 = getelementptr inbounds %struct.vertex_t, ptr %67, i32 0, i32 1
  %69 = load ptr, ptr %68, align 8, !tbaa !14
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = shl i32 %70, 2
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.kh_e32_s, ptr %72, i32 0, i32 5
  %74 = load ptr, ptr %73, align 8, !tbaa !19
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = zext i32 %75 to i64
  %77 = getelementptr inbounds i32, ptr %74, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !9
  %79 = xor i32 %78, -1
  %80 = and i32 %79, 3
  %81 = or i32 %71, %80
  %82 = call i32 @kh_get_e32(ptr noundef %69, i32 noundef %81)
  store i32 %82, ptr %9, align 4, !tbaa !9
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.kh_g_s, ptr %83, i32 0, i32 6
  %85 = load ptr, ptr %84, align 8, !tbaa !13
  %86 = load i32, ptr %8, align 4, !tbaa !9
  %87 = zext i32 %86 to i64
  %88 = getelementptr inbounds %struct.vertex_t, ptr %85, i64 %87
  %89 = getelementptr inbounds %struct.vertex_t, ptr %88, i32 0, i32 1
  %90 = load ptr, ptr %89, align 8, !tbaa !14
  %91 = load i32, ptr %9, align 4, !tbaa !9
  call void @kh_del_e32(ptr noundef %90, i32 noundef %91)
  br label %92

92:                                               ; preds = %51, %36
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %6, align 4, !tbaa !9
  %95 = add i32 %94, 1
  store i32 %95, ptr %6, align 4, !tbaa !9
  br label %30, !llvm.loop !20

96:                                               ; preds = %30
  %97 = load ptr, ptr %10, align 8, !tbaa !5
  call void @kh_destroy_e32(ptr noundef %97)
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  %99 = load i32, ptr %7, align 4, !tbaa !9
  call void @kh_del_g(ptr noundef %98, i32 noundef %99)
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.kh_g_s, ptr %100, i32 0, i32 6
  %102 = load ptr, ptr %101, align 8, !tbaa !13
  %103 = load i32, ptr %7, align 4, !tbaa !9
  %104 = zext i32 %103 to i64
  %105 = getelementptr inbounds %struct.vertex_t, ptr %102, i64 %104
  store ptr %105, ptr %3, align 8
  store i32 1, ptr %11, align 4
  br label %106

106:                                              ; preds = %96, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %107 = load ptr, ptr %3, align 8
  ret ptr %107
}

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!12 = !{!"kh_g_s", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!13 = !{!12, !6, i64 32}
!14 = !{!15, !6, i64 8}
!15 = !{!"", !10, i64 0, !6, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"kh_e32_s", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16, !6, i64 24, !6, i64 32}
!18 = !{!17, !6, i64 16}
!19 = !{!17, !6, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"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"

%struct.vertex_t = type { i32, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @kh_destroy_e32(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @kh_del_e32(ptr noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @kh_del_g(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @kg_del_v_g(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call i32 @kh_get_g(ptr noundef %0, i32 noundef %1)
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = icmp eq i32 %3, %4
  br i1 %5, label %53, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 32
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = zext i32 %3 to i64
  %10 = getelementptr inbounds %struct.vertex_t, ptr %8, i64 %9, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %.not31 = icmp eq i32 %12, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6
  %13 = getelementptr inbounds i8, ptr %11, i64 16
  %14 = getelementptr inbounds i8, ptr %11, i64 24
  %15 = shl i32 %1, 2
  br label %16

16:                                               ; preds = %.lr.ph, %48
  %17 = phi i32 [ %12, %.lr.ph ], [ %49, %48 ]
  %.02832 = phi i32 [ 0, %.lr.ph ], [ %50, %48 ]
  %18 = load ptr, ptr %13, align 8, !tbaa !16
  %19 = lshr i32 %.02832, 4
  %20 = zext nneg i32 %19 to i64
  %21 = getelementptr inbounds i32, ptr %18, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !17
  %23 = shl i32 %.02832, 1
  %24 = and i32 %23, 30
  %25 = shl nuw i32 3, %24
  %26 = and i32 %22, %25
  %.not30 = icmp eq i32 %26, 0
  br i1 %.not30, label %27, label %48

27:                                               ; preds = %16
  %28 = load ptr, ptr %14, align 8, !tbaa !18
  %29 = zext i32 %.02832 to i64
  %30 = getelementptr inbounds i32, ptr %28, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !17
  %32 = lshr i32 %31, 2
  %33 = tail call i32 @kh_get_g(ptr noundef nonnull %0, i32 noundef %32)
  %34 = load ptr, ptr %7, align 8, !tbaa !11
  %35 = zext i32 %33 to i64
  %36 = getelementptr inbounds %struct.vertex_t, ptr %34, i64 %35, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !12
  %38 = load ptr, ptr %14, align 8, !tbaa !18
  %39 = getelementptr inbounds i32, ptr %38, i64 %29
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = and i32 %40, 3
  %42 = or disjoint i32 %41, %15
  %43 = xor i32 %42, 3
  %44 = tail call i32 @kh_get_e32(ptr noundef %37, i32 noundef %43)
  %45 = load ptr, ptr %7, align 8, !tbaa !11
  %46 = getelementptr inbounds %struct.vertex_t, ptr %45, i64 %35, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !12
  tail call void @kh_del_e32(ptr noundef %47, i32 noundef %44)
  %.pre = load i32, ptr %11, align 8, !tbaa !14
  br label %48

48:                                               ; preds = %16, %27
  %49 = phi i32 [ %17, %16 ], [ %.pre, %27 ]
  %50 = add i32 %.02832, 1
  %.not = icmp eq i32 %50, %49
  br i1 %.not, label %._crit_edge, label %16, !llvm.loop !19

._crit_edge:                                      ; preds = %48, %6
  tail call void @kh_destroy_e32(ptr noundef nonnull %11)
  tail call void @kh_del_g(ptr noundef nonnull %0, i32 noundef %3)
  %51 = load ptr, ptr %7, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.vertex_t, ptr %51, i64 %9
  br label %53

53:                                               ; preds = %2, %._crit_edge
  %.0 = phi ptr [ %52, %._crit_edge ], [ null, %2 ]
  ret ptr %.0
}

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 = !{!"kh_g_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 32}
!12 = !{!13, !10, i64 8}
!13 = !{!"", !7, i64 0, !10, i64 8}
!14 = !{!15, !7, i64 0}
!15 = !{!"kh_e32_s", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !10, i64 24, !10, i64 32}
!16 = !{!15, !10, i64 16}
!17 = !{!7, !7, i64 0}
!18 = !{!15, !10, i64 24}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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