; LLVM IR from facebook/redex :: libredex/DexUtil.ll (Z16merge_visibilityjj)

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

@_ZL15VISIBILITY_MASK = external hidden global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z16merge_visibilityjj(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @_ZL15VISIBILITY_MASK, align 4, !tbaa !9
  %7 = load i32, ptr %4, align 4, !tbaa !5
  %8 = and i32 %7, %6
  store i32 %8, ptr %4, align 4, !tbaa !5
  %9 = load i32, ptr @_ZL15VISIBILITY_MASK, align 4, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = and i32 %10, %9
  store i32 %11, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = and i32 %12, 1
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %19, label %15

15:                                               ; preds = %2
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = and i32 %16, 1
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %2
  store i32 1, ptr %3, align 4
  br label %37

20:                                               ; preds = %15
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %26, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %23, %20
  store i32 0, ptr %3, align 4
  br label %37

27:                                               ; preds = %23
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = and i32 %28, 4
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %35, label %31

31:                                               ; preds = %27
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = and i32 %32, 4
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %31, %27
  store i32 4, ptr %3, align 4
  br label %37

36:                                               ; preds = %31
  store i32 2, ptr %3, align 4
  br label %37

37:                                               ; preds = %36, %35, %26, %19
  %38 = load i32, ptr %3, align 4
  ret i32 %38
}

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, !10, i64 0}
!10 = !{!"_ZTS14DexAccessFlags", !7, i64 0}


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

@_ZL15VISIBILITY_MASK = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 0, 5) i32 @_Z16merge_visibilityjj(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr @_ZL15VISIBILITY_MASK, align 4, !tbaa !5
  %4 = and i32 %3, %0
  %5 = and i32 %3, %1
  %6 = or i32 %4, %5
  %7 = and i32 %6, 1
  %or.cond15 = icmp eq i32 %7, 0
  br i1 %or.cond15, label %8, label %13

8:                                                ; preds = %2
  %9 = icmp eq i32 %4, 0
  %10 = icmp eq i32 %5, 0
  %or.cond = or i1 %9, %10
  br i1 %or.cond, label %13, label %11

11:                                               ; preds = %8
  %12 = and i32 %6, 4
  %or.cond16 = icmp eq i32 %12, 0
  %spec.select = select i1 %or.cond16, i32 2, i32 4
  br label %13

13:                                               ; preds = %11, %8, %2
  %.0 = phi i32 [ 1, %2 ], [ 0, %8 ], [ %spec.select, %11 ]
  ret i32 %.0
}

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 = !{!"_ZTS14DexAccessFlags", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass