; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/SHORT/COOK65/Problem E/brute.ll (Z6getansiii)

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

@n = external dso_local global i32, align 4
@qs = external dso_local global i32, align 4
@qe = external dso_local global i32, align 4
@_ZL1p = external hidden global [100010 x i32], align 16
@_ZL2wc = external hidden global [100010 x i32], align 16
@_ZL3pos = external hidden global [100010 x i32], align 16
@_ZL5chain = external hidden global [100010 x i32], align 16

; 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 noundef i32 @_Z2quiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

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

9:                                                ; preds = %35, %3
  br label %10

10:                                               ; preds = %9
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = load i32, ptr %5, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  %19 = icmp eq i32 %14, %18
  br i1 %19, label %20, label %35

20:                                               ; preds = %10
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %24, %25
  store i32 %26, ptr @qs, align 4, !tbaa !5
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  store i32 %30, ptr @qe, align 4, !tbaa !5
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %32 = call noundef i32 @_Z2quiiii(i32 noundef 1, i32 noundef %31, i32 noundef 1, i32 noundef 0)
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %7, align 4, !tbaa !5
  br label %59

35:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [100010 x i32], ptr @_ZL5chain, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  store i32 %42, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  store i32 %46, ptr @qs, align 4, !tbaa !5
  %47 = load i32, ptr %4, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  store i32 %50, ptr @qe, align 4, !tbaa !5
  %51 = load i32, ptr @n, align 4, !tbaa !5
  %52 = call noundef i32 @_Z2quiiii(i32 noundef 1, i32 noundef %51, i32 noundef 1, i32 noundef 0)
  %53 = load i32, ptr %7, align 4, !tbaa !5
  %54 = add nsw i32 %53, %52
  store i32 %54, ptr %7, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  store i32 %58, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %9, !llvm.loop !9

59:                                               ; preds = %20
  %60 = load i32, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  ret i32 %60
}

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 = { 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"}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@qs = external dso_local local_unnamed_addr global i32, align 4
@qe = external dso_local local_unnamed_addr global i32, align 4
@_ZL1p = external hidden local_unnamed_addr global [100010 x i32], align 16
@_ZL2wc = external hidden local_unnamed_addr global [100010 x i32], align 16
@_ZL3pos = external hidden local_unnamed_addr global [100010 x i32], align 16
@_ZL5chain = external hidden local_unnamed_addr global [100010 x i32], align 16

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z2quiiii(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z6getansiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %4
  %6 = sext i32 %0 to i64
  %7 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp eq i32 %8, %9
  br i1 %10, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.012.lcssa = phi i32 [ 0, %3 ], [ %31, %.lr.ph ]
  %.lcssa14 = phi i64 [ %6, %3 ], [ %34, %.lr.ph ]
  %11 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %4
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = add nsw i32 %12, %2
  store i32 %13, ptr @qs, align 4, !tbaa !5
  %14 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %.lcssa14
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr @qe, align 4, !tbaa !5
  %16 = load i32, ptr @n, align 4, !tbaa !5
  %17 = tail call noundef i32 @_Z2quiiii(i32 noundef 1, i32 noundef %16, i32 noundef 1, i32 noundef 0)
  %18 = add nsw i32 %17, %.012.lcssa
  ret i32 %18

.lr.ph:                                           ; preds = %3, %.lr.ph
  %19 = phi i32 [ %36, %.lr.ph ], [ %8, %3 ]
  %20 = phi i64 [ %34, %.lr.ph ], [ %6, %3 ]
  %.01215 = phi i32 [ %31, %.lr.ph ], [ 0, %3 ]
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [100010 x i32], ptr @_ZL5chain, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr @qs, align 4, !tbaa !5
  %27 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %20
  %28 = load i32, ptr %27, align 4, !tbaa !5
  store i32 %28, ptr @qe, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = tail call noundef i32 @_Z2quiiii(i32 noundef 1, i32 noundef %29, i32 noundef 1, i32 noundef 0)
  %31 = add nsw i32 %30, %.01215
  %32 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %24
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = icmp eq i32 %36, %37
  br i1 %38, label %._crit_edge, label %.lr.ph, !llvm.loop !9
}

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

!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"}


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