; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions/KGSS.ll (Z4initiii)

; 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.sum = type { i64, i64 }

@array = external dso_local global [100001 x i32], align 16
@tree = external dso_local global [400001 x %struct.sum], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z4initiii(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 %struct.sum, align 8
  %8 = alloca %struct.sum, align 8
  %9 = alloca %struct.sum, align 8
  %10 = alloca i64, align 8
  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
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %30

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %15 = getelementptr inbounds %struct.sum, ptr %7, i32 0, i32 0
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  store i64 %20, ptr %15, align 8, !tbaa !9
  %21 = getelementptr inbounds %struct.sum, ptr %7, i32 0, i32 1
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  store i64 %26, ptr %21, align 8, !tbaa !12
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %28
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %29, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %78

30:                                               ; preds = %3
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = mul nsw i32 %31, 2
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = sdiv i32 %36, 2
  call void @_Z4initiii(i32 noundef %32, i32 noundef %33, i32 noundef %37)
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = mul nsw i32 %38, 2
  %40 = add nsw i32 %39, 1
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !5
  %43 = add nsw i32 %41, %42
  %44 = sdiv i32 %43, 2
  %45 = add nsw i32 %44, 1
  %46 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z4initiii(i32 noundef %40, i32 noundef %45, i32 noundef %46)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = mul nsw i32 %47, 2
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %49
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %8, ptr align 16 %50, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = mul nsw i32 %51, 2
  %53 = add nsw i32 %52, 1
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %54
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %9, ptr align 16 %55, i64 16, i1 false), !tbaa.struct !13
  %56 = getelementptr inbounds %struct.sum, ptr %8, i32 0, i32 0
  %57 = getelementptr inbounds %struct.sum, ptr %9, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %58 = getelementptr inbounds %struct.sum, ptr %8, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !12
  %60 = getelementptr inbounds %struct.sum, ptr %9, i32 0, i32 1
  %61 = load i64, ptr %60, align 8, !tbaa !12
  %62 = add nsw i64 %59, %61
  store i64 %62, ptr %10, align 8, !tbaa !14
  %63 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %57, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %64 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %56, ptr noundef nonnull align 8 dereferenceable(8) %63)
  %65 = load i64, ptr %64, align 8, !tbaa !14
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %67
  %69 = getelementptr inbounds %struct.sum, ptr %68, i32 0, i32 0
  store i64 %65, ptr %69, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %70 = getelementptr inbounds %struct.sum, ptr %8, i32 0, i32 1
  %71 = getelementptr inbounds %struct.sum, ptr %9, i32 0, i32 1
  %72 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %70, ptr noundef nonnull align 8 dereferenceable(8) %71)
  %73 = load i64, ptr %72, align 8, !tbaa !14
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %75
  %77 = getelementptr inbounds %struct.sum, ptr %76, i32 0, i32 1
  store i64 %73, ptr %77, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %78

78:                                               ; preds = %30, %14
  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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS3sum", !11, i64 0, !11, i64 8}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{i64 0, i64 8, !14, i64 8, i64 8, !14}
!14 = !{!11, !11, 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.sum = type { i64, i64 }

@array = external dso_local local_unnamed_addr global [100001 x i32], align 16
@tree = external dso_local local_unnamed_addr global [400001 x %struct.sum], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z4initiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = alloca %struct.sum, align 8
  %5 = alloca %struct.sum, align 8
  %6 = alloca i64, align 8
  %7 = icmp eq i32 %1, %2
  br i1 %7, label %common.ret, label %14

common.ret:                                       ; preds = %3
  %8 = sext i32 %1 to i64
  %9 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = sext i32 %0 to i64
  %13 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %12
  store i64 %11, ptr %13, align 16, !tbaa !9
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 8
  store i64 %11, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !9
  br label %common.ret18

common.ret18:                                     ; preds = %14, %common.ret
  ret void

14:                                               ; preds = %3
  %15 = shl nsw i32 %0, 1
  %16 = add nsw i32 %2, %1
  %17 = sdiv i32 %16, 2
  tail call void @_Z4initiii(i32 noundef %15, i32 noundef %1, i32 noundef %17)
  %18 = or disjoint i32 %15, 1
  %19 = add nsw i32 %17, 1
  tail call void @_Z4initiii(i32 noundef %18, i32 noundef %19, i32 noundef %2)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %20 = sext i32 %15 to i64
  %21 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %20
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 16 dereferenceable(16) %21, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %22 = sext i32 %18 to i64
  %23 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 16 dereferenceable(16) %23, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %24 = getelementptr inbounds i8, ptr %4, i64 8
  %25 = load i64, ptr %24, align 8, !tbaa !12
  %26 = getelementptr inbounds i8, ptr %5, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = add nsw i64 %27, %25
  store i64 %28, ptr %6, align 8, !tbaa !9
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %5, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %4, ptr noundef nonnull align 8 dereferenceable(8) %29)
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = sext i32 %0 to i64
  %33 = getelementptr inbounds [400001 x %struct.sum], ptr @tree, i64 0, i64 %32
  store i64 %31, ptr %33, align 16, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %24, ptr noundef nonnull align 8 dereferenceable(8) %26)
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %33, i64 8
  store i64 %35, ptr %36, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #4
  br label %common.ret18
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress 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) #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"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}
!11 = !{i64 0, i64 8, !9, i64 8, i64 8, !9}
!12 = !{!13, !10, i64 8}
!13 = !{!"_ZTS3sum", !10, i64 0, !10, i64 8}
!14 = !{!13, !10, i64 0}


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