; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions/NBIN.ll (Z3prev)

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

@pre_com = external dso_local global [100 x i64], align 16
@p = external dso_local global [100 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3prev() #0 {
  %1 = alloca i32, align 4
  store i64 1, ptr getelementptr inbounds ([100 x i64], ptr @pre_com, i64 0, i64 1), align 8, !tbaa !5
  store i64 2, ptr getelementptr inbounds ([100 x i64], ptr @pre_com, i64 0, i64 2), align 16, !tbaa !5
  store i64 4, ptr getelementptr inbounds ([100 x i64], ptr @pre_com, i64 0, i64 3), align 8, !tbaa !5
  store i64 7, ptr getelementptr inbounds ([100 x i64], ptr @pre_com, i64 0, i64 4), align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 4, ptr %1, align 4, !tbaa !9
  br label %2

2:                                                ; preds = %8, %0
  %3 = load i32, ptr %1, align 4, !tbaa !9
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [100 x i64], ptr @pre_com, i64 0, i64 %4
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp sle i64 %6, 1000000000000000
  br i1 %7, label %8, label %35

8:                                                ; preds = %2
  %9 = load i32, ptr %1, align 4, !tbaa !9
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr %1, align 4, !tbaa !9
  %11 = load i32, ptr %1, align 4, !tbaa !9
  %12 = sub nsw i32 %11, 2
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [100 x i64], ptr @p, i64 0, i64 %13
  %15 = load i64, ptr %14, align 8, !tbaa !5
  %16 = add nsw i64 %15, 1
  %17 = load i32, ptr %1, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100 x i64], ptr @p, i64 0, i64 %18
  store i64 %16, ptr %19, align 8, !tbaa !5
  %20 = load i32, ptr %1, align 4, !tbaa !9
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100 x i64], ptr @pre_com, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !5
  %25 = load i32, ptr %1, align 4, !tbaa !9
  %26 = sub nsw i32 %25, 2
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [100 x i64], ptr @pre_com, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = add nsw i64 %24, %29
  %31 = add nsw i64 %30, 1
  %32 = load i32, ptr %1, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [100 x i64], ptr @pre_com, i64 0, i64 %33
  store i64 %31, ptr %34, align 8, !tbaa !5
  br label %2, !llvm.loop !11

35:                                               ; preds = %2
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret void
}

; 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

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

@pre_com = external dso_local local_unnamed_addr global [100 x i64], align 16
@p = external dso_local local_unnamed_addr global [100 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3prev() local_unnamed_addr #0 {
.lr.ph.preheader:
  store i64 1, ptr getelementptr inbounds (i8, ptr @pre_com, i64 8), align 8, !tbaa !5
  store i64 2, ptr getelementptr inbounds (i8, ptr @pre_com, i64 16), align 16, !tbaa !5
  store i64 4, ptr getelementptr inbounds (i8, ptr @pre_com, i64 24), align 8, !tbaa !5
  store i64 7, ptr getelementptr inbounds (i8, ptr @pre_com, i64 32), align 16, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 4, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %0 = phi i64 [ 7, %.lr.ph.preheader ], [ %9, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %1 = add nsw i64 %indvars.iv, -1
  %2 = getelementptr inbounds [100 x i64], ptr @p, i64 0, i64 %1
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = add nsw i64 %3, 1
  %5 = getelementptr inbounds [100 x i64], ptr @p, i64 0, i64 %indvars.iv.next
  store i64 %4, ptr %5, align 8, !tbaa !5
  %6 = getelementptr inbounds [100 x i64], ptr @pre_com, i64 0, i64 %1
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add nsw i64 %0, 1
  %9 = add i64 %8, %7
  %10 = getelementptr inbounds [100 x i64], ptr @pre_com, i64 0, i64 %indvars.iv.next
  store i64 %9, ptr %10, align 8, !tbaa !5
  %11 = icmp slt i64 %9, 1000000000000001
  br i1 %11, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass