; LLVM IR from viveakrt/Competitive-programing :: SPOJ/ttm.ll (Z6updateiiiiii)

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

@tree = external dso_local global [20000200 x %struct.node], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5clonei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z6pushlziii(i32 noundef, i32 noundef, i32 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 noundef i32 @_Z6updateiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #2 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 %0, ptr %8, align 4, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !5
  store i32 %2, ptr %10, align 4, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !5
  store i32 %4, ptr %12, align 4, !tbaa !5
  store i32 %5, ptr %13, align 4, !tbaa !5
  %17 = load i32, ptr %8, align 4, !tbaa !5
  %18 = load i32, ptr %9, align 4, !tbaa !5
  %19 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6pushlziii(i32 noundef %17, i32 noundef %18, i32 noundef %19)
  %20 = load i32, ptr %11, align 4, !tbaa !5
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = icmp sgt i32 %20, %21
  br i1 %22, label %27, label %23

23:                                               ; preds = %6
  %24 = load i32, ptr %12, align 4, !tbaa !5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %27, label %29

27:                                               ; preds = %23, %6
  %28 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %28, ptr %7, align 4
  br label %113

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = call noundef i32 @_Z5clonei(i32 noundef %30)
  store i32 %31, ptr %14, align 4, !tbaa !5
  %32 = load i32, ptr %11, align 4, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %35, label %52

35:                                               ; preds = %29
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = icmp sge i32 %36, %37
  br i1 %38, label %39, label %52

39:                                               ; preds = %35
  %40 = load i32, ptr %13, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = load i32, ptr %14, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.node, ptr %44, i32 0, i32 1
  %46 = load i64, ptr %45, align 8, !tbaa !9
  %47 = add nsw i64 %46, %41
  store i64 %47, ptr %45, align 8, !tbaa !9
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = load i32, ptr %14, align 4, !tbaa !5
  call void @_Z6pushlziii(i32 noundef %48, i32 noundef %49, i32 noundef %50)
  %51 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %51, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %112

52:                                               ; preds = %35, %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  %53 = load i32, ptr %8, align 4, !tbaa !5
  %54 = load i32, ptr %9, align 4, !tbaa !5
  %55 = add nsw i32 %53, %54
  %56 = sdiv i32 %55, 2
  store i32 %56, ptr %16, align 4, !tbaa !5
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr %16, align 4, !tbaa !5
  %59 = load i32, ptr %14, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !12
  %64 = load i32, ptr %11, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = load i32, ptr %13, align 4, !tbaa !5
  %67 = call noundef i32 @_Z6updateiiiiii(i32 noundef %57, i32 noundef %58, i32 noundef %63, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  %68 = load i32, ptr %14, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.node, ptr %70, i32 0, i32 2
  store i32 %67, ptr %71, align 8, !tbaa !12
  %72 = load i32, ptr %16, align 4, !tbaa !5
  %73 = add nsw i32 %72, 1
  %74 = load i32, ptr %9, align 4, !tbaa !5
  %75 = load i32, ptr %14, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 4, !tbaa !13
  %80 = load i32, ptr %11, align 4, !tbaa !5
  %81 = load i32, ptr %12, align 4, !tbaa !5
  %82 = load i32, ptr %13, align 4, !tbaa !5
  %83 = call noundef i32 @_Z6updateiiiiii(i32 noundef %73, i32 noundef %74, i32 noundef %79, i32 noundef %80, i32 noundef %81, i32 noundef %82)
  %84 = load i32, ptr %14, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.node, ptr %86, i32 0, i32 3
  store i32 %83, ptr %87, align 4, !tbaa !13
  %88 = load i32, ptr %14, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %89
  %91 = getelementptr inbounds %struct.node, ptr %90, i32 0, i32 2
  %92 = load i32, ptr %91, align 8, !tbaa !12
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %93
  %95 = getelementptr inbounds %struct.node, ptr %94, i32 0, i32 0
  %96 = load i64, ptr %95, align 8, !tbaa !14
  %97 = load i32, ptr %14, align 4, !tbaa !5
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %98
  %100 = getelementptr inbounds %struct.node, ptr %99, i32 0, i32 3
  %101 = load i32, ptr %100, align 4, !tbaa !13
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %102
  %104 = getelementptr inbounds %struct.node, ptr %103, i32 0, i32 0
  %105 = load i64, ptr %104, align 8, !tbaa !14
  %106 = add nsw i64 %96, %105
  %107 = load i32, ptr %14, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %108
  %110 = getelementptr inbounds %struct.node, ptr %109, i32 0, i32 0
  store i64 %106, ptr %110, align 8, !tbaa !14
  %111 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %111, ptr %7, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  br label %112

112:                                              ; preds = %52, %39
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %113

113:                                              ; preds = %112, %27
  %114 = load i32, ptr %7, align 4
  ret i32 %114
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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, !11, i64 8}
!10 = !{!"_ZTS4node", !11, i64 0, !11, i64 8, !6, i64 16, !6, i64 20}
!11 = !{!"long long", !7, i64 0}
!12 = !{!10, !6, i64 16}
!13 = !{!10, !6, i64 20}
!14 = !{!10, !11, i64 0}


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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5clonei(i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z6updateiiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  tail call void @_Z6pushlziii(i32 noundef %0, i32 noundef %1, i32 noundef %2)
  %7 = icmp sgt i32 %3, %1
  %8 = icmp slt i32 %4, %0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %common.ret45, label %9

9:                                                ; preds = %6
  %10 = tail call noundef i32 @_Z5clonei(i32 noundef %2)
  %.not = icmp sgt i32 %3, %0
  %.not43 = icmp slt i32 %4, %1
  %or.cond44 = or i1 %.not, %.not43
  br i1 %or.cond44, label %17, label %11

11:                                               ; preds = %9
  %12 = sext i32 %5 to i64
  %13 = sext i32 %10 to i64
  %14 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %13, i32 1
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %15, %12
  store i64 %16, ptr %14, align 8, !tbaa !5
  tail call void @_Z6pushlziii(i32 noundef %0, i32 noundef %1, i32 noundef %10)
  br label %common.ret45

common.ret45:                                     ; preds = %11, %6, %17
  %common.ret45.op = phi i32 [ %10, %17 ], [ %2, %6 ], [ %10, %11 ]
  ret i32 %common.ret45.op

17:                                               ; preds = %9
  %18 = add nsw i32 %1, %0
  %19 = sdiv i32 %18, 2
  %20 = sext i32 %10 to i64
  %21 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %20
  %22 = getelementptr inbounds i8, ptr %21, i64 16
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = tail call noundef i32 @_Z6updateiiiiii(i32 noundef %0, i32 noundef %19, i32 noundef %23, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  store i32 %24, ptr %22, align 8, !tbaa !11
  %25 = add nsw i32 %19, 1
  %26 = getelementptr inbounds i8, ptr %21, i64 20
  %27 = load i32, ptr %26, align 4, !tbaa !12
  %28 = tail call noundef i32 @_Z6updateiiiiii(i32 noundef %25, i32 noundef %1, i32 noundef %27, i32 noundef %3, i32 noundef %4, i32 noundef %5)
  store i32 %28, ptr %26, align 4, !tbaa !12
  %29 = load i32, ptr %22, align 8, !tbaa !11
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !13
  %33 = sext i32 %28 to i64
  %34 = getelementptr inbounds [20000200 x %struct.node], ptr @tree, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !13
  %36 = add nsw i64 %35, %32
  store i64 %36, ptr %21, align 8, !tbaa !13
  br label %common.ret45
}

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

!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 8}
!6 = !{!"_ZTS4node", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!6, !10, i64 20}
!13 = !{!6, !7, i64 0}


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