; LLVM IR from viveakrt/Competitive-programing :: SPOJ/cot.ll (Z6updateiiii)

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z5clonei(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 @_Z6updateiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %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 i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = call noundef i32 @_Z5clonei(i32 noundef %13)
  store i32 %14, ptr %10, align 4, !tbaa !5
  %15 = load i32, ptr %10, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [6000000 x %struct.node], ptr @tree, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %26

24:                                               ; preds = %4
  %25 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %25, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %65

26:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = add nsw i32 %27, %28
  %30 = sdiv i32 %29, 2
  store i32 %30, ptr %12, align 4, !tbaa !5
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = load i32, ptr %12, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %34, label %48

34:                                               ; preds = %26
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %12, align 4, !tbaa !5
  %37 = load i32, ptr %10, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [6000000 x %struct.node], ptr @tree, i64 0, i64 %38
  %40 = getelementptr inbounds %struct.node, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !11
  %42 = load i32, ptr %9, align 4, !tbaa !5
  %43 = call noundef i32 @_Z6updateiiii(i32 noundef %35, i32 noundef %36, i32 noundef %41, i32 noundef %42)
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [6000000 x %struct.node], ptr @tree, i64 0, i64 %45
  %47 = getelementptr inbounds %struct.node, ptr %46, i32 0, i32 1
  store i32 %43, ptr %47, align 4, !tbaa !11
  br label %63

48:                                               ; preds = %26
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %10, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [6000000 x %struct.node], ptr @tree, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.node, ptr %54, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !12
  %57 = load i32, ptr %9, align 4, !tbaa !5
  %58 = call noundef i32 @_Z6updateiiii(i32 noundef %50, i32 noundef %51, i32 noundef %56, i32 noundef %57)
  %59 = load i32, ptr %10, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [6000000 x %struct.node], ptr @tree, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 2
  store i32 %58, ptr %62, align 4, !tbaa !12
  br label %63

63:                                               ; preds = %48, %34
  %64 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %64, ptr %5, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %65

65:                                               ; preds = %63, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %66 = load i32, ptr %5, align 4
  ret i32 %66
}

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

@tree = external dso_local local_unnamed_addr global [6000000 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
define dso_local noundef i32 @_Z6updateiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call noundef i32 @_Z5clonei(i32 noundef %2)
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [6000000 x %struct.node], ptr @tree, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !5
  %10 = icmp eq i32 %0, %1
  br i1 %10, label %common.ret25, label %11

11:                                               ; preds = %4
  %12 = add nsw i32 %1, %0
  %13 = sdiv i32 %12, 2
  %.not = icmp slt i32 %13, %3
  br i1 %.not, label %18, label %14

common.ret25:                                     ; preds = %4, %18, %14
  %common.ret25.op = phi i32 [ %5, %14 ], [ %5, %18 ], [ %5, %4 ]
  ret i32 %common.ret25.op

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %7, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = tail call noundef i32 @_Z6updateiiii(i32 noundef %0, i32 noundef %13, i32 noundef %16, i32 noundef %3)
  store i32 %17, ptr %15, align 4, !tbaa !10
  br label %common.ret25

18:                                               ; preds = %11
  %19 = add nsw i32 %13, 1
  %20 = getelementptr inbounds i8, ptr %7, i64 8
  %21 = load i32, ptr %20, align 4, !tbaa !11
  %22 = tail call noundef i32 @_Z6updateiiii(i32 noundef %19, i32 noundef %1, i32 noundef %21, i32 noundef %3)
  store i32 %22, ptr %20, align 4, !tbaa !11
  br label %common.ret25
}

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


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