; LLVM IR from tangjz/acm-icpc :: 51nod/1967.ll (Z3addi)

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

@u = external dso_local global [400005 x i32], align 16
@v = external dso_local global [400005 x i32], align 16
@tot = external dso_local global i32, align 4
@p = external dso_local global [100005 x i32], align 16
@e = external dso_local global [800011 x %struct.Node], 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 uwtable
declare dso_local void @_Z9dsu_mergeii(i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca %struct.Node, align 4
  %4 = alloca %struct.Node, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = load i32, ptr @tot, align 4, !tbaa !5
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [400005 x i32], ptr @u, i64 0, i64 %7
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %13
  %15 = getelementptr inbounds %struct.Node, ptr %14, i32 0, i32 0
  store i32 %5, ptr %15, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #3
  %16 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 0
  store i32 -1, ptr %16, align 4, !tbaa !9
  %17 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 1
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [400005 x i32], ptr @u, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr %17, align 4, !tbaa !11
  %25 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 2
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [400005 x i32], ptr @v, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  store i32 %29, ptr %25, align 4, !tbaa !12
  %30 = getelementptr inbounds %struct.Node, ptr %3, i32 0, i32 3
  %31 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %31, ptr %30, align 4, !tbaa !13
  %32 = load i32, ptr @tot, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %33
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %34, ptr align 4 %3, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #3
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @tot, align 4, !tbaa !5
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [400005 x i32], ptr @u, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %41
  store i32 %35, ptr %42, align 4, !tbaa !5
  %43 = load i32, ptr @tot, align 4, !tbaa !5
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [400005 x i32], ptr @v, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 0
  store i32 %43, ptr %53, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #3
  %54 = getelementptr inbounds %struct.Node, ptr %4, i32 0, i32 0
  store i32 -1, ptr %54, align 4, !tbaa !9
  %55 = getelementptr inbounds %struct.Node, ptr %4, i32 0, i32 1
  %56 = load i32, ptr %2, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [400005 x i32], ptr @v, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  store i32 %62, ptr %55, align 4, !tbaa !11
  %63 = getelementptr inbounds %struct.Node, ptr %4, i32 0, i32 2
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [400005 x i32], ptr @u, i64 0, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !5
  store i32 %67, ptr %63, align 4, !tbaa !12
  %68 = getelementptr inbounds %struct.Node, ptr %4, i32 0, i32 3
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = sub nsw i32 0, %69
  store i32 %70, ptr %68, align 4, !tbaa !13
  %71 = load i32, ptr @tot, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %72
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %73, ptr align 4 %4, i64 16, i1 false), !tbaa.struct !14
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #3
  %74 = load i32, ptr @tot, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr @tot, align 4, !tbaa !5
  %76 = load i32, ptr %2, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [400005 x i32], ptr @v, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %80
  store i32 %74, ptr %81, align 4, !tbaa !5
  %82 = load i32, ptr %2, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [400005 x i32], ptr @u, i64 0, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [400005 x i32], ptr @v, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  call void @_Z9dsu_mergeii(i32 noundef %85, i32 noundef %89)
  ret void
}

; 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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!"_ZTS4Node", !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.Node = type { i32, i32, i32, i32 }

@u = external dso_local local_unnamed_addr global [400005 x i32], align 16
@v = external dso_local local_unnamed_addr global [400005 x i32], align 16
@tot = external dso_local local_unnamed_addr global i32, align 4
@p = external dso_local local_unnamed_addr global [100005 x i32], align 16
@e = external dso_local local_unnamed_addr global [800011 x %struct.Node], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9dsu_mergeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3addi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @tot, align 4, !tbaa !5
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [400005 x i32], ptr @u, i64 0, i64 %3
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %9
  store i32 %2, ptr %10, align 16, !tbaa !9
  %11 = getelementptr inbounds [400005 x i32], ptr @v, i64 0, i64 %3
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sext i32 %2 to i64
  %14 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %13
  store i32 -1, ptr %14, align 16, !tbaa !5
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 4
  store i32 %8, ptr %.sroa.42.0..sroa_idx, align 4, !tbaa !5
  %.sroa.53.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 8
  store i32 %12, ptr %.sroa.53.0..sroa_idx, align 8, !tbaa !5
  %.sroa.64.0..sroa_idx = getelementptr inbounds i8, ptr %14, i64 12
  store i32 %0, ptr %.sroa.64.0..sroa_idx, align 4, !tbaa !5
  %15 = add nsw i32 %2, 1
  store i32 %2, ptr %7, align 4, !tbaa !5
  %16 = sext i32 %12 to i64
  %17 = getelementptr inbounds [100005 x i32], ptr @p, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %19
  store i32 %15, ptr %20, align 16, !tbaa !9
  %21 = sub nsw i32 0, %0
  %22 = sext i32 %15 to i64
  %23 = getelementptr inbounds [800011 x %struct.Node], ptr @e, i64 0, i64 %22
  store i32 -1, ptr %23, align 16, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 4
  store i32 %18, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 8
  store i32 %5, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %23, i64 12
  store i32 %21, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !5
  %24 = add nsw i32 %2, 2
  store i32 %24, ptr @tot, align 4, !tbaa !5
  store i32 %15, ptr %17, align 4, !tbaa !5
  tail call void @_Z9dsu_mergeii(i32 noundef %5, i32 noundef %12)
  ret void
}

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

!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 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}


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