; LLVM IR from Tunghohin/Competitive_Coding :: Uva/uva11992.ll (Z5buildiiiP4Node)

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

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

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiiiP4Node(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.Node, align 8
  %10 = alloca i32, align 4
  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 ptr %3, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 40, ptr %9) #4
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 40, i1 false)
  %11 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 0
  %12 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %12, ptr %11, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 1
  %14 = load i32, ptr %7, align 4, !tbaa !5
  store i32 %14, ptr %13, align 4, !tbaa !14
  %15 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 2
  %16 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 3
  %17 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 4
  %18 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 5
  %19 = getelementptr inbounds %struct.Node, ptr %9, i32 0, i32 6
  %20 = load ptr, ptr %8, align 8, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds %struct.Node, ptr %20, i64 %22
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %23, ptr align 8 %9, i64 40, i1 false), !tbaa.struct !15
  call void @llvm.lifetime.end.p0(i64 40, ptr %9) #4
  %24 = load i32, ptr %6, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp eq i32 %24, %25
  br i1 %26, label %27, label %53

27:                                               ; preds = %4
  %28 = load ptr, ptr %8, align 8, !tbaa !9
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds %struct.Node, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.Node, ptr %31, i32 0, i32 2
  store i64 0, ptr %32, align 8, !tbaa !17
  %33 = load ptr, ptr %8, align 8, !tbaa !9
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.Node, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.Node, ptr %36, i32 0, i32 3
  store i32 -1, ptr %37, align 8, !tbaa !18
  %38 = load ptr, ptr %8, align 8, !tbaa !9
  %39 = load i32, ptr %5, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds %struct.Node, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct.Node, ptr %41, i32 0, i32 4
  store i64 0, ptr %42, align 8, !tbaa !19
  %43 = load ptr, ptr %8, align 8, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds %struct.Node, ptr %43, i64 %45
  %47 = getelementptr inbounds %struct.Node, ptr %46, i32 0, i32 5
  store i32 1000000000, ptr %47, align 8, !tbaa !20
  %48 = load ptr, ptr %8, align 8, !tbaa !9
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %struct.Node, ptr %48, i64 %50
  %52 = getelementptr inbounds %struct.Node, ptr %51, i32 0, i32 6
  store i32 -1000000000, ptr %52, align 4, !tbaa !21
  br label %72

53:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = add nsw i32 %54, %55
  %57 = ashr i32 %56, 1
  store i32 %57, ptr %10, align 4, !tbaa !5
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = shl i32 %58, 1
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z5buildiiiP4Node(i32 noundef %59, i32 noundef %60, i32 noundef %61, ptr noundef %62)
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = shl i32 %63, 1
  %65 = or i32 %64, 1
  %66 = load i32, ptr %10, align 4, !tbaa !5
  %67 = add nsw i32 %66, 1
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z5buildiiiP4Node(i32 noundef %65, i32 noundef %67, i32 noundef %68, ptr noundef %69)
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = load ptr, ptr %8, align 8, !tbaa !9
  call void @_Z7push_upiP4Node(i32 noundef %70, ptr noundef %71)
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %72

72:                                               ; preds = %53, %27
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; 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) #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: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 0}
!12 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !13, i64 8, !6, i64 16, !13, i64 24, !6, i64 32, !6, i64 36}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !6, i64 4}
!15 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 8, !16, i64 16, i64 4, !5, i64 24, i64 8, !16, i64 32, i64 4, !5, i64 36, i64 4, !5}
!16 = !{!13, !13, i64 0}
!17 = !{!12, !13, i64 8}
!18 = !{!12, !6, i64 16}
!19 = !{!12, !13, i64 24}
!20 = !{!12, !6, i64 32}
!21 = !{!12, !6, i64 36}


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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildiiiP4Node(i32 noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #0 {
  %5 = sext i32 %0 to i64
  %6 = getelementptr inbounds %struct.Node, ptr %3, i64 %5
  store i32 %1, ptr %6, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 4
  store i32 %2, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %6, i64 8
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %.sroa.6.0..sroa_idx, i8 0, i64 32, i1 false)
  %7 = icmp eq i32 %1, %2
  br i1 %7, label %common.ret, label %12

common.ret:                                       ; preds = %4
  store i64 0, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !9
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 -1, ptr %8, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %6, i64 24
  store i64 0, ptr %9, align 8, !tbaa !13
  %10 = getelementptr inbounds i8, ptr %6, i64 32
  store i32 1000000000, ptr %10, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %6, i64 36
  store i32 -1000000000, ptr %11, align 4, !tbaa !15
  br label %common.ret28

common.ret28:                                     ; preds = %12, %common.ret
  ret void

12:                                               ; preds = %4
  %13 = add nsw i32 %2, %1
  %14 = ashr i32 %13, 1
  %15 = shl i32 %0, 1
  tail call void @_Z5buildiiiP4Node(i32 noundef %15, i32 noundef %1, i32 noundef %14, ptr noundef nonnull %3)
  %16 = or disjoint i32 %15, 1
  %17 = add nsw i32 %14, 1
  tail call void @_Z5buildiiiP4Node(i32 noundef %16, i32 noundef %17, i32 noundef %2, ptr noundef nonnull %3)
  tail call void @_Z7push_upiP4Node(i32 noundef %0, ptr noundef nonnull %3)
  br label %common.ret28
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 8}
!10 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !11, i64 8, !6, i64 16, !11, i64 24, !6, i64 32, !6, i64 36}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !11, i64 24}
!14 = !{!10, !6, i64 32}
!15 = !{!10, !6, i64 36}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass