; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LTIME/LTIME28/Problem A/A.ll (Z6updateiiixiii)

; 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 { i64 }

@tree = external dso_local global [5001 x [10002 x %struct.node]], 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: mustprogress uwtable
declare dso_local void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; 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 void @_Z3updiiiix(i32 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5shiftiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

21:                                               ; preds = %7
  %22 = load i32, ptr %13, align 4, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !5
  %24 = icmp sge i32 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %7
  br label %85

26:                                               ; preds = %21
  %27 = load i32, ptr %9, align 4, !tbaa !5
  %28 = load i32, ptr %13, align 4, !tbaa !5
  %29 = icmp sle i32 %27, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %26
  %31 = load i32, ptr %14, align 4, !tbaa !5
  %32 = load i32, ptr %10, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %40

34:                                               ; preds = %30
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = load i32, ptr %13, align 4, !tbaa !5
  %38 = load i32, ptr %14, align 4, !tbaa !5
  %39 = load i64, ptr %11, align 8, !tbaa !9
  call void @_Z3updiiiix(i32 noundef %35, i32 noundef %36, i32 noundef %37, i32 noundef %38, i64 noundef %39)
  br label %85

40:                                               ; preds = %30, %26
  %41 = load i32, ptr %8, align 4, !tbaa !5
  %42 = load i32, ptr %12, align 4, !tbaa !5
  %43 = load i32, ptr %13, align 4, !tbaa !5
  %44 = load i32, ptr %14, align 4, !tbaa !5
  call void @_Z5shiftiiii(i32 noundef %41, i32 noundef %42, i32 noundef %43, i32 noundef %44)
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #2
  %45 = load i32, ptr %12, align 4, !tbaa !5
  %46 = shl i32 %45, 1
  store i32 %46, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #2
  %47 = load i32, ptr %15, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #2
  %49 = load i32, ptr %13, align 4, !tbaa !5
  %50 = load i32, ptr %14, align 4, !tbaa !5
  %51 = add nsw i32 %49, %50
  %52 = ashr i32 %51, 1
  store i32 %52, ptr %17, align 4, !tbaa !5
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = load i64, ptr %11, align 8, !tbaa !9
  %57 = load i32, ptr %15, align 4, !tbaa !5
  %58 = load i32, ptr %13, align 4, !tbaa !5
  %59 = load i32, ptr %17, align 4, !tbaa !5
  call void @_Z6updateiiixiii(i32 noundef %53, i32 noundef %54, i32 noundef %55, i64 noundef %56, i32 noundef %57, i32 noundef %58, i32 noundef %59)
  %60 = load i32, ptr %8, align 4, !tbaa !5
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = load i32, ptr %10, align 4, !tbaa !5
  %63 = load i64, ptr %11, align 8, !tbaa !9
  %64 = load i32, ptr %16, align 4, !tbaa !5
  %65 = load i32, ptr %17, align 4, !tbaa !5
  %66 = load i32, ptr %14, align 4, !tbaa !5
  call void @_Z6updateiiixiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i64 noundef %63, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [5001 x [10002 x %struct.node]], ptr @tree, i64 0, i64 %68
  %70 = load i32, ptr %12, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [10002 x %struct.node], ptr %69, i64 0, i64 %71
  %73 = load i32, ptr %8, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [5001 x [10002 x %struct.node]], ptr @tree, i64 0, i64 %74
  %76 = load i32, ptr %15, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [10002 x %struct.node], ptr %75, i64 0, i64 %77
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [5001 x [10002 x %struct.node]], ptr @tree, i64 0, i64 %80
  %82 = load i32, ptr %16, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [10002 x %struct.node], ptr %81, i64 0, i64 %83
  call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(8) %72, ptr noundef nonnull align 8 dereferenceable(8) %78, ptr noundef nonnull align 8 dereferenceable(8) %84)
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #2
  br label %85

85:                                               ; preds = %40, %34, %25
  ret void
}

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 = { 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}


; 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 { i64 }

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateiiixiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #0 {
  %.not = icmp slt i32 %1, %6
  %.not44 = icmp slt i32 %5, %2
  %or.cond = and i1 %.not44, %.not
  br i1 %or.cond, label %8, label %common.ret48

8:                                                ; preds = %7
  %.not45 = icmp sgt i32 %1, %5
  %.not46 = icmp sgt i32 %6, %2
  %or.cond47 = or i1 %.not45, %.not46
  br i1 %or.cond47, label %10, label %9

9:                                                ; preds = %8
  tail call void @_Z3updiiiix(i32 noundef %0, i32 noundef %4, i32 noundef %5, i32 noundef %6, i64 noundef %3)
  br label %common.ret48

common.ret48:                                     ; preds = %7, %9, %10
  ret void

10:                                               ; preds = %8
  tail call void @_Z5shiftiiii(i32 noundef %0, i32 noundef %4, i32 noundef %5, i32 noundef %6)
  %11 = shl i32 %4, 1
  %12 = or disjoint i32 %11, 1
  %13 = add nsw i32 %6, %5
  %14 = ashr i32 %13, 1
  tail call void @_Z6updateiiixiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %11, i32 noundef %5, i32 noundef %14)
  tail call void @_Z6updateiiixiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i64 noundef %3, i32 noundef %12, i32 noundef %14, i32 noundef %6)
  %15 = sext i32 %0 to i64
  %16 = sext i32 %4 to i64
  %17 = getelementptr inbounds [5001 x [10002 x %struct.node]], ptr @tree, i64 0, i64 %15, i64 %16
  %18 = sext i32 %11 to i64
  %19 = getelementptr inbounds [5001 x [10002 x %struct.node]], ptr @tree, i64 0, i64 %15, i64 %18
  %20 = sext i32 %12 to i64
  %21 = getelementptr inbounds [5001 x [10002 x %struct.node]], ptr @tree, i64 0, i64 %15, i64 %20
  tail call void @_ZN4node7combineERS_S0_(ptr noundef nonnull align 8 dereferenceable(8) %17, ptr noundef nonnull align 8 dereferenceable(8) %19, ptr noundef nonnull align 8 dereferenceable(8) %21)
  br label %common.ret48
}

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)"}


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