; LLVM IR from abeaumont/competitive-programming :: codechef/feb18/broclk.ll (Z3powPA2_nnnn)

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

@constinit = external hidden constant [2 x i128], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multPA2_nS0_n(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z3powPA2_nnnn(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i128 noundef %5) #2 {
  %7 = alloca i128, align 16
  %8 = alloca i128, align 16
  %9 = alloca ptr, align 8
  %10 = alloca i128, align 16
  %11 = alloca i128, align 16
  %12 = alloca i128, align 16
  %13 = alloca [2 x [2 x i128]], align 16
  %14 = alloca i128, align 16
  %15 = alloca i128, align 16
  %16 = alloca i128, align 16
  %17 = alloca i128, align 16
  %18 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 0
  store i64 %1, ptr %18, align 16
  %19 = getelementptr inbounds { i64, i64 }, ptr %7, i32 0, i32 1
  store i64 %2, ptr %19, align 8
  %20 = load i128, ptr %7, align 16, !tbaa !5
  %21 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 0
  store i64 %3, ptr %21, align 16
  %22 = getelementptr inbounds { i64, i64 }, ptr %8, i32 0, i32 1
  store i64 %4, ptr %22, align 8
  %23 = load i128, ptr %8, align 16, !tbaa !5
  store ptr %0, ptr %9, align 8, !tbaa !9
  store i128 %20, ptr %10, align 16, !tbaa !5
  store i128 %23, ptr %11, align 16, !tbaa !5
  store i128 %5, ptr %12, align 16, !tbaa !5
  %24 = load i128, ptr %10, align 16, !tbaa !5
  %25 = icmp sle i128 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %6
  br label %64

27:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 64, ptr %13) #4
  %28 = load i128, ptr %11, align 16, !tbaa !5
  %29 = mul nsw i128 2, %28
  store i128 %29, ptr %13, align 16, !tbaa !5
  %30 = getelementptr inbounds i128, ptr %13, i64 1
  store i128 -1, ptr %30, align 16, !tbaa !5
  %31 = getelementptr inbounds [2 x i128], ptr %13, i64 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %31, ptr align 16 @constinit, i64 32, i1 false), !tbaa.struct !11
  %32 = load ptr, ptr %9, align 8, !tbaa !9
  %33 = load i128, ptr %10, align 16, !tbaa !5
  %34 = sdiv i128 %33, 2
  %35 = load i128, ptr %11, align 16, !tbaa !5
  %36 = load i128, ptr %12, align 16, !tbaa !5
  store i128 %34, ptr %14, align 16, !tbaa !5
  %37 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 0
  %38 = load i64, ptr %37, align 16
  %39 = getelementptr inbounds { i64, i64 }, ptr %14, i32 0, i32 1
  %40 = load i64, ptr %39, align 8
  store i128 %35, ptr %15, align 16, !tbaa !5
  %41 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 0
  %42 = load i64, ptr %41, align 16
  %43 = getelementptr inbounds { i64, i64 }, ptr %15, i32 0, i32 1
  %44 = load i64, ptr %43, align 8
  call void @_Z3powPA2_nnnn(ptr noundef %32, i64 noundef %38, i64 noundef %40, i64 noundef %42, i64 noundef %44, i128 noundef %36)
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = load ptr, ptr %9, align 8, !tbaa !9
  %47 = load i128, ptr %12, align 16, !tbaa !5
  store i128 %47, ptr %16, align 16, !tbaa !5
  %48 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 0
  %49 = load i64, ptr %48, align 16
  %50 = getelementptr inbounds { i64, i64 }, ptr %16, i32 0, i32 1
  %51 = load i64, ptr %50, align 8
  call void @_Z4multPA2_nS0_n(ptr noundef %45, ptr noundef %46, i64 noundef %49, i64 noundef %51)
  %52 = load i128, ptr %10, align 16, !tbaa !5
  %53 = srem i128 %52, 2
  %54 = icmp ne i128 %53, 0
  br i1 %54, label %55, label %63

55:                                               ; preds = %27
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  %57 = getelementptr inbounds [2 x [2 x i128]], ptr %13, i64 0, i64 0
  %58 = load i128, ptr %12, align 16, !tbaa !5
  store i128 %58, ptr %17, align 16, !tbaa !5
  %59 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 0
  %60 = load i64, ptr %59, align 16
  %61 = getelementptr inbounds { i64, i64 }, ptr %17, i32 0, i32 1
  %62 = load i64, ptr %61, align 8
  call void @_Z4multPA2_nS0_n(ptr noundef %56, ptr noundef %57, i64 noundef %60, i64 noundef %62)
  br label %63

63:                                               ; preds = %55, %27
  call void @llvm.lifetime.end.p0(i64 64, ptr %13) #4
  br label %64

64:                                               ; preds = %63, %26
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"__int128", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{i64 0, i64 32, !12}
!12 = !{!7, !7, 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"

@constinit = external hidden local_unnamed_addr constant [2 x i128], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z4multPA2_nS0_n(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z3powPA2_nnnn(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i128 noundef %5) local_unnamed_addr #1 {
  %7 = alloca [2 x [2 x i128]], align 16
  %.sroa.220.0.insert.ext = zext i64 %2 to i128
  %.sroa.220.0.insert.shift = shl nuw i128 %.sroa.220.0.insert.ext, 64
  %.sroa.019.0.insert.ext = zext i64 %1 to i128
  %.sroa.019.0.insert.insert = or disjoint i128 %.sroa.220.0.insert.shift, %.sroa.019.0.insert.ext
  %8 = icmp slt i128 %.sroa.019.0.insert.insert, 2
  br i1 %8, label %19, label %9

9:                                                ; preds = %6
  %.sroa.218.0.insert.ext = zext i64 %4 to i128
  %.sroa.017.0.insert.ext = zext i64 %3 to i128
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #3
  %10 = shl i128 %.sroa.218.0.insert.ext, 65
  %11 = shl nuw nsw i128 %.sroa.017.0.insert.ext, 1
  %12 = or disjoint i128 %10, %11
  store i128 %12, ptr %7, align 16, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %7, i64 16
  store i128 -1, ptr %13, align 16, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %7, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %14, ptr noundef nonnull align 16 dereferenceable(32) @constinit, i64 32, i1 false), !tbaa.struct !9
  %15 = lshr i128 %.sroa.019.0.insert.insert, 1
  %.sroa.05.0.extract.trunc = trunc i128 %15 to i64
  %.sroa.26.0.extract.shift = lshr i64 %2, 1
  tail call void @_Z3powPA2_nnnn(ptr noundef %0, i64 noundef %.sroa.05.0.extract.trunc, i64 noundef %.sroa.26.0.extract.shift, i64 noundef %3, i64 noundef %4, i128 noundef %5)
  %.sroa.01.0.extract.trunc = trunc i128 %5 to i64
  %.sroa.22.0.extract.shift = lshr i128 %5, 64
  %.sroa.22.0.extract.trunc = trunc nuw i128 %.sroa.22.0.extract.shift to i64
  tail call void @_Z4multPA2_nS0_n(ptr noundef %0, ptr noundef %0, i64 noundef %.sroa.01.0.extract.trunc, i64 noundef %.sroa.22.0.extract.trunc)
  %16 = and i128 %.sroa.019.0.insert.ext, 1
  %.not = icmp eq i128 %16, 0
  br i1 %.not, label %18, label %17

17:                                               ; preds = %9
  call void @_Z4multPA2_nS0_n(ptr noundef %0, ptr noundef nonnull %7, i64 noundef %.sroa.01.0.extract.trunc, i64 noundef %.sroa.22.0.extract.trunc)
  br label %18

18:                                               ; preds = %17, %9
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #3
  br label %19

19:                                               ; preds = %6, %18
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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


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