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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7updateriii(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 = %32, %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 %32

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
  call void @_Z2upiii(i32 noundef 1, i32 noundef %31, i32 noundef 1)
  br label %53

32:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %33 = load i32, ptr %4, 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 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100010 x i32], ptr @_ZL5chain, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr %8, align 4, !tbaa !5
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  store i32 %43, ptr @qs, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr @qe, align 4, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z2upiii(i32 noundef 1, i32 noundef %48, i32 noundef 1)
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  store i32 %52, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %9, !llvm.loop !9

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

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 void @_Z2upiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7updateriii(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
  %.lcssa11 = phi i64 [ %6, %3 ], [ %30, %.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 %.lcssa11
  %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
  tail call void @_Z2upiii(i32 noundef 1, i32 noundef %16, i32 noundef 1)
  ret i32 0

.lr.ph:                                           ; preds = %3, %.lr.ph
  %17 = phi i32 [ %32, %.lr.ph ], [ %8, %3 ]
  %18 = phi i64 [ %30, %.lr.ph ], [ %6, %3 ]
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [100010 x i32], ptr @_ZL5chain, i64 0, i64 %19
  %21 = load i32, ptr %20, 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
  store i32 %24, ptr @qs, align 4, !tbaa !5
  %25 = getelementptr inbounds [100010 x i32], ptr @_ZL3pos, i64 0, i64 %18
  %26 = load i32, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr @qe, align 4, !tbaa !5
  %27 = load i32, ptr @n, align 4, !tbaa !5
  tail call void @_Z2upiii(i32 noundef 1, i32 noundef %27, i32 noundef 1)
  %28 = getelementptr inbounds [100010 x i32], ptr @_ZL1p, i64 0, i64 %22
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [100010 x i32], ptr @_ZL2wc, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr %5, align 4, !tbaa !5
  %34 = icmp eq i32 %32, %33
  br i1 %34, 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,SROAPass,SimplifyCFGPass,TailCallElimPass