; LLVM IR from CZWin32768/ACMICPC-Templates-in-Latex :: atl/codes/Tree/LvTrie.ll (Z1fi)

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

@chd = external dso_local global [32000160 x [2 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 nounwind uwtable
define dso_local noundef i32 @_Z1fi(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 31, ptr %5, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %41, %1
  %8 = load i32, ptr %5, align 4, !tbaa !5
  %9 = icmp sge i32 %8, 0
  br i1 %9, label %11, label %10

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

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

25:                                               ; preds = %11
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = xor i32 %26, 1
  store i32 %27, ptr %6, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %25, %11
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %30
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2 x i32], ptr %31, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %3, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = shl i32 %36, 1
  store i32 %37, ptr %4, align 4, !tbaa !5
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = or i32 %39, %38
  store i32 %40, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %41

41:                                               ; preds = %28
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = add nsw i32 %42, -1
  store i32 %43, ptr %5, align 4, !tbaa !5
  br label %7, !llvm.loop !9

44:                                               ; preds = %10
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = xor i32 %45, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %47
}

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

@chd = external dso_local local_unnamed_addr global [32000160 x [2 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z1fi(i32 noundef %0) local_unnamed_addr #0 {
  br label %4

2:                                                ; preds = %4
  %3 = xor i32 %31, %0
  ret i32 %3

4:                                                ; preds = %4, %1
  %.01419 = phi i32 [ 31, %1 ], [ %32, %4 ]
  %.01518 = phi i32 [ 0, %1 ], [ %31, %4 ]
  %.01617 = phi i32 [ 0, %1 ], [ %27, %4 ]
  %5 = lshr i32 %0, %.01419
  %6 = and i32 %5, 1
  %7 = xor i32 %6, 1
  %8 = sext i32 %.01617 to i64
  %9 = zext nneg i32 %7 to i64
  %10 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %8, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = icmp eq i32 %11, -1
  %spec.select = select i1 %12, i32 %6, i32 %7
  %13 = zext nneg i32 %spec.select to i64
  %14 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %8, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = add nsw i32 %.01419, -1
  %17 = lshr i32 %0, %16
  %18 = and i32 %17, 1
  %19 = xor i32 %18, 1
  %20 = sext i32 %15 to i64
  %21 = zext nneg i32 %19 to i64
  %22 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %20, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %24 = icmp eq i32 %23, -1
  %spec.select.1 = select i1 %24, i32 %18, i32 %19
  %25 = zext nneg i32 %spec.select.1 to i64
  %26 = getelementptr inbounds [32000160 x [2 x i32]], ptr @chd, i64 0, i64 %20, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = shl i32 %.01518, 2
  %29 = shl nuw nsw i32 %spec.select, 1
  %30 = or disjoint i32 %28, %29
  %31 = or disjoint i32 %spec.select.1, %30
  %32 = add nsw i32 %.01419, -2
  %.not.1 = icmp eq i32 %16, 0
  br i1 %.not.1, label %2, label %4, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, 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" }

!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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass