; LLVM IR from tangjz/acm-icpc :: poj (2886)

; 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
@m = external dso_local global i32, align 4
@pos = external dso_local global i32, align 4
@a = external dso_local global [524288 x i32], align 16
@ans = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@now = external dso_local global i32, align 4
@s = external dso_local global [524288 x [11 x i8]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@_ZL9antiprime = external hidden constant [36 x i32], align 16
@_ZL7anticnt = external hidden constant [36 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

; 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

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

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

4:                                                ; preds = %53, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @pos)
  %6 = icmp eq i32 %5, 2
  br i1 %6, label %7, label %60

7:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %8

8:                                                ; preds = %22, %7
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = icmp sle i32 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %25

13:                                               ; preds = %8
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [524288 x [11 x i8]], ptr @s, i64 0, i64 %15
  %17 = getelementptr inbounds [11 x i8], ptr %16, i64 0, i64 0
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @a, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %17, ptr noundef %20)
  br label %22

22:                                               ; preds = %13
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !9

25:                                               ; preds = %12
  %26 = call noundef ptr @_ZSt11upper_boundIPKiiET_S2_S2_RKT0_(ptr noundef @_ZL9antiprime, ptr noundef getelementptr inbounds (i32, ptr @_ZL9antiprime, i64 36), ptr noundef nonnull align 4 dereferenceable(4) @n)
  %27 = ptrtoint ptr %26 to i64
  %28 = sub i64 %27, ptrtoint (ptr @_ZL9antiprime to i64)
  %29 = sdiv exact i64 %28, 4
  %30 = sub nsw i64 %29, 1
  %31 = trunc i64 %30 to i32
  store i32 %31, ptr @ans, align 4, !tbaa !5
  %32 = load i32, ptr @ans, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [36 x i32], ptr @_ZL7anticnt, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr @cnt, align 4, !tbaa !5
  %36 = load i32, ptr @ans, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [36 x i32], ptr @_ZL9antiprime, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr @ans, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  call void @_Z5buildiii(i32 noundef 1, i32 noundef 1, i32 noundef %40)
  %41 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %41, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %50, %25
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  br label %53

47:                                               ; preds = %42
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = load i32, ptr @pos, align 4, !tbaa !5
  call void @_Z3updiiii(i32 noundef 1, i32 noundef 1, i32 noundef %48, i32 noundef %49)
  br label %50

50:                                               ; preds = %47
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %3, align 4, !tbaa !5
  br label %42, !llvm.loop !11

53:                                               ; preds = %46
  %54 = load i32, ptr @now, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [524288 x [11 x i8]], ptr @s, i64 0, i64 %55
  %57 = getelementptr inbounds [11 x i8], ptr %56, i64 0, i64 0
  %58 = load i32, ptr @cnt, align 4, !tbaa !5
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, ptr noundef %57, i32 noundef %58)
  br label %4, !llvm.loop !12

60:                                               ; preds = %4
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11upper_boundIPKiiET_S2_S2_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #4

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { inlinehint 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 #5 = { 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}
!12 = distinct !{!12, !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"

@n = external dso_local global i32, align 4
@m = external dso_local local_unnamed_addr global i32, align 4
@pos = external dso_local global i32, align 4
@a = external dso_local global [524288 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@now = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local global [524288 x [11 x i8]], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@_ZL9antiprime = external hidden constant [36 x i32], align 16
@_ZL7anticnt = external hidden local_unnamed_addr constant [36 x i32], align 16
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @pos)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.preheader, label %._crit_edge15

.preheader:                                       ; preds = %0, %._crit_edge14
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %.not8 = icmp slt i32 %3, 1
  br i1 %.not8, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %4 = tail call noundef ptr @_ZSt11upper_boundIPKiiET_S2_S2_RKT0_(ptr noundef nonnull @_ZL9antiprime, ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZL9antiprime, i64 144), ptr noundef nonnull align 4 dereferenceable(4) @n)
  %5 = ptrtoint ptr %4 to i64
  %6 = sub i64 %5, ptrtoint (ptr @_ZL9antiprime to i64)
  %7 = shl i64 %6, 30
  %sext = add i64 %7, -4294967296
  %8 = ashr i64 %sext, 32
  %9 = getelementptr inbounds [36 x i32], ptr @_ZL7anticnt, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %10, ptr @cnt, align 4, !tbaa !5
  %11 = getelementptr inbounds [36 x i32], ptr @_ZL9antiprime, i64 0, i64 %8
  %12 = load i32, ptr %11, align 4, !tbaa !5
  store i32 %12, ptr @ans, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  tail call void @_Z5buildiii(i32 noundef 1, i32 noundef 1, i32 noundef %13)
  %14 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %14, ptr @m, align 4, !tbaa !5
  %15 = load i32, ptr @ans, align 4, !tbaa !5
  %.not710 = icmp slt i32 %15, 1
  br i1 %.not710, label %._crit_edge14, label %.lr.ph13

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader ]
  %16 = getelementptr inbounds [524288 x [11 x i8]], ptr @s, i64 0, i64 %indvars.iv
  %17 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %18 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %16, ptr noundef nonnull %17)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %.not.not = icmp slt i64 %indvars.iv, %20
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge14:                                    ; preds = %.lr.ph13, %._crit_edge
  %21 = load i32, ptr @now, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [524288 x [11 x i8]], ptr @s, i64 0, i64 %22
  %24 = load i32, ptr @cnt, align 4, !tbaa !5
  %25 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, ptr noundef nonnull %23, i32 noundef %24)
  %26 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @pos)
  %27 = icmp eq i32 %26, 2
  br i1 %27, label %.preheader, label %._crit_edge15, !llvm.loop !11

.lr.ph13:                                         ; preds = %._crit_edge, %.lr.ph13
  %.011 = phi i32 [ %30, %.lr.ph13 ], [ 1, %._crit_edge ]
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = load i32, ptr @pos, align 4, !tbaa !5
  tail call void @_Z3updiiii(i32 noundef 1, i32 noundef 1, i32 noundef %28, i32 noundef %29)
  %30 = add nuw nsw i32 %.011, 1
  %31 = load i32, ptr @ans, align 4, !tbaa !5
  %.not7.not = icmp slt i32 %.011, %31
  br i1 %.not7.not, label %.lr.ph13, label %._crit_edge14, !llvm.loop !12

._crit_edge15:                                    ; preds = %._crit_edge14, %0
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11upper_boundIPKiiET_S2_S2_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

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" }
attributes #1 = { 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 #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 = { inlinehint 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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass