; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/QTREE3/qtree3.ll (Z8query_upii)

; 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.point = type { i32, i32 }

@BLACK = external dso_local global i32, align 4
@chain_ind = external dso_local global [101000 x i32], align 16
@chain_head = external dso_local global [101000 x i32], align 16
@pos_in_base = external dso_local global [101000 x i32], align 16
@color = external dso_local global [101000 x i32], align 16
@reverse_map = external dso_local global [101000 x i32], align 16
@ptr = external dso_local global i32, align 4
@pa = external dso_local global [101000 x i32], align 16

; 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: mustprogress uwtable
declare dso_local i64 @_Z10query_treeiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8query_upii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.point, align 4
  %10 = alloca %struct.point, align 4
  %11 = alloca %struct.point, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [101000 x i32], ptr @color, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = load i32, ptr @BLACK, align 4, !tbaa !5
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  br label %107

20:                                               ; preds = %2
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  store i32 -1, ptr %3, align 4
  br label %107

25:                                               ; preds = %20
  br label %26

26:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [101000 x i32], ptr @chain_ind, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 -1, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  br label %31

31:                                               ; preds = %88, %26
  br label %32

32:                                               ; preds = %31
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [101000 x i32], ptr @chain_ind, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %6, align 4, !tbaa !5
  %37 = load i32, ptr %6, align 4, !tbaa !5
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = icmp eq i32 %37, %38
  br i1 %39, label %40, label %66

40:                                               ; preds = %32
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = icmp eq i32 %41, %42
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  br label %96

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %46 = load i32, ptr @ptr, align 4, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = add nsw i32 %50, 1
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = add nsw i32 %55, 1
  %57 = call i64 @_Z10query_treeiiiii(i32 noundef 1, i32 noundef 0, i32 noundef %46, i32 noundef %51, i32 noundef %56)
  store i64 %57, ptr %10, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %10, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  %58 = getelementptr inbounds %struct.point, ptr %9, i32 0, i32 0
  %59 = load i32, ptr %58, align 4, !tbaa !10
  %60 = load i32, ptr @BLACK, align 4, !tbaa !5
  %61 = icmp eq i32 %59, %60
  br i1 %61, label %62, label %65

62:                                               ; preds = %45
  %63 = getelementptr inbounds %struct.point, ptr %9, i32 0, i32 1
  %64 = load i32, ptr %63, align 4, !tbaa !12
  store i32 %64, ptr %8, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %62, %45
  br label %96

66:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %67 = load i32, ptr @ptr, align 4, !tbaa !5
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [101000 x i32], ptr @chain_head, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = add nsw i32 %78, 1
  %80 = call i64 @_Z10query_treeiiiii(i32 noundef 1, i32 noundef 0, i32 noundef %67, i32 noundef %74, i32 noundef %79)
  store i64 %80, ptr %11, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %11, i64 8, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %81 = getelementptr inbounds %struct.point, ptr %9, i32 0, i32 0
  %82 = load i32, ptr %81, align 4, !tbaa !10
  %83 = load i32, ptr @BLACK, align 4, !tbaa !5
  %84 = icmp eq i32 %82, %83
  br i1 %84, label %85, label %88

85:                                               ; preds = %66
  %86 = getelementptr inbounds %struct.point, ptr %9, i32 0, i32 1
  %87 = load i32, ptr %86, align 4, !tbaa !12
  store i32 %87, ptr %8, align 4, !tbaa !5
  br label %88

88:                                               ; preds = %85, %66
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [101000 x i32], ptr @chain_head, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [101000 x i32], ptr @pa, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  store i32 %95, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !13

96:                                               ; preds = %65, %44
  %97 = load i32, ptr %8, align 4, !tbaa !5
  %98 = icmp eq i32 %97, -1
  br i1 %98, label %99, label %100

99:                                               ; preds = %96
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %106

100:                                              ; preds = %96
  %101 = load i32, ptr %8, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [101000 x i32], ptr @reverse_map, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = add nsw i32 %104, 1
  store i32 %105, ptr %3, align 4
  store i32 1, ptr %12, align 4
  br label %106

106:                                              ; preds = %100, %99
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %107

107:                                              ; preds = %106, %24, %19
  %108 = load i32, ptr %3, align 4
  ret i32 %108
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 4, !5, i64 4, i64 4, !5}
!10 = !{!11, !6, i64 0}
!11 = !{!"_ZTS5point", !6, i64 0, !6, i64 4}
!12 = !{!11, !6, i64 4}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@BLACK = external dso_local local_unnamed_addr global i32, align 4
@chain_ind = external dso_local local_unnamed_addr global [101000 x i32], align 16
@chain_head = external dso_local local_unnamed_addr global [101000 x i32], align 16
@pos_in_base = external dso_local local_unnamed_addr global [101000 x i32], align 16
@color = external dso_local local_unnamed_addr global [101000 x i32], align 16
@reverse_map = external dso_local local_unnamed_addr global [101000 x i32], align 16
@ptr = external dso_local local_unnamed_addr global i32, align 4
@pa = external dso_local local_unnamed_addr global [101000 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z10query_treeiiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z8query_upii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %1 to i64
  %4 = getelementptr inbounds [101000 x i32], ptr @color, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = load i32, ptr @BLACK, align 4, !tbaa !5
  %7 = icmp eq i32 %5, %6
  br i1 %7, label %60, label %8

8:                                                ; preds = %2
  %9 = icmp eq i32 %0, %1
  br i1 %9, label %60, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds [101000 x i32], ptr @chain_ind, i64 0, i64 %3
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [101000 x i32], ptr @chain_ind, i64 0, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = icmp eq i32 %15, %12
  br i1 %16, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %10
  %.025.lcssa = phi i32 [ -1, %10 ], [ %.126, %.lr.ph ]
  %.024.lcssa = phi i32 [ %0, %10 ], [ %48, %.lr.ph ]
  %.lcssa = phi i64 [ %13, %10 ], [ %49, %.lr.ph ]
  %17 = icmp eq i32 %.024.lcssa, %1
  br i1 %17, label %53, label %18

18:                                               ; preds = %._crit_edge
  %19 = load i32, ptr @ptr, align 4, !tbaa !5
  %20 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %3
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  %23 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %.lcssa
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  %26 = tail call i64 @_Z10query_treeiiiii(i32 noundef 1, i32 noundef 0, i32 noundef %19, i32 noundef %22, i32 noundef %25)
  %.sroa.02.0.extract.trunc4 = trunc i64 %26 to i32
  %27 = load i32, ptr @BLACK, align 4, !tbaa !5
  %28 = icmp eq i32 %27, %.sroa.02.0.extract.trunc4
  br i1 %28, label %29, label %53

29:                                               ; preds = %18
  %.sroa.6.0.extract.shift5 = lshr i64 %26, 32
  %.sroa.6.0.extract.trunc6 = trunc nuw i64 %.sroa.6.0.extract.shift5 to i32
  br label %53

.lr.ph:                                           ; preds = %10, %.lr.ph
  %30 = phi i32 [ %51, %.lr.ph ], [ %15, %10 ]
  %31 = phi i64 [ %49, %.lr.ph ], [ %13, %10 ]
  %.02530 = phi i32 [ %.126, %.lr.ph ], [ -1, %10 ]
  %32 = load i32, ptr @ptr, align 4, !tbaa !5
  %33 = sext i32 %30 to i64
  %34 = getelementptr inbounds [101000 x i32], ptr @chain_head, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = getelementptr inbounds [101000 x i32], ptr @pos_in_base, i64 0, i64 %31
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  %42 = tail call i64 @_Z10query_treeiiiii(i32 noundef 1, i32 noundef 0, i32 noundef %32, i32 noundef %38, i32 noundef %41)
  %.sroa.02.0.extract.trunc = trunc i64 %42 to i32
  %43 = load i32, ptr @BLACK, align 4, !tbaa !5
  %44 = icmp eq i32 %43, %.sroa.02.0.extract.trunc
  %.sroa.6.0.extract.shift = lshr i64 %42, 32
  %.sroa.6.0.extract.trunc = trunc nuw i64 %.sroa.6.0.extract.shift to i32
  %.126 = select i1 %44, i32 %.sroa.6.0.extract.trunc, i32 %.02530
  %45 = load i32, ptr %34, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [101000 x i32], ptr @pa, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [101000 x i32], ptr @chain_ind, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = icmp eq i32 %51, %12
  br i1 %52, label %._crit_edge, label %.lr.ph, !llvm.loop !9

53:                                               ; preds = %18, %29, %._crit_edge
  %.2 = phi i32 [ %.025.lcssa, %._crit_edge ], [ %.sroa.6.0.extract.trunc6, %29 ], [ %.025.lcssa, %18 ]
  %54 = icmp eq i32 %.2, -1
  br i1 %54, label %60, label %55

55:                                               ; preds = %53
  %56 = sext i32 %.2 to i64
  %57 = getelementptr inbounds [101000 x i32], ptr @reverse_map, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  br label %60

60:                                               ; preds = %55, %53, %8, %2
  %.1 = phi i32 [ 1, %2 ], [ -1, %8 ], [ %59, %55 ], [ -1, %53 ]
  ret i32 %.1
}

attributes #0 = { mustprogress 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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