; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/332 Division 2/Problem E/E.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 @_Z3go1iii(i32 noundef, 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 i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = 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
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %4, align 4, !tbaa !5
  %15 = shl i32 1, %14
  %16 = xor i32 %13, %15
  store i32 %16, ptr %6, align 4, !tbaa !5
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %20

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

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

21:                                               ; preds = %36, %20
  %22 = load i32, ptr %9, align 4, !tbaa !5
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %21
  store i32 2, ptr %7, align 4
  br label %39

26:                                               ; preds = %21
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !5
  %29 = shl i32 1, %28
  %30 = and i32 %27, %29
  %31 = icmp sgt i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %26
  %33 = load i32, ptr %9, align 4, !tbaa !5
  %34 = shl i32 1, %33
  store i32 %34, ptr %8, align 4, !tbaa !5
  store i32 2, ptr %7, align 4
  br label %39

35:                                               ; preds = %26
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %9, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %9, align 4, !tbaa !5
  br label %21, !llvm.loop !9

39:                                               ; preds = %32, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %40

40:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  store i64 0, ptr %10, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %41 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %41, ptr %11, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %80, %40
  %43 = load i32, ptr %11, align 4, !tbaa !5
  %44 = icmp sgt i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %42
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %85

46:                                               ; preds = %42
  %47 = load i32, ptr %11, align 4, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = and i32 %47, %48
  %50 = icmp eq i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %46
  br label %80

52:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %53

53:                                               ; preds = %76, %52
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = load i32, ptr @n, align 4, !tbaa !5
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  store i32 8, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %79

58:                                               ; preds = %53
  %59 = load i32, ptr %12, align 4, !tbaa !5
  %60 = load i32, ptr %11, align 4, !tbaa !5
  %61 = call noundef zeroext i1 @_Z2inii(i32 noundef %59, i32 noundef %60)
  br i1 %61, label %62, label %75

62:                                               ; preds = %58
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = load i32, ptr %11, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = call noundef i64 @_Z3go1iii(i32 noundef %63, i32 noundef %64, i32 noundef %65)
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = load i32, ptr %5, align 4, !tbaa !5
  %69 = load i32, ptr %11, align 4, !tbaa !5
  %70 = xor i32 %68, %69
  %71 = call noundef i64 @_Z3go2ii(i32 noundef %67, i32 noundef %70)
  %72 = mul nsw i64 %66, %71
  %73 = load i64, ptr %10, align 8, !tbaa !11
  %74 = add nsw i64 %73, %72
  store i64 %74, ptr %10, align 8, !tbaa !11
  br label %75

75:                                               ; preds = %62, %58
  br label %76

76:                                               ; preds = %75
  %77 = load i32, ptr %12, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %12, align 4, !tbaa !5
  br label %53, !llvm.loop !13

79:                                               ; preds = %57
  br label %80

80:                                               ; preds = %79, %51
  %81 = load i32, ptr %11, align 4, !tbaa !5
  %82 = sub nsw i32 %81, 1
  %83 = load i32, ptr %6, align 4, !tbaa !5
  %84 = and i32 %82, %83
  store i32 %84, ptr %11, align 4, !tbaa !5
  br label %42, !llvm.loop !14

85:                                               ; preds = %45
  %86 = load i64, ptr %10, align 8, !tbaa !11
  store i64 %86, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %87

87:                                               ; preds = %85, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %88 = load i64, ptr %3, align 8
  ret i64 %88
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3go2ii(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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; 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 @_Z3go1iii(i32 noundef, 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 %.loopexit33, label %.preheader34

.preheader34:                                     ; preds = %2
  %6 = load i32, ptr @n, align 4
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

8:                                                ; preds = %.lr.ph
  %9 = add nuw nsw i32 %.02935, 1
  %exitcond.not = icmp eq i32 %9, %6
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %.preheader34, %8
  %.02935 = phi i32 [ %9, %8 ], [ 0, %.preheader34 ]
  %10 = shl nuw i32 1, %.02935
  %11 = and i32 %10, %4
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %._crit_edge, label %8

._crit_edge:                                      ; preds = %8, %.lr.ph, %.preheader34
  %.030 = phi i32 [ 0, %.preheader34 ], [ %10, %.lr.ph ], [ 0, %8 ]
  %13 = icmp sgt i32 %4, 0
  br i1 %13, label %.lr.ph45, label %.loopexit33

.lr.ph45:                                         ; preds = %._crit_edge, %.loopexit
  %14 = phi i32 [ %30, %.loopexit ], [ %6, %._crit_edge ]
  %.02743 = phi i32 [ %32, %.loopexit ], [ %4, %._crit_edge ]
  %.02842 = phi i64 [ %.3, %.loopexit ], [ 0, %._crit_edge ]
  %15 = and i32 %.02743, %.030
  %16 = icmp ne i32 %15, 0
  %17 = icmp sgt i32 %14, 0
  %or.cond = select i1 %16, i1 %17, i1 false
  br i1 %or.cond, label %.lr.ph40, label %.loopexit

.lr.ph40:                                         ; preds = %.lr.ph45
  %18 = xor i32 %.02743, %1
  br label %19

19:                                               ; preds = %.lr.ph40, %26
  %.039 = phi i32 [ 0, %.lr.ph40 ], [ %27, %26 ]
  %.138 = phi i64 [ %.02842, %.lr.ph40 ], [ %.2, %26 ]
  %20 = tail call noundef zeroext i1 @_Z2inii(i32 noundef %.039, i32 noundef %.02743)
  br i1 %20, label %21, label %26

21:                                               ; preds = %19
  %22 = tail call noundef i64 @_Z3go1iii(i32 noundef %.039, i32 noundef %.02743, i32 noundef %0)
  %23 = tail call noundef i64 @_Z3go2ii(i32 noundef %0, i32 noundef %18)
  %24 = mul nsw i64 %23, %22
  %25 = add nsw i64 %24, %.138
  br label %26

26:                                               ; preds = %19, %21
  %.2 = phi i64 [ %25, %21 ], [ %.138, %19 ]
  %27 = add nuw nsw i32 %.039, 1
  %28 = load i32, ptr @n, align 4
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %19, label %.loopexit, !llvm.loop !7

.loopexit:                                        ; preds = %26, %.lr.ph45
  %30 = phi i32 [ %14, %.lr.ph45 ], [ %28, %26 ]
  %.3 = phi i64 [ %.02842, %.lr.ph45 ], [ %.2, %26 ]
  %31 = add nuw i32 %.02743, 2147483647
  %32 = and i32 %31, %4
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %.lr.ph45, label %.loopexit33, !llvm.loop !8

.loopexit33:                                      ; preds = %.loopexit, %._crit_edge, %2
  %.031 = phi i64 [ 1, %2 ], [ 0, %._crit_edge ], [ %.3, %.loopexit ]
  ret i64 %.031
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z3go2ii(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}
!8 = distinct !{!8, !6}


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