; LLVM IR from tangjz/acm-icpc :: lydsy/4809.ll (Z3dfsiiii)

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

@n = external dso_local global i32, align 4
@ban = external dso_local global [17 x i32], align 16
@ans = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3dfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = icmp eq i32 %11, %12
  br i1 %13, label %14, label %17

14:                                               ; preds = %4
  %15 = load i32, ptr @ans, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @ans, align 4, !tbaa !5
  br label %58

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [17 x i32], ptr @ban, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = or i32 %21, %22
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = or i32 %23, %24
  %26 = load i32, ptr %8, align 4, !tbaa !5
  %27 = or i32 %25, %26
  %28 = xor i32 %27, -1
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = shl i32 1, %29
  %31 = sub nsw i32 %30, 1
  %32 = and i32 %28, %31
  store i32 %32, ptr %9, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %36, %17
  %34 = load i32, ptr %9, align 4, !tbaa !5
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %36, label %57

36:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = sub nsw i32 0, %38
  %40 = and i32 %37, %39
  store i32 %40, ptr %10, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = or i32 %43, %44
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %10, align 4, !tbaa !5
  %48 = or i32 %46, %47
  %49 = ashr i32 %48, 1
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = or i32 %50, %51
  %53 = shl i32 %52, 1
  call void @_Z3dfsiiii(i32 noundef %42, i32 noundef %45, i32 noundef %49, i32 noundef %53)
  %54 = load i32, ptr %10, align 4, !tbaa !5
  %55 = load i32, ptr %9, align 4, !tbaa !5
  %56 = xor i32 %55, %54
  store i32 %56, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %33, !llvm.loop !9

57:                                               ; preds = %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  br label %58

58:                                               ; preds = %57, %14
  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: 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 = { 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"

@n = external dso_local local_unnamed_addr global i32, align 4
@ban = external dso_local local_unnamed_addr global [17 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z3dfsiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp eq i32 %5, %0
  br i1 %6, label %7, label %10

7:                                                ; preds = %4
  %8 = load i32, ptr @ans, align 4, !tbaa !5
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr @ans, align 4, !tbaa !5
  br label %.loopexit

10:                                               ; preds = %4
  %11 = sext i32 %0 to i64
  %12 = getelementptr inbounds [17 x i32], ptr @ban, i64 0, i64 %11
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %5
  %14 = or i32 %notmask, %13
  %15 = or i32 %14, %1
  %16 = or i32 %15, %2
  %.demorgan = or i32 %16, %3
  %.not = icmp eq i32 %.demorgan, -1
  br i1 %.not, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %10
  %17 = xor i32 %.demorgan, -1
  %18 = add nsw i32 %0, 1
  br label %19

19:                                               ; preds = %.lr.ph, %19
  %.019 = phi i32 [ %17, %.lr.ph ], [ %27, %19 ]
  %20 = sub nsw i32 0, %.019
  %21 = and i32 %.019, %20
  %22 = or i32 %21, %1
  %23 = or i32 %21, %2
  %24 = ashr i32 %23, 1
  %25 = or i32 %21, %3
  %26 = shl i32 %25, 1
  tail call void @_Z3dfsiiii(i32 noundef %18, i32 noundef %22, i32 noundef %24, i32 noundef %26)
  %27 = xor i32 %21, %.019
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %19, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %19, %10, %7
  ret void
}

attributes #0 = { mustprogress nofree nosync nounwind memory(readwrite, 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,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass