; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/332 Division 2/Problem E/tmp.ll (Z4calcii)

; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z2inii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5calcGii(i32 noundef, i32 noundef) #1

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4calcii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %11 = load i32, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = shl i32 1, %12
  %14 = xor i32 %11, %13
  store i32 %14, ptr %6, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i64 1, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %68

18:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %19 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %19, ptr %9, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %61, %18
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %20
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %66

24:                                               ; preds = %20
  %25 = load i32, ptr %9, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = and i32 %25, %26
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sub nsw i32 0, %28
  %30 = and i32 %27, %29
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %24
  br label %61

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %57, %33
  %35 = load i32, ptr %10, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %60

39:                                               ; preds = %34
  %40 = load i32, ptr %10, align 4, !tbaa !5
  %41 = load i32, ptr %9, align 4, !tbaa !5
  %42 = call noundef zeroext i1 @_Z2inii(i32 noundef %40, i32 noundef %41)
  br i1 %42, label %43, label %56

43:                                               ; preds = %39
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = load i32, ptr %9, align 4, !tbaa !5
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = call noundef i64 @_Z5calcFiii(i32 noundef %44, i32 noundef %45, i32 noundef %46)
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = load i32, ptr %9, align 4, !tbaa !5
  %51 = xor i32 %49, %50
  %52 = call noundef i64 @_Z5calcGii(i32 noundef %48, i32 noundef %51)
  %53 = mul nsw i64 %47, %52
  %54 = load i64, ptr %8, align 8, !tbaa !9
  %55 = add nsw i64 %54, %53
  store i64 %55, ptr %8, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %43, %39
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %10, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %10, align 4, !tbaa !5
  br label %34, !llvm.loop !11

60:                                               ; preds = %38
  br label %61

61:                                               ; preds = %60, %32
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  %64 = load i32, ptr %6, align 4, !tbaa !5
  %65 = and i32 %63, %64
  store i32 %65, ptr %9, align 4, !tbaa !5
  br label %20, !llvm.loop !13

66:                                               ; preds = %23
  %67 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %67, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %68

68:                                               ; preds = %66, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %69 = load i64, ptr %3, align 8
  ret i64 %69
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5calcFiii(i32 noundef, i32 noundef, i32 noundef) #1

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" }
attributes #1 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z2inii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5calcGii(i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4calcii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = shl nuw i32 1, %0
  %4 = xor i32 %3, %1
  %5 = icmp eq i32 %3, %1
  br i1 %5, label %.loopexit28, label %.preheader27

.preheader27:                                     ; preds = %2
  %6 = icmp sgt i32 %4, 0
  br i1 %6, label %.lr.ph33, label %.loopexit28

.lr.ph33:                                         ; preds = %.preheader27
  %7 = sub nsw i32 0, %4
  %8 = and i32 %4, %7
  %.pre = load i32, ptr @n, align 4
  br label %9

9:                                                ; preds = %.lr.ph33, %.loopexit
  %10 = phi i32 [ %.pre, %.lr.ph33 ], [ %26, %.loopexit ]
  %.02332 = phi i32 [ %4, %.lr.ph33 ], [ %28, %.loopexit ]
  %.02431 = phi i64 [ 0, %.lr.ph33 ], [ %.3, %.loopexit ]
  %11 = and i32 %8, %.02332
  %12 = icmp ne i32 %11, 0
  %13 = icmp sgt i32 %10, 0
  %or.cond = select i1 %12, i1 %13, i1 false
  br i1 %or.cond, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %9
  %14 = xor i32 %.02332, %1
  br label %15

15:                                               ; preds = %.lr.ph, %22
  %.030 = phi i32 [ 0, %.lr.ph ], [ %23, %22 ]
  %.129 = phi i64 [ %.02431, %.lr.ph ], [ %.2, %22 ]
  %16 = tail call noundef zeroext i1 @_Z2inii(i32 noundef %.030, i32 noundef %.02332)
  br i1 %16, label %17, label %22

17:                                               ; preds = %15
  %18 = tail call noundef i64 @_Z5calcFiii(i32 noundef %.030, i32 noundef %.02332, i32 noundef %0)
  %19 = tail call noundef i64 @_Z5calcGii(i32 noundef %0, i32 noundef %14)
  %20 = mul nsw i64 %19, %18
  %21 = add nsw i64 %20, %.129
  br label %22

22:                                               ; preds = %15, %17
  %.2 = phi i64 [ %21, %17 ], [ %.129, %15 ]
  %23 = add nuw nsw i32 %.030, 1
  %24 = load i32, ptr @n, align 4
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %15, label %.loopexit, !llvm.loop !5

.loopexit:                                        ; preds = %22, %9
  %26 = phi i32 [ %10, %9 ], [ %24, %22 ]
  %.3 = phi i64 [ %.02431, %9 ], [ %.2, %22 ]
  %27 = add nuw i32 %.02332, 2147483647
  %28 = and i32 %27, %4
  %29 = icmp sgt i32 %28, 0
  br i1 %29, label %9, label %.loopexit28, !llvm.loop !7

.loopexit28:                                      ; preds = %.loopexit, %.preheader27, %2
  %.025 = phi i64 [ 1, %2 ], [ 0, %.preheader27 ], [ %.3, %.loopexit ]
  ret i64 %.025
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5calcFiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

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" }
attributes #1 = { 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" }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass