; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions/GSS3.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.no = type { i32, i32, i32, i32 }

@tree = external dso_local global [400001 x %struct.no], align 16
@array = external dso_local global [100001 x i32], 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.no, align 4
  %8 = alloca %struct.no, align 4
  %9 = alloca %struct.no, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = 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
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = icmp eq i32 %13, %14
  br i1 %15, label %16, label %40

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %17 = getelementptr inbounds %struct.no, ptr %7, i32 0, i32 0
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  store i32 %21, ptr %17, align 4, !tbaa !9
  %22 = getelementptr inbounds %struct.no, ptr %7, i32 0, i32 1
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr %22, align 4, !tbaa !11
  %27 = getelementptr inbounds %struct.no, ptr %7, i32 0, i32 2
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  store i32 %31, ptr %27, align 4, !tbaa !12
  %32 = getelementptr inbounds %struct.no, ptr %7, i32 0, i32 3
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  store i32 %36, ptr %32, align 4, !tbaa !13
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %38
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %39, ptr align 4 %7, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %113

40:                                               ; preds = %3
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = mul nsw i32 %41, 2
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = sdiv i32 %46, 2
  call void @_Z4initiii(i32 noundef %42, i32 noundef %43, i32 noundef %47)
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = mul nsw i32 %48, 2
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %5, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  %54 = sdiv i32 %53, 2
  %55 = add nsw i32 %54, 1
  %56 = load i32, ptr %6, align 4, !tbaa !5
  call void @_Z4initiii(i32 noundef %50, i32 noundef %55, i32 noundef %56)
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = mul nsw i32 %57, 2
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %59
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %8, ptr align 16 %60, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  %61 = load i32, ptr %4, align 4, !tbaa !5
  %62 = mul nsw i32 %61, 2
  %63 = add nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %64
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 16 %65, i64 16, i1 false), !tbaa.struct !14
  %66 = getelementptr inbounds %struct.no, ptr %8, i32 0, i32 0
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %67 = getelementptr inbounds %struct.no, ptr %8, i32 0, i32 3
  %68 = load i32, ptr %67, align 4, !tbaa !13
  %69 = getelementptr inbounds %struct.no, ptr %9, i32 0, i32 0
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = add nsw i32 %68, %70
  store i32 %71, ptr %10, align 4, !tbaa !5
  %72 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %66, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = load i32, ptr %4, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %75
  %77 = getelementptr inbounds %struct.no, ptr %76, i32 0, i32 0
  store i32 %73, ptr %77, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %78 = getelementptr inbounds %struct.no, ptr %9, i32 0, i32 1
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %79 = getelementptr inbounds %struct.no, ptr %9, i32 0, i32 3
  %80 = load i32, ptr %79, align 4, !tbaa !13
  %81 = getelementptr inbounds %struct.no, ptr %8, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !11
  %83 = add nsw i32 %80, %82
  store i32 %83, ptr %11, align 4, !tbaa !5
  %84 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %78, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.no, ptr %88, i32 0, i32 1
  store i32 %85, ptr %89, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  %90 = getelementptr inbounds %struct.no, ptr %8, i32 0, i32 2
  %91 = getelementptr inbounds %struct.no, ptr %9, i32 0, i32 2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %92 = getelementptr inbounds %struct.no, ptr %8, i32 0, i32 1
  %93 = load i32, ptr %92, align 4, !tbaa !11
  %94 = getelementptr inbounds %struct.no, ptr %9, i32 0, i32 0
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = add nsw i32 %93, %95
  store i32 %96, ptr %12, align 4, !tbaa !5
  %97 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %91, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %98 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %90, ptr noundef nonnull align 4 dereferenceable(4) %97)
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = load i32, ptr %4, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %101
  %103 = getelementptr inbounds %struct.no, ptr %102, i32 0, i32 2
  store i32 %99, ptr %103, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %104 = getelementptr inbounds %struct.no, ptr %8, i32 0, i32 3
  %105 = load i32, ptr %104, align 4, !tbaa !13
  %106 = getelementptr inbounds %struct.no, ptr %9, i32 0, i32 3
  %107 = load i32, ptr %106, align 4, !tbaa !13
  %108 = add nsw i32 %105, %107
  %109 = load i32, ptr %4, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %110
  %112 = getelementptr inbounds %struct.no, ptr %111, i32 0, i32 3
  store i32 %108, ptr %112, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  br label %113

113:                                              ; preds = %40, %16
  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 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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, !6, i64 0}
!10 = !{!"_ZTS2no", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!11 = !{!10, !6, i64 4}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !6, i64 12}
!14 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !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.no = type { i32, i32, i32, i32 }

@tree = external dso_local local_unnamed_addr global [400001 x %struct.no], align 16
@array = external dso_local local_unnamed_addr global [100001 x i32], 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.no, align 4
  %5 = alloca %struct.no, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = icmp eq i32 %1, %2
  br i1 %9, label %common.ret, label %17

common.ret:                                       ; preds = %3
  %10 = sext i32 %1 to i64
  %11 = getelementptr inbounds [100001 x i32], ptr @array, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %0 to i64
  %14 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %13
  %15 = insertelement <4 x i32> poison, i32 %12, i64 0
  %16 = shufflevector <4 x i32> %15, <4 x i32> poison, <4 x i32> zeroinitializer
  store <4 x i32> %16, ptr %14, align 16, !tbaa !5
  br label %common.ret22

common.ret22:                                     ; preds = %17, %common.ret
  ret void

17:                                               ; preds = %3
  %18 = shl nsw i32 %0, 1
  %19 = add nsw i32 %2, %1
  %20 = sdiv i32 %19, 2
  tail call void @_Z4initiii(i32 noundef %18, i32 noundef %1, i32 noundef %20)
  %21 = or disjoint i32 %18, 1
  %22 = add nsw i32 %20, 1
  tail call void @_Z4initiii(i32 noundef %21, i32 noundef %22, i32 noundef %2)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #4
  %23 = sext i32 %18 to i64
  %24 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %23
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %4, ptr noundef nonnull align 16 dereferenceable(16) %24, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #4
  %25 = sext i32 %21 to i64
  %26 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %25
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %5, ptr noundef nonnull align 16 dereferenceable(16) %26, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %27 = getelementptr inbounds i8, ptr %4, i64 12
  %28 = load i32, ptr %27, align 4, !tbaa !10
  %29 = load i32, ptr %5, align 4, !tbaa !12
  %30 = add nsw i32 %29, %28
  store i32 %30, ptr %6, align 4, !tbaa !5
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %0 to i64
  %34 = getelementptr inbounds [400001 x %struct.no], ptr @tree, i64 0, i64 %33
  store i32 %32, ptr %34, align 16, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  %35 = getelementptr inbounds i8, ptr %5, i64 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  %36 = getelementptr inbounds i8, ptr %5, i64 12
  %37 = load i32, ptr %36, align 4, !tbaa !10
  %38 = getelementptr inbounds i8, ptr %4, i64 4
  %39 = load i32, ptr %38, align 4, !tbaa !13
  %40 = add nsw i32 %39, %37
  store i32 %40, ptr %7, align 4, !tbaa !5
  %41 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %35, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %34, i64 4
  store i32 %42, ptr %43, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  %44 = getelementptr inbounds i8, ptr %4, i64 8
  %45 = getelementptr inbounds i8, ptr %5, i64 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #4
  %46 = load i32, ptr %38, align 4, !tbaa !13
  %47 = load i32, ptr %5, align 4, !tbaa !12
  %48 = add nsw i32 %47, %46
  store i32 %48, ptr %8, align 4, !tbaa !5
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %45, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %50 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %44, ptr noundef nonnull align 4 dereferenceable(4) %49)
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %34, i64 8
  store i32 %51, ptr %52, align 8, !tbaa !14
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #4
  %53 = load i32, ptr %27, align 4, !tbaa !10
  %54 = load i32, ptr %36, align 4, !tbaa !10
  %55 = add nsw i32 %54, %53
  %56 = getelementptr inbounds i8, ptr %34, i64 12
  store i32 %55, ptr %56, align 4, !tbaa !10
  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.ret22
}

; 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 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5}
!10 = !{!11, !6, i64 12}
!11 = !{!"_ZTS2no", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!12 = !{!11, !6, i64 0}
!13 = !{!11, !6, i64 4}
!14 = !{!11, !6, i64 8}


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