; LLVM IR from viveakrt/Competitive-programing :: SPOJ/ttm.ll (Z6pushlziii)

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6pushlziii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %10
  %12 = getelementptr inbounds %struct.node, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  br label %87

16:                                               ; preds = %3
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.node, ptr %19, i32 0, i32 1
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sub nsw i32 %22, %23
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = mul nsw i64 %21, %26
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [20000200 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 8, !tbaa !12
  %33 = add nsw i64 %32, %27
  store i64 %33, ptr %31, align 8, !tbaa !12
  %34 = load i32, ptr %4, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = icmp ne i32 %34, %35
  br i1 %36, label %37, label %82

37:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 2
  %42 = load i32, ptr %41, align 8, !tbaa !13
  %43 = call noundef i32 @_Z5clonei(i32 noundef %42)
  store i32 %43, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 3
  %48 = load i32, ptr %47, align 4, !tbaa !14
  %49 = call noundef i32 @_Z5clonei(i32 noundef %48)
  store i32 %49, ptr %8, align 4, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.node, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = add nsw i64 %59, %54
  store i64 %60, ptr %58, align 8, !tbaa !9
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %62
  %64 = getelementptr inbounds %struct.node, ptr %63, i32 0, i32 1
  %65 = load i64, ptr %64, align 8, !tbaa !9
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.node, ptr %68, i32 0, i32 1
  %70 = load i64, ptr %69, align 8, !tbaa !9
  %71 = add nsw i64 %70, %65
  store i64 %71, ptr %69, align 8, !tbaa !9
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %74
  %76 = getelementptr inbounds %struct.node, ptr %75, i32 0, i32 2
  store i32 %72, ptr %76, align 8, !tbaa !13
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %79
  %81 = getelementptr inbounds %struct.node, ptr %80, i32 0, i32 3
  store i32 %77, ptr %81, align 4, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %82

82:                                               ; preds = %37, %16
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.node, ptr %85, i32 0, i32 1
  store i64 0, ptr %86, align 8, !tbaa !9
  br label %87

87:                                               ; preds = %82, %15
  ret void
}

; 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

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 = { 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, !11, i64 8}
!10 = !{!"_ZTS4node", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 20}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!10, !6, i64 20}


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

@tree = external dso_local local_unnamed_addr global [20000200 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 void @_Z6pushlziii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %2 to i64
  %5 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %4
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %32, label %8

8:                                                ; preds = %3
  %reass.sub = sub i32 %1, %0
  %9 = add i32 %reass.sub, 1
  %10 = sext i32 %9 to i64
  %11 = mul nsw i64 %7, %10
  %12 = load i64, ptr %5, align 8, !tbaa !11
  %13 = add nsw i64 %12, %11
  store i64 %13, ptr %5, align 8, !tbaa !11
  %.not18 = icmp eq i32 %0, %1
  br i1 %.not18, label %31, label %14

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %5, i64 16
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = tail call noundef i32 @_Z5clonei(i32 noundef %16)
  %18 = getelementptr inbounds i8, ptr %5, i64 20
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = tail call noundef i32 @_Z5clonei(i32 noundef %19)
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = sext i32 %17 to i64
  %23 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %22, i32 1
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = add nsw i64 %24, %21
  store i64 %25, ptr %23, align 8, !tbaa !5
  %26 = load i64, ptr %6, align 8, !tbaa !5
  %27 = sext i32 %20 to i64
  %28 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %27, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = add nsw i64 %29, %26
  store i64 %30, ptr %28, align 8, !tbaa !5
  store i32 %17, ptr %15, align 8, !tbaa !12
  store i32 %20, ptr %18, align 4, !tbaa !13
  br label %31

31:                                               ; preds = %14, %8
  store i64 0, ptr %6, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %3, %31
  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, !7, i64 8}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 20}


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