; LLVM IR from tangjz/acm-icpc :: projecteuler (4)

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

@tot = external dso_local global i32, align 4
@a = external dso_local global [1000001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z10palindromei(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 norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 100, ptr %2, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %33, %0
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = icmp slt i32 %7, 1000
  br i1 %8, label %10, label %9

9:                                                ; preds = %6
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %36

10:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 100, ptr %4, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %29, %10
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 1000
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %32

15:                                               ; preds = %11
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = mul nsw i32 %16, %17
  %19 = call noundef zeroext i1 @_Z10palindromei(i32 noundef %18)
  br i1 %19, label %20, label %28

20:                                               ; preds = %15
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = mul nsw i32 %21, %22
  %24 = load i32, ptr @tot, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @tot, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [1000001 x i32], ptr @a, i64 0, i64 %26
  store i32 %23, ptr %27, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %20, %15
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %4, align 4, !tbaa !5
  br label %11, !llvm.loop !9

32:                                               ; preds = %14
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !11

36:                                               ; preds = %9
  %37 = load i32, ptr @tot, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds i32, ptr @a, i64 %38
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %39)
  %40 = load i32, ptr @tot, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @a, i64 %41
  %43 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @a, ptr noundef %42)
  %44 = ptrtoint ptr %43 to i64
  %45 = sub i64 %44, ptrtoint (ptr @a to i64)
  %46 = sdiv exact i64 %45, 4
  %47 = trunc i64 %46 to i32
  store i32 %47, ptr @tot, align 4, !tbaa !5
  %48 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %49

49:                                               ; preds = %53, %36
  %50 = load i32, ptr @t, align 4, !tbaa !5
  %51 = add nsw i32 %50, -1
  store i32 %51, ptr @t, align 4, !tbaa !5
  %52 = icmp ne i32 %50, 0
  br i1 %52, label %53, label %64

53:                                               ; preds = %49
  %54 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %55 = load i32, ptr @tot, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr @a, i64 %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !5
  %60 = call noundef ptr @_ZSt11upper_boundIPiiET_S1_S1_RKT0_(ptr noundef @a, ptr noundef %57, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %61 = getelementptr inbounds i32, ptr %60, i64 -1
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %62)
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %49, !llvm.loop !12

64:                                               ; preds = %49
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) #3

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11upper_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #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 = { 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 #4 = { "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"

@tot = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global [1000001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global 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: mustprogress uwtable
declare dso_local noundef zeroext i1 @_Z10palindromei(i32 noundef) local_unnamed_addr #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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  br label %.preheader

.preheader:                                       ; preds = %0, %17
  %.0810 = phi i32 [ 100, %0 ], [ %18, %17 ]
  br label %19

2:                                                ; preds = %17
  %3 = load i32, ptr @tot, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds i32, ptr @a, i64 %4
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %5)
  %6 = load i32, ptr @tot, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds i32, ptr @a, i64 %7
  %9 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %8)
  %10 = ptrtoint ptr %9 to i64
  %11 = sub i64 %10, ptrtoint (ptr @a to i64)
  %12 = lshr exact i64 %11, 2
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr @tot, align 4, !tbaa !5
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %15 = load i32, ptr @t, align 4, !tbaa !5
  %16 = add nsw i32 %15, -1
  store i32 %16, ptr @t, align 4, !tbaa !5
  %.not11 = icmp eq i32 %15, 0
  br i1 %.not11, label %._crit_edge, label %.lr.ph

17:                                               ; preds = %27
  %18 = add nuw nsw i32 %.0810, 1
  %exitcond12.not = icmp eq i32 %18, 1000
  br i1 %exitcond12.not, label %2, label %.preheader, !llvm.loop !9

19:                                               ; preds = %.preheader, %27
  %.09 = phi i32 [ 100, %.preheader ], [ %28, %27 ]
  %20 = mul nuw nsw i32 %.09, %.0810
  %21 = tail call noundef zeroext i1 @_Z10palindromei(i32 noundef %20)
  br i1 %21, label %22, label %27

22:                                               ; preds = %19
  %23 = load i32, ptr @tot, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr @tot, align 4, !tbaa !5
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds [1000001 x i32], ptr @a, i64 0, i64 %25
  store i32 %20, ptr %26, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %19, %22
  %28 = add nuw nsw i32 %.09, 1
  %exitcond.not = icmp eq i32 %28, 1000
  br i1 %exitcond.not, label %17, label %19, !llvm.loop !11

.lr.ph:                                           ; preds = %2, %.lr.ph
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %30 = load i32, ptr @tot, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds i32, ptr @a, i64 %31
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %1, align 4, !tbaa !5
  %35 = call noundef ptr @_ZSt11upper_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @a, ptr noundef nonnull %32, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %36 = getelementptr inbounds i8, ptr %35, i64 -4
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %37)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %39 = load i32, ptr @t, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %39, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %2
  ret i32 0
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt11upper_boundIPiiET_S1_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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 = { mustprogress 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 = { 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 #4 = { 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 #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}


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