; LLVM IR from attractivechaos/klib :: test (krmq_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.my_node = type { i32, i32, %struct.anon }
%struct.anon = type { [2 x ptr], ptr, i8, i32 }
%struct.krmq_itr_my = type { [64 x ptr], ptr }

@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [71 x i8], align 1
@__PRETTY_FUNCTION__.check_rmq = external hidden unnamed_addr constant [48 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1

; 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 dso_local ptr @krmq_interval_my(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @krmq_rmq_my(ptr noundef, ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @check_rmq(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.my_node, align 8
  %9 = alloca %struct.my_node, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca %struct.krmq_itr_my, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 520, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 2147483647, ptr %13, align 4, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.my_node, ptr %8, i32 0, i32 0
  store i32 %16, ptr %17, align 8, !tbaa !11
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = getelementptr inbounds %struct.my_node, ptr %9, i32 0, i32 0
  store i32 %18, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call ptr @krmq_rmq_my(ptr noundef %20, ptr noundef %8, ptr noundef %9)
  store ptr %21, ptr %10, align 8, !tbaa !5
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call ptr @krmq_interval_my(ptr noundef %22, ptr noundef %8, ptr noundef null, ptr noundef %11)
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %27

26:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %96

27:                                               ; preds = %3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = call i32 @krmq_itr_find_my(ptr noundef %28, ptr noundef %29, ptr noundef %12)
  br label %31

31:                                               ; preds = %64, %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  %32 = getelementptr inbounds %struct.krmq_itr_my, ptr %12, i32 0, i32 1
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = getelementptr inbounds %struct.krmq_itr_my, ptr %12, i32 0, i32 0
  %35 = getelementptr inbounds [64 x ptr], ptr %34, i64 0, i64 0
  %36 = icmp ult ptr %33, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %42

38:                                               ; preds = %31
  %39 = getelementptr inbounds %struct.krmq_itr_my, ptr %12, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %38, %37
  %43 = phi ptr [ null, %37 ], [ %41, %38 ]
  store ptr %43, ptr %15, align 8, !tbaa !5
  %44 = load ptr, ptr %15, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.my_node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 8, !tbaa !11
  %47 = load i32, ptr %7, align 4, !tbaa !9
  %48 = icmp sgt i32 %46, %47
  br i1 %48, label %49, label %50

49:                                               ; preds = %42
  store i32 2, ptr %14, align 4
  br label %61

50:                                               ; preds = %42
  %51 = load ptr, ptr %15, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.my_node, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !16
  %54 = load i32, ptr %13, align 4, !tbaa !9
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %60

56:                                               ; preds = %50
  %57 = load ptr, ptr %15, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.my_node, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %58, align 4, !tbaa !16
  store i32 %59, ptr %13, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %56, %50
  store i32 0, ptr %14, align 4
  br label %61

61:                                               ; preds = %60, %49
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  %62 = load i32, ptr %14, align 4
  switch i32 %62, label %98 [
    i32 0, label %63
    i32 2, label %67
  ]

63:                                               ; preds = %61
  br label %64

64:                                               ; preds = %63
  %65 = call i32 @krmq_itr_next_bidir_my(ptr noundef %12, i32 noundef 1)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %31, label %67, !llvm.loop !17

67:                                               ; preds = %64, %61
  %68 = load i32, ptr %13, align 4, !tbaa !9
  %69 = icmp eq i32 %68, 2147483647
  br i1 %69, label %70, label %73

70:                                               ; preds = %67
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = icmp eq ptr %71, null
  br i1 %72, label %79, label %73

73:                                               ; preds = %70, %67
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = icmp slt i32 %74, 2147483647
  br i1 %75, label %76, label %80

76:                                               ; preds = %73
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = icmp ne ptr %77, null
  br i1 %78, label %79, label %80

79:                                               ; preds = %76, %70
  br label %81

80:                                               ; preds = %76, %73
  call void @__assert_fail(ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 58, ptr noundef @__PRETTY_FUNCTION__.check_rmq) #5
  unreachable

81:                                               ; preds = %79
  %82 = load i32, ptr %13, align 4, !tbaa !9
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.my_node, ptr %83, i32 0, i32 1
  %85 = load i32, ptr %84, align 4, !tbaa !16
  %86 = icmp ne i32 %82, %85
  br i1 %86, label %87, label %94

87:                                               ; preds = %81
  %88 = load ptr, ptr @stderr, align 8, !tbaa !5
  %89 = load ptr, ptr %10, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.my_node, ptr %89, i32 0, i32 1
  %91 = load i32, ptr %90, align 4, !tbaa !16
  %92 = load i32, ptr %13, align 4, !tbaa !9
  %93 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %88, ptr noundef @.str.5, i32 noundef %91, i32 noundef %92) #4
  br label %94

94:                                               ; preds = %87, %81
  %95 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %95, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %96

96:                                               ; preds = %94, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 520, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 40, ptr %8) #4
  %97 = load i32, ptr %4, align 4
  ret i32 %97

98:                                               ; preds = %61
  unreachable
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

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 "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 = { noreturn nounwind "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 }
attributes #5 = { noreturn 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 = !{!"my_node", !10, i64 0, !10, i64 4, !13, i64 8}
!13 = !{!"", !7, i64 0, !6, i64 16, !7, i64 24, !10, i64 28}
!14 = !{!15, !6, i64 512}
!15 = !{!"krmq_itr_my", !7, i64 0, !6, i64 512}
!16 = !{!12, !10, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"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.my_node = type { i32, i32, %struct.anon }
%struct.anon = type { [2 x ptr], ptr, i8, i32 }
%struct.krmq_itr_my = type { [64 x ptr], ptr }

@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [51 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [71 x i8], align 1
@__PRETTY_FUNCTION__.check_rmq = external hidden unnamed_addr constant [48 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [18 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @krmq_interval_my(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @krmq_rmq_my(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @check_rmq(ptr noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca %struct.my_node, align 8
  %5 = alloca %struct.my_node, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %struct.krmq_itr_my, align 8
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 520, ptr nonnull %7) #5
  store i32 %1, ptr %4, align 8, !tbaa !5
  store i32 %2, ptr %5, align 8, !tbaa !5
  %8 = call ptr @krmq_rmq_my(ptr noundef %0, ptr noundef nonnull %4, ptr noundef nonnull %5)
  %9 = call ptr @krmq_interval_my(ptr noundef %0, ptr noundef nonnull %4, ptr noundef null, ptr noundef nonnull %6)
  %10 = icmp eq ptr %8, null
  br i1 %10, label %36, label %11

11:                                               ; preds = %3
  %12 = load ptr, ptr %6, align 8, !tbaa !12
  %13 = call i32 @krmq_itr_find_my(ptr noundef %0, ptr noundef %12, ptr noundef nonnull %7)
  %14 = getelementptr inbounds i8, ptr %7, i64 512
  br label %15

15:                                               ; preds = %24, %11
  %.025 = phi i32 [ 2147483647, %11 ], [ %spec.select, %24 ]
  %16 = load ptr, ptr %14, align 8, !tbaa !13
  %17 = icmp ult ptr %16, %7
  br i1 %17, label %20, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %16, align 8, !tbaa !12
  br label %20

20:                                               ; preds = %15, %18
  %21 = phi ptr [ %19, %18 ], [ null, %15 ]
  %22 = load i32, ptr %21, align 8, !tbaa !5
  %23 = icmp sgt i32 %22, %2
  br i1 %23, label %28, label %24

24:                                               ; preds = %20
  %25 = getelementptr inbounds i8, ptr %21, i64 4
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %spec.select = call i32 @llvm.smin.i32(i32 %26, i32 %.025)
  %27 = call i32 @krmq_itr_next_bidir_my(ptr noundef nonnull %7, i32 noundef 1)
  %.not = icmp eq i32 %27, 0
  br i1 %.not, label %28, label %15, !llvm.loop !16

28:                                               ; preds = %20, %24
  %.235 = phi i32 [ %spec.select, %24 ], [ %.025, %20 ]
  %.not30 = icmp eq i32 %.235, 2147483647
  br i1 %.not30, label %29, label %30

29:                                               ; preds = %28
  call void @__assert_fail(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 58, ptr noundef nonnull @__PRETTY_FUNCTION__.check_rmq) #6
  unreachable

30:                                               ; preds = %28
  %31 = getelementptr inbounds i8, ptr %8, i64 4
  %32 = load i32, ptr %31, align 4, !tbaa !15
  %.not31 = icmp eq i32 %.235, %32
  br i1 %.not31, label %36, label %33

33:                                               ; preds = %30
  %34 = load ptr, ptr @stderr, align 8, !tbaa !12
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.5, i32 noundef %32, i32 noundef %.235) #7
  br label %36

36:                                               ; preds = %30, %33, %3
  %.0 = phi i32 [ -1, %3 ], [ %.235, %33 ], [ %.235, %30 ]
  call void @llvm.lifetime.end.p0(i64 520, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %4) #5
  ret i32 %.0
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

attributes #0 = { mustprogress 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 = { nofree nounwind "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 = { noreturn nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nounwind }
attributes #6 = { noreturn nounwind }
attributes #7 = { cold 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, !7, i64 0}
!6 = !{!"my_node", !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 = !{!"", !8, i64 0, !11, i64 16, !8, i64 24, !7, i64 28}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!14, !11, i64 512}
!14 = !{!"krmq_itr_my", !8, i64 0, !11, i64 512}
!15 = !{!6, !7, i64 4}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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