; LLVM IR from tangjz/acm-icpc :: hdu/5536.ll (Z6changeii)

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

%struct.Trie = type { i32, [2 x i32] }

@tot = external dso_local global i32, align 4
@e = external dso_local global [31010 x %struct.Trie], align 16

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

8:                                                ; preds = %55, %2
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %12, label %11

11:                                               ; preds = %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %58

12:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %6, align 4, !tbaa !5
  %15 = ashr i32 %13, %14
  %16 = and i32 %15, 1
  store i32 %16, ptr %7, align 4, !tbaa !5
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %18
  %20 = getelementptr inbounds %struct.Trie, ptr %19, i32 0, i32 1
  %21 = load i32, ptr %7, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2 x i32], ptr %20, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %39, label %26

26:                                               ; preds = %12
  %27 = load i32, ptr @tot, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Trie, ptr %30, i32 0, i32 1
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2 x i32], ptr %31, i64 0, i64 %33
  store i32 %27, ptr %34, align 4, !tbaa !5
  %35 = load i32, ptr @tot, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr @tot, align 4, !tbaa !5
  %37 = sext i32 %35 to i64
  %38 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %37
  call void @_ZN4Trie5clearEv(ptr noundef nonnull align 4 dereferenceable(12) %38)
  br label %39

39:                                               ; preds = %26, %12
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %41
  %43 = getelementptr inbounds %struct.Trie, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %7, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [2 x i32], ptr %43, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  store i32 %47, ptr %5, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %50
  %52 = getelementptr inbounds %struct.Trie, ptr %51, i32 0, i32 0
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = add nsw i32 %53, %48
  store i32 %54, ptr %52, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %55

55:                                               ; preds = %39
  %56 = load i32, ptr %6, align 4, !tbaa !5
  %57 = add nsw i32 %56, -1
  store i32 %57, ptr %6, align 4, !tbaa !5
  br label %8, !llvm.loop !11

58:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Trie5clearEv(ptr noundef nonnull align 4 dereferenceable(12)) #2 align 2

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

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 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 #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, !6, i64 0}
!10 = !{!"_ZTS4Trie", !6, i64 0, !7, i64 4}
!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"

%struct.Trie = type { i32, [2 x i32] }

@tot = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local global [31010 x %struct.Trie], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6changeii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  br label %4

3:                                                ; preds = %16
  ret void

4:                                                ; preds = %2, %16
  %.014 = phi i32 [ 0, %2 ], [ %17, %16 ]
  %.01213 = phi i32 [ 30, %2 ], [ %22, %16 ]
  %5 = lshr i32 %0, %.01213
  %6 = and i32 %5, 1
  %7 = sext i32 %.014 to i64
  %8 = zext nneg i32 %6 to i64
  %9 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %7, i32 1, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not = icmp eq i32 %10, 0
  br i1 %.not, label %11, label %16

11:                                               ; preds = %4
  %12 = load i32, ptr @tot, align 4, !tbaa !5
  store i32 %12, ptr %9, align 4, !tbaa !5
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @tot, align 4, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %14
  tail call void @_ZN4Trie5clearEv(ptr noundef nonnull align 4 dereferenceable(12) %15)
  %.pre = load i32, ptr %9, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %11, %4
  %17 = phi i32 [ %.pre, %11 ], [ %10, %4 ]
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = add nsw i32 %20, %1
  store i32 %21, ptr %19, align 4, !tbaa !9
  %22 = add nsw i32 %.01213, -1
  %.not15 = icmp eq i32 %.01213, 0
  br i1 %.not15, label %3, label %4, !llvm.loop !11
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN4Trie5clearEv(ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #0 align 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" }

!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, !6, i64 0}
!10 = !{!"_ZTS4Trie", !6, i64 0, !7, i64 4}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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