; LLVM IR from tangjz/acm-icpc :: hackerrank (pairwise-sum-and-divide)

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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@s = external dso_local global [2 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %30, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %46

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  store i32 0, ptr getelementptr inbounds ([2 x i32], ptr @s, i64 0, i64 1), align 4, !tbaa !5
  store i32 0, ptr @s, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %10

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

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

15:                                               ; preds = %10
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @x)
  %17 = load i32, ptr @x, align 4, !tbaa !5
  %18 = add nsw i32 %17, -1
  store i32 %18, ptr @x, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 2
  br i1 %19, label %20, label %26

20:                                               ; preds = %15
  %21 = load i32, ptr @x, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x i32], ptr @s, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %20, %15
  br label %27

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

30:                                               ; preds = %14
  %31 = load i32, ptr @s, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = sub nsw i64 %34, 1
  %36 = mul nsw i64 %32, %35
  %37 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @s, i64 0, i64 1), align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = load i32, ptr getelementptr inbounds ([2 x i32], ptr @s, i64 0, i64 1), align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = sub nsw i64 %40, 1
  %42 = mul nsw i64 %38, %41
  %43 = ashr i64 %42, 1
  %44 = add nsw i64 %36, %43
  %45 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %44)
  br label %4, !llvm.loop !11

46:                                               ; preds = %4
  ret i32 0
}

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

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

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

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

attributes #0 = { mustprogress norecurse 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !10}


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

@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@x = external dso_local global i32, align 4
@s = external dso_local local_unnamed_addr global [2 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %2 = load i32, ptr @t, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @t, align 4, !tbaa !5
  %.not5 = icmp eq i32 %2, 0
  br i1 %.not5, label %._crit_edge8, label %.lr.ph7

.lr.ph7:                                          ; preds = %0, %._crit_edge
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  store i32 0, ptr getelementptr inbounds (i8, ptr @s, i64 4), align 4, !tbaa !5
  store i32 0, ptr @s, align 4, !tbaa !5
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %30
  %.pre = load i32, ptr @s, align 4, !tbaa !5
  %.pre10 = load i32, ptr getelementptr inbounds (i8, ptr @s, i64 4), align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph7
  %7 = phi i32 [ 0, %.lr.ph7 ], [ %.pre10, %._crit_edge.loopexit ]
  %8 = phi i32 [ 0, %.lr.ph7 ], [ %.pre, %._crit_edge.loopexit ]
  %.lcssa = phi i32 [ %5, %.lr.ph7 ], [ %32, %._crit_edge.loopexit ]
  %9 = sext i32 %8 to i64
  %10 = sext i32 %.lcssa to i64
  %11 = add nsw i64 %10, -1
  %12 = mul nsw i64 %11, %9
  %13 = sext i32 %7 to i64
  %14 = add nsw i64 %13, -1
  %15 = mul nsw i64 %14, %13
  %16 = ashr i64 %15, 1
  %17 = add nsw i64 %16, %12
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %17)
  %19 = load i32, ptr @t, align 4, !tbaa !5
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge8, label %.lr.ph7, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph7, %30
  %.04 = phi i32 [ %31, %30 ], [ 0, %.lr.ph7 ]
  %21 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @x)
  %22 = load i32, ptr @x, align 4, !tbaa !5
  %23 = add nsw i32 %22, -1
  store i32 %23, ptr @x, align 4, !tbaa !5
  %24 = icmp slt i32 %22, 3
  br i1 %24, label %25, label %30

25:                                               ; preds = %.lr.ph
  %26 = sext i32 %23 to i64
  %27 = getelementptr inbounds [2 x i32], ptr @s, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %27, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %.lr.ph, %25
  %31 = add nuw nsw i32 %.04, 1
  %32 = load i32, ptr @n, align 4, !tbaa !5
  %33 = icmp slt i32 %31, %32
  br i1 %33, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !11

._crit_edge8:                                     ; preds = %._crit_edge, %0
  ret i32 0
}

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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" }

!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 = distinct !{!11, !10}


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