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

; 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] }

@e = external dso_local global [31010 x %struct.Trie], 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 @_Z4findi(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 30, ptr %5, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %70, %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 %73

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 = xor i32 %14, -1
  %16 = and 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 [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 %6, 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 %26, label %54

26:                                               ; preds = %11
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Trie, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2 x i32], ptr %30, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.Trie, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %54

40:                                               ; preds = %26
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.Trie, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2 x i32], ptr %44, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  store i32 %48, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = load i32, ptr %5, align 4, !tbaa !5
  %51 = shl i32 %49, %50
  %52 = load i32, ptr %4, align 4, !tbaa !5
  %53 = or i32 %52, %51
  store i32 %53, ptr %4, align 4, !tbaa !5
  br label %69

54:                                               ; preds = %26, %11
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %56
  %58 = getelementptr inbounds %struct.Trie, ptr %57, i32 0, i32 1
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = xor i32 %59, 1
  store i32 %60, ptr %6, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [2 x i32], ptr %58, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  store i32 %63, ptr %3, align 4, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = shl i32 %64, %65
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = or i32 %67, %66
  store i32 %68, ptr %4, align 4, !tbaa !5
  br label %69

69:                                               ; preds = %54, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %70

70:                                               ; preds = %69
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = add nsw i32 %71, -1
  store i32 %72, ptr %5, align 4, !tbaa !5
  br label %7, !llvm.loop !11

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

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 = !{!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] }

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

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

2:                                                ; preds = %19
  ret i32 %.1

3:                                                ; preds = %1, %19
  %.027 = phi i32 [ 30, %1 ], [ %20, %19 ]
  %.01926 = phi i32 [ 0, %1 ], [ %.1, %19 ]
  %.02025 = phi i32 [ 0, %1 ], [ %.121, %19 ]
  %4 = lshr i32 %0, %.027
  %5 = and i32 %4, 1
  %6 = xor i32 %5, 1
  %7 = sext i32 %.02025 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 %15, label %11

11:                                               ; preds = %3
  %12 = sext i32 %10 to i64
  %13 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %.not23 = icmp eq i32 %14, 0
  br i1 %.not23, label %15, label %19

15:                                               ; preds = %11, %3
  %16 = zext nneg i32 %5 to i64
  %17 = getelementptr inbounds [31010 x %struct.Trie], ptr @e, i64 0, i64 %7, i32 1, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %11, %15
  %.121 = phi i32 [ %18, %15 ], [ %10, %11 ]
  %.pn24 = phi i32 [ %5, %15 ], [ %6, %11 ]
  %.pn = shl nuw i32 %.pn24, %.027
  %.1 = or i32 %.pn, %.01926
  %20 = add nsw i32 %.027, -1
  %.not28 = icmp eq i32 %.027, 0
  br i1 %.not28, label %2, label %3, !llvm.loop !11
}

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 = !{!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,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass