; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x02-递推与递归/98. 分形之城.ll (Z6getPosxx)

; 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.Pos = type { i64, i64 }

; Function Attrs: mustprogress uwtable
define dso_local { i64, i64 } @_Z6getPosxx(i64 noundef %0, i64 noundef %1) #0 {
  %3 = alloca %struct.Pos, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca %struct.Pos, align 8
  %9 = alloca i32, align 4
  store i64 %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !5
  %10 = load i64, ptr %4, align 8, !tbaa !5
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef 0, i64 noundef 0)
  br label %72

13:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %14 = load i64, ptr %4, align 8, !tbaa !5
  %15 = sub nsw i64 %14, 1
  %16 = shl i64 1, %15
  store i64 %16, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %17 = load i64, ptr %4, align 8, !tbaa !5
  %18 = mul nsw i64 2, %17
  %19 = sub nsw i64 %18, 2
  %20 = shl i64 1, %19
  store i64 %20, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #3
  %21 = load i64, ptr %4, align 8, !tbaa !5
  %22 = sub nsw i64 %21, 1
  %23 = load i64, ptr %5, align 8, !tbaa !5
  %24 = load i64, ptr %7, align 8, !tbaa !5
  %25 = srem i64 %23, %24
  %26 = call { i64, i64 } @_Z6getPosxx(i64 noundef %22, i64 noundef %25)
  %27 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  %28 = extractvalue { i64, i64 } %26, 0
  store i64 %28, ptr %27, align 8
  %29 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  %30 = extractvalue { i64, i64 } %26, 1
  store i64 %30, ptr %29, align 8
  %31 = load i64, ptr %5, align 8, !tbaa !5
  %32 = load i64, ptr %7, align 8, !tbaa !5
  %33 = sdiv i64 %31, %32
  switch i64 %33, label %70 [
    i64 0, label %34
    i64 1, label %39
    i64 2, label %46
    i64 3, label %55
  ]

34:                                               ; preds = %13
  %35 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 1
  %36 = load i64, ptr %35, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 0
  %38 = load i64, ptr %37, align 8, !tbaa !11
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %36, i64 noundef %38)
  store i32 1, ptr %9, align 4
  br label %71

39:                                               ; preds = %13
  %40 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !11
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = add nsw i64 %41, %42
  %44 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 1
  %45 = load i64, ptr %44, align 8, !tbaa !9
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %43, i64 noundef %45)
  store i32 1, ptr %9, align 4
  br label %71

46:                                               ; preds = %13
  %47 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !11
  %49 = load i64, ptr %6, align 8, !tbaa !5
  %50 = add nsw i64 %48, %49
  %51 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 1
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = load i64, ptr %6, align 8, !tbaa !5
  %54 = add nsw i64 %52, %53
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %50, i64 noundef %54)
  store i32 1, ptr %9, align 4
  br label %71

55:                                               ; preds = %13
  %56 = load i64, ptr %6, align 8, !tbaa !5
  %57 = mul nsw i64 2, %56
  %58 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !9
  %60 = load i64, ptr %6, align 8, !tbaa !5
  %61 = add nsw i64 %59, %60
  %62 = sub nsw i64 %57, %61
  %63 = sub nsw i64 %62, 1
  %64 = load i64, ptr %6, align 8, !tbaa !5
  %65 = mul nsw i64 2, %64
  %66 = getelementptr inbounds %struct.Pos, ptr %8, i32 0, i32 0
  %67 = load i64, ptr %66, align 8, !tbaa !11
  %68 = sub nsw i64 %65, %67
  %69 = sub nsw i64 %68, 1
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %63, i64 noundef %69)
  store i32 1, ptr %9, align 4
  br label %71

70:                                               ; preds = %13
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef -1, i64 noundef -1)
  store i32 1, ptr %9, align 4
  br label %71

71:                                               ; preds = %70, %55, %46, %39, %34
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %72

72:                                               ; preds = %71, %12
  %73 = load { i64, i64 }, ptr %3, align 8
  ret { i64, i64 } %73
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i64 noundef) unnamed_addr #1 align 2

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS3Pos", !6, i64 0, !6, i64 8}
!11 = !{!10, !6, 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"

%struct.Pos = type { i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_Z6getPosxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = alloca %struct.Pos, align 8
  %4 = icmp eq i64 %0, 0
  br i1 %4, label %5, label %6

5:                                                ; preds = %2
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef 0, i64 noundef 0)
  br label %31

6:                                                ; preds = %2
  %7 = add nsw i64 %0, -1
  %8 = shl nuw i64 1, %7
  %9 = shl nsw i64 %0, 1
  %10 = add nsw i64 %9, -2
  %11 = shl nuw i64 1, %10
  %12 = srem i64 %1, %11
  %13 = tail call { i64, i64 } @_Z6getPosxx(i64 noundef %7, i64 noundef %12)
  %14 = extractvalue { i64, i64 } %13, 0
  %15 = extractvalue { i64, i64 } %13, 1
  %16 = sdiv i64 %1, %11
  switch i64 %16, label %30 [
    i64 0, label %17
    i64 1, label %18
    i64 2, label %20
    i64 3, label %23
  ]

17:                                               ; preds = %6
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %15, i64 noundef %14)
  br label %31

18:                                               ; preds = %6
  %19 = add nsw i64 %14, %8
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %19, i64 noundef %15)
  br label %31

20:                                               ; preds = %6
  %21 = add nsw i64 %14, %8
  %22 = add nsw i64 %15, %8
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %21, i64 noundef %22)
  br label %31

23:                                               ; preds = %6
  %24 = shl i64 2, %7
  %25 = add nsw i64 %15, %8
  %26 = xor i64 %25, -1
  %27 = add i64 %24, %26
  %28 = xor i64 %14, -1
  %29 = add i64 %24, %28
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef %27, i64 noundef %29)
  br label %31

30:                                               ; preds = %6
  call void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16) %3, i64 noundef -1, i64 noundef -1)
  br label %31

31:                                               ; preds = %17, %18, %20, %23, %30, %5
  %.fca.0.load = load i64, ptr %3, align 8
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %3, i64 8
  %.fca.1.load = load i64, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.fca.1.load, 1
  ret { i64, i64 } %.fca.1.insert
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3PosC2Exx(ptr noundef nonnull align 8 dereferenceable(16), i64 noundef, i64 noundef) 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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass