; LLVM IR from viveakrt/Competitive-programing :: SPOJ/salman.ll (Z6updatexxxxxx)

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

@tree = external dso_local global [1048576 x %struct.node], align 16
@lazy = external dso_local global [1048576 x i64], 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 nounwind uwtable
declare dso_local void @_Z6pushlzxxx(i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZplRK4nodeS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) #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: mustprogress uwtable
define dso_local void @_Z6updatexxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) #2 {
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  %14 = alloca %struct.node, align 8
  store i64 %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !5
  store i64 %5, ptr %12, align 8, !tbaa !5
  %15 = load i64, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %8, align 8, !tbaa !5
  %17 = load i64, ptr %9, align 8, !tbaa !5
  call void @_Z6pushlzxxx(i64 noundef %15, i64 noundef %16, i64 noundef %17)
  %18 = load i64, ptr %10, align 8, !tbaa !5
  %19 = load i64, ptr %8, align 8, !tbaa !5
  %20 = icmp sgt i64 %18, %19
  br i1 %20, label %25, label %21

21:                                               ; preds = %6
  %22 = load i64, ptr %11, align 8, !tbaa !5
  %23 = load i64, ptr %7, align 8, !tbaa !5
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %25, label %26

25:                                               ; preds = %21, %6
  br label %78

26:                                               ; preds = %21
  %27 = load i64, ptr %10, align 8, !tbaa !5
  %28 = load i64, ptr %7, align 8, !tbaa !5
  %29 = icmp sle i64 %27, %28
  br i1 %29, label %30, label %43

30:                                               ; preds = %26
  %31 = load i64, ptr %11, align 8, !tbaa !5
  %32 = load i64, ptr %8, align 8, !tbaa !5
  %33 = icmp sge i64 %31, %32
  br i1 %33, label %34, label %43

34:                                               ; preds = %30
  %35 = load i64, ptr %12, align 8, !tbaa !5
  %36 = load i64, ptr %9, align 8, !tbaa !5
  %37 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %38, %35
  store i64 %39, ptr %37, align 8, !tbaa !5
  %40 = load i64, ptr %7, align 8, !tbaa !5
  %41 = load i64, ptr %8, align 8, !tbaa !5
  %42 = load i64, ptr %9, align 8, !tbaa !5
  call void @_Z6pushlzxxx(i64 noundef %40, i64 noundef %41, i64 noundef %42)
  br label %78

43:                                               ; preds = %30, %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %44 = load i64, ptr %7, align 8, !tbaa !5
  %45 = load i64, ptr %8, align 8, !tbaa !5
  %46 = add nsw i64 %44, %45
  %47 = sdiv i64 %46, 2
  store i64 %47, ptr %13, align 8, !tbaa !5
  %48 = load i64, ptr %7, align 8, !tbaa !5
  %49 = load i64, ptr %13, align 8, !tbaa !5
  %50 = load i64, ptr %9, align 8, !tbaa !5
  %51 = mul nsw i64 %50, 2
  %52 = load i64, ptr %10, align 8, !tbaa !5
  %53 = load i64, ptr %11, align 8, !tbaa !5
  %54 = load i64, ptr %12, align 8, !tbaa !5
  call void @_Z6updatexxxxxx(i64 noundef %48, i64 noundef %49, i64 noundef %51, i64 noundef %52, i64 noundef %53, i64 noundef %54)
  %55 = load i64, ptr %13, align 8, !tbaa !5
  %56 = add nsw i64 %55, 1
  %57 = load i64, ptr %8, align 8, !tbaa !5
  %58 = load i64, ptr %9, align 8, !tbaa !5
  %59 = mul nsw i64 %58, 2
  %60 = add nsw i64 %59, 1
  %61 = load i64, ptr %10, align 8, !tbaa !5
  %62 = load i64, ptr %11, align 8, !tbaa !5
  %63 = load i64, ptr %12, align 8, !tbaa !5
  call void @_Z6updatexxxxxx(i64 noundef %56, i64 noundef %57, i64 noundef %60, i64 noundef %61, i64 noundef %62, i64 noundef %63)
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #4
  %64 = load i64, ptr %9, align 8, !tbaa !5
  %65 = mul nsw i64 %64, 2
  %66 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %65
  %67 = load i64, ptr %9, align 8, !tbaa !5
  %68 = mul nsw i64 %67, 2
  %69 = add nsw i64 %68, 1
  %70 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %69
  %71 = call { i64, i64 } @_ZplRK4nodeS1_(ptr noundef nonnull align 8 dereferenceable(16) %66, ptr noundef nonnull align 8 dereferenceable(16) %70)
  %72 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 0
  %73 = extractvalue { i64, i64 } %71, 0
  store i64 %73, ptr %72, align 8
  %74 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 1
  %75 = extractvalue { i64, i64 } %71, 1
  store i64 %75, ptr %74, align 8
  %76 = load i64, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %76
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %77, ptr align 8 %14, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  br label %78

78:                                               ; preds = %43, %34, %25
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i64 0, i64 8, !5, i64 8, i64 8, !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.node = type { i64, i64 }

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

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

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i64 } @_ZplRK4nodeS1_(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updatexxxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #1 {
  tail call void @_Z6pushlzxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2)
  %7 = icmp sgt i64 %3, %1
  %8 = icmp slt i64 %4, %0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %common.ret38, label %9

9:                                                ; preds = %6
  %.not = icmp sgt i64 %3, %0
  %.not36 = icmp slt i64 %4, %1
  %or.cond37 = or i1 %.not, %.not36
  br i1 %or.cond37, label %14, label %10

10:                                               ; preds = %9
  %11 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %2
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = add nsw i64 %12, %5
  store i64 %13, ptr %11, align 8, !tbaa !5
  tail call void @_Z6pushlzxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2)
  br label %common.ret38

common.ret38:                                     ; preds = %6, %10, %14
  ret void

14:                                               ; preds = %9
  %15 = add nsw i64 %1, %0
  %16 = sdiv i64 %15, 2
  %17 = shl nsw i64 %2, 1
  tail call void @_Z6updatexxxxxx(i64 noundef %0, i64 noundef %16, i64 noundef %17, i64 noundef %3, i64 noundef %4, i64 noundef %5)
  %18 = add nsw i64 %16, 1
  %19 = or disjoint i64 %17, 1
  tail call void @_Z6updatexxxxxx(i64 noundef %18, i64 noundef %1, i64 noundef %19, i64 noundef %3, i64 noundef %4, i64 noundef %5)
  %20 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %17
  %21 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %19
  %22 = tail call { i64, i64 } @_ZplRK4nodeS1_(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef nonnull align 8 dereferenceable(16) %21)
  %23 = extractvalue { i64, i64 } %22, 0
  %24 = extractvalue { i64, i64 } %22, 1
  %25 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %2
  store i64 %23, ptr %25, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %25, i64 8
  store i64 %24, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  br label %common.ret38
}

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

!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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


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