; LLVM IR from viveakrt/Competitive-programing :: SPOJ/dquery.ll (Z6updateiiiii)

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

@tree = external dso_local global [1000001 x %struct.node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5clonei(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: mustprogress uwtable
define dso_local noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = call noundef i32 @_Z5clonei(i32 noundef %15)
  store i32 %16, ptr %12, align 4, !tbaa !5
  %17 = load i32, ptr %11, align 4, !tbaa !5
  %18 = load i32, ptr %12, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = add nsw i32 %22, %17
  store i32 %23, ptr %21, align 4, !tbaa !9
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %5
  %28 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %28, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %70

29:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %30 = load i32, ptr %7, align 4, !tbaa !5
  %31 = load i32, ptr %8, align 4, !tbaa !5
  %32 = add nsw i32 %30, %31
  %33 = sdiv i32 %32, 2
  store i32 %33, ptr %14, align 4, !tbaa !5
  %34 = load i32, ptr %10, align 4, !tbaa !5
  %35 = load i32, ptr %14, align 4, !tbaa !5
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %52

37:                                               ; preds = %29
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !5
  %40 = load i32, ptr %9, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.node, ptr %42, i32 0, i32 0
  %44 = load i32, ptr %43, align 4, !tbaa !11
  %45 = load i32, ptr %10, align 4, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !5
  %47 = call noundef i32 @_Z6updateiiiii(i32 noundef %38, i32 noundef %39, i32 noundef %44, i32 noundef %45, i32 noundef %46)
  %48 = load i32, ptr %12, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.node, ptr %50, i32 0, i32 0
  store i32 %47, ptr %51, align 4, !tbaa !11
  br label %68

52:                                               ; preds = %29
  %53 = load i32, ptr %14, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %9, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !5
  %63 = call noundef i32 @_Z6updateiiiii(i32 noundef %54, i32 noundef %55, i32 noundef %60, i32 noundef %61, i32 noundef %62)
  %64 = load i32, ptr %12, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.node, ptr %66, i32 0, i32 1
  store i32 %63, ptr %67, align 4, !tbaa !12
  br label %68

68:                                               ; preds = %52, %37
  %69 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %69, ptr %6, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %70

70:                                               ; preds = %68, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %71 = load i32, ptr %6, align 4
  ret i32 %71
}

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 = { 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 #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 = !{!10, !6, i64 8}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 4, !6, i64 8}
!11 = !{!10, !6, i64 0}
!12 = !{!10, !6, i64 4}


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

@tree = external dso_local local_unnamed_addr global [1000001 x %struct.node], align 16

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = tail call noundef i32 @_Z5clonei(i32 noundef %2)
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add nsw i32 %10, %4
  store i32 %11, ptr %9, align 4, !tbaa !5
  %12 = icmp eq i32 %0, %1
  br i1 %12, label %common.ret28, label %13

13:                                               ; preds = %5
  %14 = add nsw i32 %1, %0
  %15 = sdiv i32 %14, 2
  %.not = icmp slt i32 %15, %3
  br i1 %.not, label %21, label %16

common.ret28:                                     ; preds = %5, %21, %16
  %common.ret28.op = phi i32 [ %6, %16 ], [ %6, %21 ], [ %6, %5 ]
  ret i32 %common.ret28.op

16:                                               ; preds = %13
  %17 = sext i32 %2 to i64
  %18 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = tail call noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %15, i32 noundef %19, i32 noundef %3, i32 noundef %4)
  store i32 %20, ptr %8, align 4, !tbaa !10
  br label %common.ret28

21:                                               ; preds = %13
  %22 = add nsw i32 %15, 1
  %23 = sext i32 %2 to i64
  %24 = getelementptr inbounds [1000001 x %struct.node], ptr @tree, i64 0, i64 %23, i32 1
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = tail call noundef i32 @_Z6updateiiiii(i32 noundef %22, i32 noundef %1, i32 noundef %25, i32 noundef %3, i32 noundef %4)
  %27 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 %26, ptr %27, align 4, !tbaa !11
  br label %common.ret28
}

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, !7, i64 8}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 0}
!11 = !{!6, !7, i64 4}


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