; LLVM IR from tangjz/acm-icpc :: spoj/HC10000.ll (Z7preparev)

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

@bin = external dso_local global [61 x [61 x i64]], align 16
@a = external dso_local global [61 x [61 x i32]], align 16
@b = external dso_local global [61 x [61 x i32]], align 16
@c = external dso_local global [61 x [61 x i32]], align 16
@sb = external dso_local global [61 x [61 x i32]], align 16
@sc = external dso_local global [61 x [61 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z7preparev() #0 {
  %1 = alloca i32, align 4
  call void @llvm.memset.p0.i64(ptr align 16 @bin, i8 -1, i64 29768, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @a, i8 -1, i64 14884, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @b, i8 -1, i64 14884, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @c, i8 -1, i64 14884, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @sb, i8 -1, i64 14884, i1 false)
  call void @llvm.memset.p0.i64(ptr align 16 @sc, i8 -1, i64 14884, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  store i32 0, ptr %1, align 4, !tbaa !5
  br label %2

2:                                                ; preds = %52, %0
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp slt i32 %3, 61
  br i1 %4, label %6, label %5

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

6:                                                ; preds = %2
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [61 x [61 x i64]], ptr @bin, i64 0, i64 %8
  %10 = load i32, ptr %1, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [61 x i64], ptr %9, i64 0, i64 %11
  store i64 1, ptr %12, align 8, !tbaa !9
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [61 x [61 x i64]], ptr @bin, i64 0, i64 %14
  %16 = getelementptr inbounds [61 x i64], ptr %15, i64 0, i64 0
  store i64 1, ptr %16, align 8, !tbaa !9
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [61 x [61 x i32]], ptr @b, i64 0, i64 %18
  %20 = load i32, ptr %1, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [61 x i32], ptr %19, i64 0, i64 %21
  store i32 1, ptr %22, align 4, !tbaa !5
  %23 = load i32, ptr %1, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [61 x [61 x i32]], ptr @b, i64 0, i64 %24
  %26 = getelementptr inbounds [61 x i32], ptr %25, i64 0, i64 0
  store i32 1, ptr %26, align 4, !tbaa !5
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [61 x [61 x i32]], ptr @a, i64 0, i64 %28
  %30 = getelementptr inbounds [61 x i32], ptr %29, i64 0, i64 0
  store i32 1, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [61 x [61 x i32]], ptr @a, i64 0, i64 %32
  %34 = load i32, ptr %1, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [61 x i32], ptr %33, i64 0, i64 %35
  store i32 0, ptr %36, align 4, !tbaa !5
  %37 = load i32, ptr %1, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [61 x [61 x i32]], ptr @sb, i64 0, i64 %38
  %40 = getelementptr inbounds [61 x i32], ptr %39, i64 0, i64 0
  store i32 0, ptr %40, align 4, !tbaa !5
  %41 = load i32, ptr %1, align 4, !tbaa !5
  %42 = zext i32 %41 to i64
  %43 = shl i64 1, %42
  %44 = srem i64 %43, 1000000000
  %45 = trunc i64 %44 to i32
  %46 = load i32, ptr %1, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [61 x [61 x i32]], ptr @c, i64 0, i64 %47
  %49 = load i32, ptr %1, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [61 x i32], ptr %48, i64 0, i64 %50
  store i32 %45, ptr %51, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %6
  %53 = load i32, ptr %1, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %1, align 4, !tbaa !5
  br label %2, !llvm.loop !11

55:                                               ; preds = %5
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long long", !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"

@bin = external dso_local local_unnamed_addr global [61 x [61 x i64]], align 16
@a = external dso_local local_unnamed_addr global [61 x [61 x i32]], align 16
@b = external dso_local local_unnamed_addr global [61 x [61 x i32]], align 16
@c = external dso_local local_unnamed_addr global [61 x [61 x i32]], align 16
@sb = external dso_local local_unnamed_addr global [61 x [61 x i32]], align 16
@sc = external dso_local local_unnamed_addr global [61 x [61 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z7preparev() local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(29768) @bin, i8 -1, i64 29768, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(14884) @a, i8 -1, i64 14884, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(14884) @b, i8 -1, i64 14884, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(14884) @c, i8 -1, i64 14884, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(14884) @sb, i8 -1, i64 14884, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(14884) @sc, i8 -1, i64 14884, i1 false)
  br label %2

1:                                                ; preds = %2
  ret void

2:                                                ; preds = %0, %2
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %2 ]
  %3 = getelementptr inbounds [61 x [61 x i64]], ptr @bin, i64 0, i64 %indvars.iv
  %4 = getelementptr inbounds [61 x [61 x i64]], ptr @bin, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i64 1, ptr %4, align 8, !tbaa !5
  store i64 1, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds [61 x [61 x i32]], ptr @b, i64 0, i64 %indvars.iv
  %6 = getelementptr inbounds [61 x [61 x i32]], ptr @b, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 1, ptr %6, align 4, !tbaa !9
  store i32 1, ptr %5, align 4, !tbaa !9
  %7 = getelementptr inbounds [61 x [61 x i32]], ptr @a, i64 0, i64 %indvars.iv
  store i32 1, ptr %7, align 4, !tbaa !9
  %8 = getelementptr inbounds [61 x [61 x i32]], ptr @a, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 0, ptr %8, align 4, !tbaa !9
  %9 = getelementptr inbounds [61 x [61 x i32]], ptr @sb, i64 0, i64 %indvars.iv
  store i32 0, ptr %9, align 4, !tbaa !9
  %10 = shl nuw nsw i64 1, %indvars.iv
  %11 = urem i64 %10, 1000000000
  %12 = trunc nuw nsw i64 %11 to i32
  %13 = getelementptr inbounds [61 x [61 x i32]], ptr @c, i64 0, i64 %indvars.iv, i64 %indvars.iv
  store i32 %12, ptr %13, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 61
  br i1 %exitcond.not, label %1, label %2, !llvm.loop !11
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(write, 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" }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass