; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/359 Division 1/Problem C/C.ll (Z5solvev)

; 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.point = type { i64, i64, i64 }

@p = external dso_local global [100100 x %struct.point], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

; 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 uwtable
declare dso_local void @_Z5checkx(ptr dead_on_unwind noalias writable sret(%struct.point) align 8, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca %struct.point, align 8
  %6 = alloca %struct.point, align 8
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %27, %0
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp slt i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  br label %30

13:                                               ; preds = %8
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100100 x %struct.point], ptr @p, i64 0, i64 %15
  %17 = getelementptr inbounds %struct.point, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100100 x %struct.point], ptr @p, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.point, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %1, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100100 x %struct.point], ptr @p, i64 0, i64 %23
  %25 = getelementptr inbounds %struct.point, ptr %24, i32 0, i32 2
  %26 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %17, ptr noundef %21, ptr noundef %25)
  br label %27

27:                                               ; preds = %13
  %28 = load i32, ptr %1, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %1, align 4, !tbaa !5
  br label %8, !llvm.loop !9

30:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 -1, ptr %2, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 3000000000000000000, ptr %4, align 8, !tbaa !11
  br label %31

31:                                               ; preds = %51, %30
  %32 = load i64, ptr %2, align 8, !tbaa !11
  %33 = add nsw i64 %32, 1
  %34 = load i64, ptr %4, align 8, !tbaa !11
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %36, label %52

36:                                               ; preds = %31
  %37 = load i64, ptr %2, align 8, !tbaa !11
  %38 = load i64, ptr %4, align 8, !tbaa !11
  %39 = load i64, ptr %2, align 8, !tbaa !11
  %40 = sub nsw i64 %38, %39
  %41 = sdiv i64 %40, 2
  %42 = add nsw i64 %37, %41
  store i64 %42, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #3
  %43 = load i64, ptr %3, align 8, !tbaa !11
  call void @_Z5checkx(ptr dead_on_unwind writable sret(%struct.point) align 8 %5, i64 noundef %43)
  %44 = getelementptr inbounds %struct.point, ptr %5, i32 0, i32 0
  %45 = load i64, ptr %44, align 8, !tbaa !13
  %46 = icmp ne i64 %45, 3000000000000000000
  call void @llvm.lifetime.end.p0(i64 24, ptr %5) #3
  br i1 %46, label %47, label %49

47:                                               ; preds = %36
  %48 = load i64, ptr %3, align 8, !tbaa !11
  store i64 %48, ptr %4, align 8, !tbaa !11
  br label %51

49:                                               ; preds = %36
  %50 = load i64, ptr %3, align 8, !tbaa !11
  store i64 %50, ptr %2, align 8, !tbaa !11
  br label %51

51:                                               ; preds = %49, %47
  br label %31, !llvm.loop !15

52:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #3
  %53 = load i64, ptr %4, align 8, !tbaa !11
  call void @_Z5checkx(ptr dead_on_unwind writable sret(%struct.point) align 8 %6, i64 noundef %53)
  %54 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 0
  %55 = load i64, ptr %54, align 8, !tbaa !13
  %56 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !16
  %58 = getelementptr inbounds %struct.point, ptr %6, i32 0, i32 2
  %59 = load i64, ptr %58, align 8, !tbaa !17
  %60 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %55, i64 noundef %57, i64 noundef %59)
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  ret void
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

declare i32 @printf(ptr noundef, ...) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !12, i64 0}
!14 = !{!"_ZTS5point", !12, i64 0, !12, i64 8, !12, i64 16}
!15 = distinct !{!15, !10}
!16 = !{!14, !12, i64 8}
!17 = !{!14, !12, i64 16}


; 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.point = type { i64, i64, i64 }

@p = external dso_local global [100100 x %struct.point], align 16
@n = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5checkx(ptr dead_on_unwind noalias writable sret(%struct.point) align 8, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #1 {
  %1 = alloca %struct.point, align 8
  %2 = alloca %struct.point, align 8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %.preheader.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %6 = getelementptr inbounds [100100 x %struct.point], ptr @p, i64 0, i64 %indvars.iv
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = getelementptr inbounds i8, ptr %6, i64 16
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef nonnull %8)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = icmp slt i64 %indvars.iv.next, %11
  br i1 %12, label %.lr.ph, label %.preheader.preheader, !llvm.loop !9

.preheader.preheader:                             ; preds = %.lr.ph, %0
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.019 = phi i64 [ %.0., %.preheader ], [ 3000000000000000000, %.preheader.preheader ]
  %.01518 = phi i64 [ %..015, %.preheader ], [ -1, %.preheader.preheader ]
  %13 = sub nsw i64 %.019, %.01518
  %14 = sdiv i64 %13, 2
  %15 = add nsw i64 %14, %.01518
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %1) #3
  call void @_Z5checkx(ptr dead_on_unwind nonnull writable sret(%struct.point) align 8 %1, i64 noundef %15)
  %16 = load i64, ptr %1, align 8, !tbaa !11
  %.not = icmp eq i64 %16, 3000000000000000000
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %1) #3
  %..015 = select i1 %.not, i64 %15, i64 %.01518
  %.0. = select i1 %.not, i64 %.019, i64 %15
  %17 = add nsw i64 %..015, 1
  %18 = icmp slt i64 %17, %.0.
  br i1 %18, label %.preheader, label %19, !llvm.loop !14

19:                                               ; preds = %.preheader
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %2) #3
  call void @_Z5checkx(ptr dead_on_unwind nonnull writable sret(%struct.point) align 8 %2, i64 noundef %.0.)
  %20 = load i64, ptr %2, align 8, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %2, i64 8
  %22 = load i64, ptr %21, align 8, !tbaa !15
  %23 = getelementptr inbounds i8, ptr %2, i64 16
  %24 = load i64, ptr %23, align 8, !tbaa !16
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %20, i64 noundef %22, i64 noundef %24)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %2) #3
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nofree nounwind "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS5point", !13, i64 0, !13, i64 8, !13, i64 16}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !13, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass