; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions (AMZSEQ)

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

@a = external dso_local global [3 x i32], align 4
@p = external dso_local global [3 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %4

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

8:                                                ; preds = %4
  %9 = load i32, ptr @p, align 4, !tbaa !5
  %10 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 1), align 4, !tbaa !5
  %11 = add nsw i32 %9, %10
  store i32 %11, ptr @a, align 4, !tbaa !5
  %12 = load i32, ptr @p, align 4, !tbaa !5
  %13 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 1), align 4, !tbaa !5
  %14 = add nsw i32 %12, %13
  %15 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 2), align 4, !tbaa !5
  %16 = add nsw i32 %14, %15
  store i32 %16, ptr getelementptr inbounds ([3 x i32], ptr @a, i64 0, i64 1), align 4, !tbaa !5
  %17 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 1), align 4, !tbaa !5
  %18 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 2), align 4, !tbaa !5
  %19 = add nsw i32 %17, %18
  store i32 %19, ptr getelementptr inbounds ([3 x i32], ptr @a, i64 0, i64 2), align 4, !tbaa !5
  %20 = load i32, ptr @a, align 4, !tbaa !5
  store i32 %20, ptr @p, align 4, !tbaa !5
  %21 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @a, i64 0, i64 1), align 4, !tbaa !5
  store i32 %21, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 1), align 4, !tbaa !5
  %22 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @a, i64 0, i64 2), align 4, !tbaa !5
  store i32 %22, ptr getelementptr inbounds ([3 x i32], ptr @p, i64 0, i64 2), align 4, !tbaa !5
  br label %4, !llvm.loop !9

23:                                               ; preds = %4
  %24 = load i32, ptr @a, align 4, !tbaa !5
  %25 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @a, i64 0, i64 1), align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  %27 = load i32, ptr getelementptr inbounds ([3 x i32], ptr @a, i64 0, i64 2), align 4, !tbaa !5
  %28 = add nsw i32 %26, %27
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %28)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  ret i32 0
}

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

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

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

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

attributes #0 = { 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 = { "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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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

@a = external dso_local local_unnamed_addr global [3 x i32], align 4
@p = external dso_local local_unnamed_addr global [3 x i32], align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %.promoted = load i32, ptr %1, align 4, !tbaa !5
  %3 = add nsw i32 %.promoted, -1
  %.not3 = icmp eq i32 %3, 0
  br i1 %.not3, label %._crit_edge14, label %.lr.ph.preheader

._crit_edge14:                                    ; preds = %0
  %.pre = load i32, ptr @a, align 4, !tbaa !5
  %.pre15 = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4, !tbaa !5
  %.pre16 = load i32, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 4, !tbaa !5
  br label %31

.lr.ph.preheader:                                 ; preds = %0
  %.promoted2 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 8), align 4, !tbaa !5
  %.promoted1 = load i32, ptr getelementptr inbounds (i8, ptr @p, i64 4), align 4, !tbaa !5
  %p.promoted = load i32, ptr @p, align 4, !tbaa !5
  %4 = add i32 %.promoted, -2
  %xtraiter = and i32 %3, 3
  %lcmp.mod.not = icmp eq i32 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol

.lr.ph.prol:                                      ; preds = %.lr.ph.preheader, %.lr.ph.prol
  %5 = phi i32 [ %12, %.lr.ph.prol ], [ %3, %.lr.ph.preheader ]
  %6 = phi i32 [ %9, %.lr.ph.prol ], [ %p.promoted, %.lr.ph.preheader ]
  %7 = phi i32 [ %10, %.lr.ph.prol ], [ %.promoted1, %.lr.ph.preheader ]
  %8 = phi i32 [ %11, %.lr.ph.prol ], [ %.promoted2, %.lr.ph.preheader ]
  %prol.iter = phi i32 [ %prol.iter.next, %.lr.ph.prol ], [ 0, %.lr.ph.preheader ]
  %9 = add nsw i32 %7, %6
  %10 = add nsw i32 %8, %9
  %11 = add nsw i32 %8, %7
  %12 = add nsw i32 %5, -1
  %prol.iter.next = add i32 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i32 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph.prol.loopexit, label %.lr.ph.prol, !llvm.loop !9

.lr.ph.prol.loopexit:                             ; preds = %.lr.ph.prol, %.lr.ph.preheader
  %.lcssa22.unr = phi i32 [ poison, %.lr.ph.preheader ], [ %9, %.lr.ph.prol ]
  %.lcssa21.unr = phi i32 [ poison, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %.lcssa.unr = phi i32 [ poison, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %.unr = phi i32 [ %3, %.lr.ph.preheader ], [ %12, %.lr.ph.prol ]
  %.unr23 = phi i32 [ %p.promoted, %.lr.ph.preheader ], [ %9, %.lr.ph.prol ]
  %.unr24 = phi i32 [ %.promoted1, %.lr.ph.preheader ], [ %10, %.lr.ph.prol ]
  %.unr25 = phi i32 [ %.promoted2, %.lr.ph.preheader ], [ %11, %.lr.ph.prol ]
  %13 = icmp ult i32 %4, 3
  br i1 %13, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.prol.loopexit, %.lr.ph
  %14 = phi i32 [ %30, %.lr.ph ], [ %.unr, %.lr.ph.prol.loopexit ]
  %15 = phi i32 [ %27, %.lr.ph ], [ %.unr23, %.lr.ph.prol.loopexit ]
  %16 = phi i32 [ %28, %.lr.ph ], [ %.unr24, %.lr.ph.prol.loopexit ]
  %17 = phi i32 [ %29, %.lr.ph ], [ %.unr25, %.lr.ph.prol.loopexit ]
  %18 = add nsw i32 %16, %15
  %19 = add nsw i32 %17, %18
  %20 = add nsw i32 %17, %16
  %21 = add nsw i32 %19, %18
  %22 = add nsw i32 %20, %21
  %23 = add nsw i32 %20, %19
  %24 = add nsw i32 %22, %21
  %25 = add nsw i32 %23, %24
  %26 = add nsw i32 %23, %22
  %27 = add nsw i32 %25, %24
  %28 = add nsw i32 %26, %27
  %29 = add nsw i32 %26, %25
  %30 = add nsw i32 %14, -4
  %.not.3 = icmp eq i32 %30, 0
  br i1 %.not.3, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph.prol.loopexit
  %.lcssa22 = phi i32 [ %.lcssa22.unr, %.lr.ph.prol.loopexit ], [ %27, %.lr.ph ]
  %.lcssa21 = phi i32 [ %.lcssa21.unr, %.lr.ph.prol.loopexit ], [ %28, %.lr.ph ]
  %.lcssa = phi i32 [ %.lcssa.unr, %.lr.ph.prol.loopexit ], [ %29, %.lr.ph ]
  store i32 %.lcssa22, ptr @a, align 4, !tbaa !5
  store i32 %.lcssa21, ptr getelementptr inbounds (i8, ptr @a, i64 4), align 4, !tbaa !5
  store i32 %.lcssa, ptr getelementptr inbounds (i8, ptr @a, i64 8), align 4, !tbaa !5
  store i32 %.lcssa22, ptr @p, align 4, !tbaa !5
  store i32 %.lcssa21, ptr getelementptr inbounds (i8, ptr @p, i64 4), align 4, !tbaa !5
  store i32 %.lcssa, ptr getelementptr inbounds (i8, ptr @p, i64 8), align 4, !tbaa !5
  br label %31

31:                                               ; preds = %._crit_edge14, %._crit_edge
  %32 = phi i32 [ %.pre16, %._crit_edge14 ], [ %.lcssa, %._crit_edge ]
  %33 = phi i32 [ %.pre15, %._crit_edge14 ], [ %.lcssa21, %._crit_edge ]
  %34 = phi i32 [ %.pre, %._crit_edge14 ], [ %.lcssa22, %._crit_edge ]
  store i32 0, ptr %1, align 4, !tbaa !5
  %35 = add nsw i32 %33, %34
  %36 = add nsw i32 %35, %32
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %36)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret i32 0
}

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

; 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

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

attributes #0 = { nofree 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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