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

; 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: mustprogress nounwind uwtable
define dso_local void @_Z6pushlzxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !5
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = icmp ne i64 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %3
  br label %58

12:                                               ; preds = %3
  %13 = load i64, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = load i64, ptr %5, align 8, !tbaa !5
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = sub nsw i64 %16, %17
  %19 = add nsw i64 %18, 1
  %20 = mul nsw i64 %15, %19
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.node, ptr %22, i32 0, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = add nsw i64 %24, %20
  store i64 %25, ptr %23, align 8, !tbaa !9
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = load i64, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.node, ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 16, !tbaa !11
  %33 = add nsw i64 %32, %28
  store i64 %33, ptr %31, align 16, !tbaa !11
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !5
  %36 = icmp ne i64 %34, %35
  br i1 %36, label %37, label %55

37:                                               ; preds = %12
  %38 = load i64, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr %6, align 8, !tbaa !5
  %42 = mul nsw i64 %41, 2
  %43 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %42
  %44 = load i64, ptr %43, align 8, !tbaa !5
  %45 = add nsw i64 %44, %40
  store i64 %45, ptr %43, align 8, !tbaa !5
  %46 = load i64, ptr %6, align 8, !tbaa !5
  %47 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %46
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = mul nsw i64 %49, 2
  %51 = add nsw i64 %50, 1
  %52 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = add nsw i64 %53, %48
  store i64 %54, ptr %52, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %37, %12
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %56
  store i64 0, ptr %57, align 8, !tbaa !5
  br label %58

58:                                               ; preds = %55, %11
  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 = !{!"long long", !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 8}
!11 = !{!10, !6, 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, i64 }

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z6pushlzxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %2
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %26, label %6

6:                                                ; preds = %3
  %reass.sub = sub i64 %1, %0
  %7 = add i64 %reass.sub, 1
  %8 = mul nsw i64 %5, %7
  %9 = getelementptr inbounds [1048576 x %struct.node], ptr @tree, i64 0, i64 %2
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = add nsw i64 %11, %8
  store i64 %12, ptr %10, align 8, !tbaa !9
  %13 = load i64, ptr %9, align 16, !tbaa !11
  %14 = add nsw i64 %13, %5
  store i64 %14, ptr %9, align 16, !tbaa !11
  %.not14 = icmp eq i64 %0, %1
  br i1 %.not14, label %25, label %15

15:                                               ; preds = %6
  %16 = shl nsw i64 %2, 1
  %17 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %16
  %18 = load i64, ptr %17, align 16, !tbaa !5
  %19 = add nsw i64 %18, %5
  store i64 %19, ptr %17, align 16, !tbaa !5
  %20 = load i64, ptr %4, align 8, !tbaa !5
  %21 = or disjoint i64 %16, 1
  %22 = getelementptr inbounds [1048576 x i64], ptr @lazy, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = add nsw i64 %23, %20
  store i64 %24, ptr %22, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %15, %6
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %3, %25
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS4node", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, i64 0}


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