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

; 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 }
%class.anon = type { ptr }

@que = external dso_local global [200001 x [3 x i32]], align 16
@pos = external dso_local global [200001 x i32], align 16
@ord = external dso_local global [200001 x i32], align 16
@tree = external dso_local global [200001 x %struct.Node], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z8kd_buildiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %class.anon, align 8
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = add nsw i32 %11, %12
  %14 = ashr i32 %13, 1
  store i32 %14, ptr %9, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i32, ptr @ord, i64 %16
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @ord, i64 %19
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr @ord, i64 %22
  %24 = getelementptr inbounds i32, ptr %23, i64 1
  %25 = getelementptr inbounds %class.anon, ptr %10, i32 0, i32 0
  store ptr %7, ptr %25, align 8, !tbaa !9
  %26 = getelementptr inbounds %class.anon, ptr %10, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8
  call void @"_ZSt11nth_elementIPiZ8kd_buildiiiiE3$_0EvT_S2_S2_T0_"(ptr noundef %17, ptr noundef %20, ptr noundef %24, ptr %27)
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200001 x i32], ptr @ord, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %33
  store i32 %28, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %36
  %38 = load i32, ptr %8, align 4, !tbaa !5
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [200001 x i32], ptr @ord, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [200001 x [3 x i32]], ptr @que, i64 0, i64 %43
  %45 = getelementptr inbounds [3 x i32], ptr %44, i64 0, i64 0
  call void @_ZN4Node4initEiPi(ptr noundef nonnull align 4 dereferenceable(52) %37, i32 noundef %38, ptr noundef %45)
  %46 = load i32, ptr %5, align 4, !tbaa !5
  %47 = load i32, ptr %9, align 4, !tbaa !5
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %49, label %71

49:                                               ; preds = %4
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = load i32, ptr %9, align 4, !tbaa !5
  %52 = sub nsw i32 %51, 1
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = xor i32 %53, 1
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = call noundef i32 @_Z8kd_buildiiii(i32 noundef %50, i32 noundef %52, i32 noundef %54, i32 noundef %55)
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 1
  store i32 %56, ptr %60, align 4, !tbaa !11
  %61 = load i32, ptr %9, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %62
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %65
  %67 = getelementptr inbounds %struct.Node, ptr %66, i32 0, i32 1
  %68 = load i32, ptr %67, align 4, !tbaa !11
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %69
  call void @_ZN4Node3updERKS_(ptr noundef nonnull align 4 dereferenceable(52) %63, ptr noundef nonnull align 4 dereferenceable(52) %70)
  br label %71

71:                                               ; preds = %49, %4
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = icmp slt i32 %72, %73
  br i1 %74, label %75, label %97

75:                                               ; preds = %71
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = add nsw i32 %76, 1
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !5
  %80 = xor i32 %79, 1
  %81 = load i32, ptr %9, align 4, !tbaa !5
  %82 = call noundef i32 @_Z8kd_buildiiii(i32 noundef %77, i32 noundef %78, i32 noundef %80, i32 noundef %81)
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %84
  %86 = getelementptr inbounds %struct.Node, ptr %85, i32 0, i32 2
  store i32 %82, ptr %86, align 4, !tbaa !13
  %87 = load i32, ptr %9, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %88
  %90 = load i32, ptr %9, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.Node, ptr %92, i32 0, i32 2
  %94 = load i32, ptr %93, align 4, !tbaa !13
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %95
  call void @_ZN4Node3updERKS_(ptr noundef nonnull align 4 dereferenceable(52) %89, ptr noundef nonnull align 4 dereferenceable(52) %96)
  br label %97

97:                                               ; preds = %75, %71
  %98 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %98
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZSt11nth_elementIPiZ8kd_buildiiiiE3$_0EvT_S2_S2_T0_"(ptr noundef, ptr noundef, ptr noundef, ptr) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node4initEiPi(ptr noundef nonnull align 4 dereferenceable(52), i32 noundef, ptr noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node3updERKS_(ptr noundef nonnull align 4 dereferenceable(52), ptr noundef nonnull align 4 dereferenceable(52)) #3 align 2

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

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 = { inlinehint 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 #3 = { 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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 4}
!12 = !{!"_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}
!13 = !{!12, !6, i64 8}


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

@que = external dso_local global [200001 x [3 x i32]], align 16
@pos = external dso_local local_unnamed_addr global [200001 x i32], align 16
@ord = external dso_local global [200001 x i32], align 16
@tree = external dso_local global [200001 x %struct.Node], align 16

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 -1073741824, 1073741824) i32 @_Z8kd_buildiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca i32, align 4
  store i32 %2, ptr %5, align 4, !tbaa !5
  %6 = add nsw i32 %1, %0
  %7 = ashr i32 %6, 1
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds i32, ptr @ord, i64 %8
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds i32, ptr @ord, i64 %10
  %12 = sext i32 %1 to i64
  %13 = getelementptr inbounds i32, ptr @ord, i64 %12
  %14 = getelementptr inbounds i8, ptr %13, i64 4
  call void @"_ZSt11nth_elementIPiZ8kd_buildiiiiE3$_0EvT_S2_S2_T0_"(ptr noundef nonnull %9, ptr noundef nonnull %11, ptr noundef nonnull %14, ptr nonnull %5)
  %15 = load i32, ptr %11, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [200001 x i32], ptr @pos, i64 0, i64 %16
  store i32 %7, ptr %17, align 4, !tbaa !5
  %18 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %10
  %19 = getelementptr inbounds [200001 x [3 x i32]], ptr @que, i64 0, i64 %16
  call void @_ZN4Node4initEiPi(ptr noundef nonnull align 4 dereferenceable(52) %18, i32 noundef %3, ptr noundef nonnull %19)
  %20 = icmp sgt i32 %7, %0
  br i1 %20, label %21, label %29

21:                                               ; preds = %4
  %22 = add nsw i32 %7, -1
  %23 = load i32, ptr %5, align 4, !tbaa !5
  %24 = xor i32 %23, 1
  %25 = call noundef i32 @_Z8kd_buildiiii(i32 noundef %0, i32 noundef %22, i32 noundef %24, i32 noundef %7)
  %26 = getelementptr inbounds i8, ptr %18, i64 4
  store i32 %25, ptr %26, align 4, !tbaa !9
  %27 = sext i32 %25 to i64
  %28 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %27
  call void @_ZN4Node3updERKS_(ptr noundef nonnull align 4 dereferenceable(52) %18, ptr noundef nonnull align 4 dereferenceable(52) %28)
  br label %29

29:                                               ; preds = %21, %4
  %30 = icmp slt i32 %7, %1
  br i1 %30, label %31, label %39

31:                                               ; preds = %29
  %32 = add nsw i32 %7, 1
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = xor i32 %33, 1
  %35 = call noundef i32 @_Z8kd_buildiiii(i32 noundef %32, i32 noundef %1, i32 noundef %34, i32 noundef %7)
  %36 = getelementptr inbounds i8, ptr %18, i64 8
  store i32 %35, ptr %36, align 4, !tbaa !11
  %37 = sext i32 %35 to i64
  %38 = getelementptr inbounds [200001 x %struct.Node], ptr @tree, i64 0, i64 %37
  call void @_ZN4Node3updERKS_(ptr noundef nonnull align 4 dereferenceable(52) %18, ptr noundef nonnull align 4 dereferenceable(52) %38)
  br label %39

39:                                               ; preds = %31, %29
  ret i32 %7
}

; Function Attrs: inlinehint mustprogress uwtable
declare hidden void @"_ZSt11nth_elementIPiZ8kd_buildiiiiE3$_0EvT_S2_S2_T0_"(ptr noundef, ptr noundef, ptr noundef, ptr) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node4initEiPi(ptr noundef nonnull align 4 dereferenceable(52), i32 noundef, ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Node3updERKS_(ptr noundef nonnull align 4 dereferenceable(52), ptr noundef nonnull align 4 dereferenceable(52)) local_unnamed_addr #2 align 2

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 = { inlinehint 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 = { 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, !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}


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