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

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

19:                                               ; preds = %4
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = icmp eq i32 %20, %21
  br i1 %22, label %23, label %29

23:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = call i32 @_Z4hojai(i32 noundef %24)
  %26 = getelementptr inbounds %struct.nodost, ptr %9, i32 0, i32 0
  store i32 %25, ptr %26, align 4
  %27 = load i64, ptr %8, align 8, !tbaa !9
  %28 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %27
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %28, ptr align 4 %9, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %66

29:                                               ; preds = %19, %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = mul nsw i64 2, %30
  store i64 %31, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %32 = load i64, ptr %8, align 8, !tbaa !9
  %33 = mul nsw i64 2, %32
  %34 = add nsw i64 %33, 1
  store i64 %34, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = add nsw i32 %35, %36
  %38 = sdiv i32 %37, 2
  store i32 %38, ptr %12, align 4, !tbaa !5
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %42, label %47

42:                                               ; preds = %29
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %12, align 4, !tbaa !5
  %46 = load i64, ptr %10, align 8, !tbaa !9
  call void @_Z6updateiiix(i32 noundef %43, i32 noundef %44, i32 noundef %45, i64 noundef %46)
  br label %53

47:                                               ; preds = %29
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i64, ptr %11, align 8, !tbaa !9
  call void @_Z6updateiiix(i32 noundef %48, i32 noundef %50, i32 noundef %51, i64 noundef %52)
  br label %53

53:                                               ; preds = %47, %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %54 = load i64, ptr %10, align 8, !tbaa !9
  %55 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %54
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %55, i64 4, i1 false), !tbaa.struct !11
  %56 = load i64, ptr %11, align 8, !tbaa !9
  %57 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %56
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %15, ptr align 4 %57, i64 4, i1 false), !tbaa.struct !11
  %58 = getelementptr inbounds %struct.nodost, ptr %14, i32 0, i32 0
  %59 = load i32, ptr %58, align 4
  %60 = getelementptr inbounds %struct.nodost, ptr %15, i32 0, i32 0
  %61 = load i32, ptr %60, align 4
  %62 = call i32 @_Z5merge6nodostS_(i32 %59, i32 %61)
  %63 = getelementptr inbounds %struct.nodost, ptr %13, i32 0, i32 0
  store i32 %62, ptr %63, align 4
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %65, ptr align 4 %13, i64 4, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, 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
  br label %66

66:                                               ; preds = %53, %23
  ret void
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 @_Z6updateiiix(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %1, %0
  %6 = icmp eq i32 %2, %0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %9

7:                                                ; preds = %4
  %8 = tail call i32 @_Z4hojai(i32 noundef %1)
  br label %21

9:                                                ; preds = %4
  %10 = shl nsw i64 %3, 1
  %11 = or disjoint i64 %10, 1
  %12 = add nsw i32 %2, %1
  %13 = sdiv i32 %12, 2
  %.not = icmp slt i32 %13, %0
  br i1 %.not, label %15, label %14

14:                                               ; preds = %9
  tail call void @_Z6updateiiix(i32 noundef %0, i32 noundef %1, i32 noundef %13, i64 noundef %10)
  br label %17

15:                                               ; preds = %9
  %16 = add nsw i32 %13, 1
  tail call void @_Z6updateiiix(i32 noundef %0, i32 noundef %16, i32 noundef %2, i64 noundef %11)
  br label %17

17:                                               ; preds = %15, %14
  %18 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %10
  %.sroa.01.0.copyload = load i32, ptr %18, align 8, !tbaa !5
  %19 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %11
  %.sroa.0.0.copyload = load i32, ptr %19, align 4, !tbaa !5
  %20 = tail call i32 @_Z5merge6nodostS_(i32 %.sroa.01.0.copyload, i32 %.sroa.0.0.copyload)
  br label %21

21:                                               ; preds = %17, %7
  %.sink = phi i32 [ %20, %17 ], [ %8, %7 ]
  %22 = getelementptr inbounds [1000000 x %struct.nodost], ptr @nodo, i64 0, i64 %3
  store i32 %.sink, ptr %22, align 4, !tbaa !5
  ret void
}

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,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass