; LLVM IR from pranjalwalia/Competitive-programming :: spoj/dquery.ll (Z7buildstiix)

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

@nodo = external dso_local global [1000000 x %struct.nodost], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @_Z5merge6nodostS_(i32, i32) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @_Z4hojai(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z7buildstiix(i32 noundef %0, i32 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca %struct.nodost, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.nodost, align 4
  %12 = alloca %struct.nodost, align 4
  %13 = alloca %struct.nodost, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = icmp eq i32 %14, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = call i32 @_Z4hojai(i32 noundef %18)
  %20 = getelementptr inbounds %struct.nodost, ptr %7, i32 0, i32 0
  store i32 %19, ptr %20, align 4
  %21 = load i64, ptr %6, align 8, !tbaa !9
  %22 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 4 %7, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %52

23:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load i64, ptr %6, align 8, !tbaa !9
  %25 = mul nsw i64 2, %24
  store i64 %25, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %26 = load i64, ptr %6, align 8, !tbaa !9
  %27 = mul nsw i64 2, %26
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = add nsw i32 %29, %30
  %32 = sdiv i32 %31, 2
  store i32 %32, ptr %10, align 4, !tbaa !5
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = load i64, ptr %8, align 8, !tbaa !9
  call void @_Z7buildstiix(i32 noundef %33, i32 noundef %34, i64 noundef %35)
  %36 = load i32, ptr %10, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  %38 = load i32, ptr %5, align 4, !tbaa !5
  %39 = load i64, ptr %9, align 8, !tbaa !9
  call void @_Z7buildstiix(i32 noundef %37, i32 noundef %38, i64 noundef %39)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %40
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 4 %41, i64 4, i1 false), !tbaa.struct !11
  %42 = load i64, ptr %9, align 8, !tbaa !9
  %43 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %42
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %43, i64 4, i1 false), !tbaa.struct !11
  %44 = getelementptr inbounds %struct.nodost, ptr %12, i32 0, i32 0
  %45 = load i32, ptr %44, align 4
  %46 = getelementptr inbounds %struct.nodost, ptr %13, i32 0, i32 0
  %47 = load i32, ptr %46, align 4
  %48 = call i32 @_Z5merge6nodostS_(i32 %45, i32 %47)
  %49 = getelementptr inbounds %struct.nodost, ptr %11, i32 0, i32 0
  store i32 %48, ptr %49, align 4
  %50 = load i64, ptr %6, align 8, !tbaa !9
  %51 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %50
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %51, ptr align 4 %11, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %52

52:                                               ; preds = %23, %17
  ret void
}

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

; 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) #3

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

attributes #0 = { mustprogress 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 = { 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{i64 0, i64 4, !5}


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

@nodo = external dso_local local_unnamed_addr global [1000000 x %struct.nodost], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @_Z5merge6nodostS_(i32, i32) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @_Z4hojai(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7buildstiix(i32 noundef %0, i32 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq i32 %0, %1
  br i1 %4, label %5, label %8

5:                                                ; preds = %3
  %6 = tail call i32 @_Z4hojai(i32 noundef %0)
  br label %common.ret

common.ret:                                       ; preds = %5, %8
  %.sink = phi i32 [ %6, %5 ], [ %16, %8 ]
  %7 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %2
  store i32 %.sink, ptr %7, align 4
  ret void

8:                                                ; preds = %3
  %9 = shl nsw i64 %2, 1
  %10 = or disjoint i64 %9, 1
  %11 = add nsw i32 %1, %0
  %12 = sdiv i32 %11, 2
  tail call void @_Z7buildstiix(i32 noundef %0, i32 noundef %12, i64 noundef %9)
  %13 = add nsw i32 %12, 1
  tail call void @_Z7buildstiix(i32 noundef %13, i32 noundef %1, i64 noundef %10)
  %14 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %9
  %.sroa.01.0.copyload = load i32, ptr %14, align 8, !tbaa !5
  %15 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %10
  %.sroa.0.0.copyload = load i32, ptr %15, align 4, !tbaa !5
  %16 = tail call i32 @_Z5merge6nodostS_(i32 %.sroa.01.0.copyload, i32 %.sroa.0.0.copyload)
  br label %common.ret
}

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass