; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Random/2's complement/A.ll (Z1fx)

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@__PRETTY_FUNCTION__._Z1fx = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z1fx(i64 noundef %0) #0 {
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %3, align 8, !tbaa !5
  %9 = icmp sge i64 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  br label %13

11:                                               ; preds = %1
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 39, ptr noundef @__PRETTY_FUNCTION__._Z1fx) #3
  unreachable

12:                                               ; No predecessors!
  br label %13

13:                                               ; preds = %12, %10
  %14 = load i64, ptr %3, align 8, !tbaa !5
  %15 = icmp sle i64 %14, 1
  br i1 %15, label %16, label %18

16:                                               ; preds = %13
  %17 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %17, ptr %2, align 8
  br label %57

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 -1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 32, ptr %5, align 4, !tbaa !9
  br label %19

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

22:                                               ; preds = %19
  store i32 2, ptr %6, align 4
  br label %37

23:                                               ; preds = %19
  %24 = load i64, ptr %3, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = zext i32 %25 to i64
  %27 = shl i64 1, %26
  %28 = and i64 %24, %27
  %29 = icmp sgt i64 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %23
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  store i64 %32, ptr %4, align 8, !tbaa !5
  store i32 2, ptr %6, align 4
  br label %37

33:                                               ; preds = %23
  br label %34

34:                                               ; preds = %33
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = add nsw i32 %35, -1
  store i32 %36, ptr %5, align 4, !tbaa !9
  br label %19, !llvm.loop !11

37:                                               ; preds = %30, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %38

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

57:                                               ; preds = %38, %16
  %58 = load i64, ptr %2, align 8
  ret i64 %58
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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

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 = { noreturn nounwind "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 = { noreturn nounwind }
attributes #4 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [108 x i8], align 1
@__PRETTY_FUNCTION__._Z1fx = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z1fx(i64 noundef %0) local_unnamed_addr #0 {
  %2 = icmp sgt i64 %0, -1
  br i1 %2, label %.lr.ph, label %tailrecurse._crit_edge

tailrecurse._crit_edge:                           ; preds = %tailrecurse, %1
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 39, ptr noundef nonnull @__PRETTY_FUNCTION__._Z1fx) #2
  unreachable

.lr.ph:                                           ; preds = %1, %tailrecurse
  %.tr23 = phi i64 [ %39, %tailrecurse ], [ %0, %1 ]
  %accumulator.tr22 = phi i64 [ %42, %tailrecurse ], [ 0, %1 ]
  %3 = icmp ult i64 %.tr23, 2
  br i1 %3, label %44, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.lr.ph
  %4 = and i64 %.tr23, 4294967296
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %.preheader.1, label %tailrecurse

.preheader.1:                                     ; preds = %.preheader.preheader
  %5 = and i64 %.tr23, 2147483648
  %.not26 = icmp eq i64 %5, 0
  br i1 %.not26, label %.preheader.2, label %tailrecurse

.preheader.2:                                     ; preds = %.preheader.1
  %6 = and i64 %.tr23, 1073741824
  %.not27 = icmp eq i64 %6, 0
  br i1 %.not27, label %.preheader.3, label %tailrecurse

.preheader.3:                                     ; preds = %.preheader.2
  %7 = and i64 %.tr23, 536870912
  %.not28 = icmp eq i64 %7, 0
  br i1 %.not28, label %.preheader.4, label %tailrecurse

.preheader.4:                                     ; preds = %.preheader.3
  %8 = and i64 %.tr23, 268435456
  %.not29 = icmp eq i64 %8, 0
  br i1 %.not29, label %.preheader.5, label %tailrecurse

.preheader.5:                                     ; preds = %.preheader.4
  %9 = and i64 %.tr23, 134217728
  %.not30 = icmp eq i64 %9, 0
  br i1 %.not30, label %.preheader.6, label %tailrecurse

.preheader.6:                                     ; preds = %.preheader.5
  %10 = and i64 %.tr23, 67108864
  %.not31 = icmp eq i64 %10, 0
  br i1 %.not31, label %.preheader.7, label %tailrecurse

.preheader.7:                                     ; preds = %.preheader.6
  %11 = and i64 %.tr23, 33554432
  %.not32 = icmp eq i64 %11, 0
  br i1 %.not32, label %.preheader.8, label %tailrecurse

.preheader.8:                                     ; preds = %.preheader.7
  %12 = and i64 %.tr23, 16777216
  %.not33 = icmp eq i64 %12, 0
  br i1 %.not33, label %.preheader.9, label %tailrecurse

.preheader.9:                                     ; preds = %.preheader.8
  %13 = and i64 %.tr23, 8388608
  %.not34 = icmp eq i64 %13, 0
  br i1 %.not34, label %.preheader.10, label %tailrecurse

.preheader.10:                                    ; preds = %.preheader.9
  %14 = and i64 %.tr23, 4194304
  %.not35 = icmp eq i64 %14, 0
  br i1 %.not35, label %.preheader.11, label %tailrecurse

.preheader.11:                                    ; preds = %.preheader.10
  %15 = and i64 %.tr23, 2097152
  %.not36 = icmp eq i64 %15, 0
  br i1 %.not36, label %.preheader.12, label %tailrecurse

.preheader.12:                                    ; preds = %.preheader.11
  %16 = and i64 %.tr23, 1048576
  %.not37 = icmp eq i64 %16, 0
  br i1 %.not37, label %.preheader.13, label %tailrecurse

.preheader.13:                                    ; preds = %.preheader.12
  %17 = and i64 %.tr23, 524288
  %.not38 = icmp eq i64 %17, 0
  br i1 %.not38, label %.preheader.14, label %tailrecurse

.preheader.14:                                    ; preds = %.preheader.13
  %18 = and i64 %.tr23, 262144
  %.not39 = icmp eq i64 %18, 0
  br i1 %.not39, label %.preheader.15, label %tailrecurse

.preheader.15:                                    ; preds = %.preheader.14
  %19 = and i64 %.tr23, 131072
  %.not40 = icmp eq i64 %19, 0
  br i1 %.not40, label %.preheader.16, label %tailrecurse

.preheader.16:                                    ; preds = %.preheader.15
  %20 = and i64 %.tr23, 65536
  %.not41 = icmp eq i64 %20, 0
  br i1 %.not41, label %.preheader.17, label %tailrecurse

.preheader.17:                                    ; preds = %.preheader.16
  %21 = and i64 %.tr23, 32768
  %.not42 = icmp eq i64 %21, 0
  br i1 %.not42, label %.preheader.18, label %tailrecurse

.preheader.18:                                    ; preds = %.preheader.17
  %22 = and i64 %.tr23, 16384
  %.not43 = icmp eq i64 %22, 0
  br i1 %.not43, label %.preheader.19, label %tailrecurse

.preheader.19:                                    ; preds = %.preheader.18
  %23 = and i64 %.tr23, 8192
  %.not44 = icmp eq i64 %23, 0
  br i1 %.not44, label %.preheader.20, label %tailrecurse

.preheader.20:                                    ; preds = %.preheader.19
  %24 = and i64 %.tr23, 4096
  %.not45 = icmp eq i64 %24, 0
  br i1 %.not45, label %.preheader.21, label %tailrecurse

.preheader.21:                                    ; preds = %.preheader.20
  %25 = and i64 %.tr23, 2048
  %.not46 = icmp eq i64 %25, 0
  br i1 %.not46, label %.preheader.22, label %tailrecurse

.preheader.22:                                    ; preds = %.preheader.21
  %26 = and i64 %.tr23, 1024
  %.not47 = icmp eq i64 %26, 0
  br i1 %.not47, label %.preheader.23, label %tailrecurse

.preheader.23:                                    ; preds = %.preheader.22
  %27 = and i64 %.tr23, 512
  %.not48 = icmp eq i64 %27, 0
  br i1 %.not48, label %.preheader.24, label %tailrecurse

.preheader.24:                                    ; preds = %.preheader.23
  %28 = and i64 %.tr23, 256
  %.not49 = icmp eq i64 %28, 0
  br i1 %.not49, label %.preheader.25, label %tailrecurse

.preheader.25:                                    ; preds = %.preheader.24
  %29 = and i64 %.tr23, 128
  %.not50 = icmp eq i64 %29, 0
  br i1 %.not50, label %.preheader.26, label %tailrecurse

.preheader.26:                                    ; preds = %.preheader.25
  %30 = and i64 %.tr23, 64
  %.not51 = icmp eq i64 %30, 0
  br i1 %.not51, label %.preheader.27, label %tailrecurse

.preheader.27:                                    ; preds = %.preheader.26
  %31 = and i64 %.tr23, 32
  %.not52 = icmp eq i64 %31, 0
  br i1 %.not52, label %.preheader.28, label %tailrecurse

.preheader.28:                                    ; preds = %.preheader.27
  %32 = and i64 %.tr23, 16
  %.not53 = icmp eq i64 %32, 0
  br i1 %.not53, label %.preheader.29, label %tailrecurse

.preheader.29:                                    ; preds = %.preheader.28
  %33 = and i64 %.tr23, 8
  %.not54 = icmp eq i64 %33, 0
  br i1 %.not54, label %.preheader.30, label %tailrecurse

.preheader.30:                                    ; preds = %.preheader.29
  %34 = and i64 %.tr23, 4
  %.not55 = icmp eq i64 %34, 0
  br i1 %.not55, label %.preheader.31, label %tailrecurse

.preheader.31:                                    ; preds = %.preheader.30
  %35 = and i64 %.tr23, 2
  %.not56 = icmp eq i64 %35, 0
  br i1 %.not56, label %.preheader.32, label %tailrecurse

.preheader.32:                                    ; preds = %.preheader.31
  %36 = and i64 %.tr23, 1
  %sext = add nsw i64 %36, -1
  br label %tailrecurse

tailrecurse:                                      ; preds = %.preheader.32, %.preheader.31, %.preheader.30, %.preheader.29, %.preheader.28, %.preheader.27, %.preheader.26, %.preheader.25, %.preheader.24, %.preheader.23, %.preheader.22, %.preheader.21, %.preheader.20, %.preheader.19, %.preheader.18, %.preheader.17, %.preheader.16, %.preheader.15, %.preheader.14, %.preheader.13, %.preheader.12, %.preheader.11, %.preheader.10, %.preheader.9, %.preheader.8, %.preheader.7, %.preheader.6, %.preheader.5, %.preheader.4, %.preheader.3, %.preheader.2, %.preheader.1, %.preheader.preheader
  %.017 = phi i64 [ 32, %.preheader.preheader ], [ 31, %.preheader.1 ], [ 30, %.preheader.2 ], [ 29, %.preheader.3 ], [ 28, %.preheader.4 ], [ 27, %.preheader.5 ], [ 26, %.preheader.6 ], [ 25, %.preheader.7 ], [ 24, %.preheader.8 ], [ 23, %.preheader.9 ], [ 22, %.preheader.10 ], [ 21, %.preheader.11 ], [ 20, %.preheader.12 ], [ 19, %.preheader.13 ], [ 18, %.preheader.14 ], [ 17, %.preheader.15 ], [ 16, %.preheader.16 ], [ 15, %.preheader.17 ], [ 14, %.preheader.18 ], [ 13, %.preheader.19 ], [ 12, %.preheader.20 ], [ 11, %.preheader.21 ], [ 10, %.preheader.22 ], [ 9, %.preheader.23 ], [ 8, %.preheader.24 ], [ 7, %.preheader.25 ], [ 6, %.preheader.26 ], [ 5, %.preheader.27 ], [ 4, %.preheader.28 ], [ 3, %.preheader.29 ], [ 2, %.preheader.30 ], [ 1, %.preheader.31 ], [ %sext, %.preheader.32 ]
  %37 = add nsw i64 %.017, -1
  %38 = shl nsw i64 %.017, %37
  %.neg = shl nsw i64 -1, %.017
  %39 = add nsw i64 %.neg, %.tr23
  %40 = add i64 %accumulator.tr22, 1
  %41 = add i64 %40, %39
  %42 = add i64 %41, %38
  %43 = icmp sgt i64 %39, -1
  br i1 %43, label %.lr.ph, label %tailrecurse._crit_edge

44:                                               ; preds = %.lr.ph
  %accumulator.ret.tr = add nsw i64 %.tr23, %accumulator.tr22
  ret i64 %accumulator.ret.tr
}

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr 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 = { noreturn nounwind "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 = { noreturn 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)"}


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