; LLVM IR from tangjz/acm-icpc :: hdu/5994.ll (Z5kd_upi)

; 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, [2 x i32], [2 x i32], [2 x i32], i32, i32, i32, i32 }

@tree = external dso_local global [200001 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 nounwind uwtable
define dso_local void @_Z5kd_upi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %6
  %8 = getelementptr inbounds %struct.Node, ptr %7, i32 0, i32 1
  %9 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %9, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.Node, ptr %12, i32 0, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !11
  store i32 %14, ptr %4, align 4, !tbaa !5
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.Node, ptr %17, i32 0, i32 6
  %19 = load i32, ptr %18, align 4, !tbaa !12
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 7
  store i32 %19, ptr %23, align 4, !tbaa !13
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.Node, ptr %27, i32 0, i32 8
  store i32 %24, ptr %28, align 4, !tbaa !14
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 7
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 7
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = icmp slt i32 %33, %38
  br i1 %39, label %40, label %59

40:                                               ; preds = %1
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Node, ptr %43, i32 0, i32 7
  %45 = load i32, ptr %44, align 4, !tbaa !13
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.Node, ptr %48, i32 0, i32 7
  store i32 %45, ptr %49, align 4, !tbaa !13
  %50 = load i32, ptr %3, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.Node, ptr %52, i32 0, i32 8
  %54 = load i32, ptr %53, align 4, !tbaa !14
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Node, ptr %57, i32 0, i32 8
  store i32 %54, ptr %58, align 4, !tbaa !14
  br label %59

59:                                               ; preds = %40, %1
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %61
  %63 = getelementptr inbounds %struct.Node, ptr %62, i32 0, i32 7
  %64 = load i32, ptr %63, align 4, !tbaa !13
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %66
  %68 = getelementptr inbounds %struct.Node, ptr %67, i32 0, i32 7
  %69 = load i32, ptr %68, align 4, !tbaa !13
  %70 = icmp slt i32 %64, %69
  br i1 %70, label %71, label %90

71:                                               ; preds = %59
  %72 = load i32, ptr %4, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.Node, ptr %74, i32 0, i32 7
  %76 = load i32, ptr %75, align 4, !tbaa !13
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %78
  %80 = getelementptr inbounds %struct.Node, ptr %79, i32 0, i32 7
  store i32 %76, ptr %80, align 4, !tbaa !13
  %81 = load i32, ptr %4, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %82
  %84 = getelementptr inbounds %struct.Node, ptr %83, i32 0, i32 8
  %85 = load i32, ptr %84, align 4, !tbaa !14
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %87
  %89 = getelementptr inbounds %struct.Node, ptr %88, i32 0, i32 8
  store i32 %85, ptr %89, align 4, !tbaa !14
  br label %90

90:                                               ; preds = %71, %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 4}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8, !7, i64 12, !7, i64 20, !7, i64 28, !6, i64 36, !6, i64 40, !6, i64 44, !6, i64 48}
!11 = !{!10, !6, i64 8}
!12 = !{!10, !6, i64 36}
!13 = !{!10, !6, i64 40}
!14 = !{!10, !6, i64 44}


; 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, [2 x i32], [2 x i32], [2 x i32], i32, i32, i32, i32 }

@tree = external dso_local local_unnamed_addr global [200001 x %struct.Node], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5kd_upi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %2
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 8
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %3, i64 36
  %9 = load i32, ptr %8, align 4, !tbaa !11
  %10 = getelementptr inbounds i8, ptr %3, i64 40
  store i32 %9, ptr %10, align 4, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %3, i64 44
  store i32 %0, ptr %11, align 4, !tbaa !13
  %12 = sext i32 %5 to i64
  %13 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 40
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = icmp slt i32 %15, %9
  br i1 %16, label %17, label %20

17:                                               ; preds = %1
  store i32 %15, ptr %10, align 4, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %13, i64 44
  %19 = load i32, ptr %18, align 4, !tbaa !13
  store i32 %19, ptr %11, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %17, %1
  %21 = phi i32 [ %15, %17 ], [ %9, %1 ]
  %22 = sext i32 %7 to i64
  %23 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %22
  %24 = getelementptr inbounds i8, ptr %23, i64 40
  %25 = load i32, ptr %24, align 4, !tbaa !12
  %26 = icmp slt i32 %25, %21
  br i1 %26, label %27, label %30

27:                                               ; preds = %20
  store i32 %25, ptr %10, align 4, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %23, i64 44
  %29 = load i32, ptr %28, align 4, !tbaa !13
  store i32 %29, ptr %11, align 4, !tbaa !13
  br label %30

30:                                               ; preds = %27, %20
  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, !7, i64 4}
!6 = !{!"_ZTS4Node", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 20, !8, i64 28, !7, i64 36, !7, i64 40, !7, i64 44, !7, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 36}
!12 = !{!6, !7, i64 40}
!13 = !{!6, !7, i64 44}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass