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

; 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.1 = 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 uwtable
declare dso_local void @_Z3powPA2_nnnn(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i128 noundef) #1

; 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) #2

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

28:                                               ; preds = %6
  %29 = load i128, ptr %12, align 16, !tbaa !5
  store i128 %29, ptr %7, align 16
  br label %61

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

61:                                               ; preds = %30, %28
  %62 = load { i64, i64 }, ptr %7, align 16
  ret { i64, i64 } %62
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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}


; 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.1 = 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 uwtable
declare dso_local void @_Z3powPA2_nnnn(ptr noundef, i64 noundef, i64 noundef, i64 noundef, i64 noundef, i128 noundef) local_unnamed_addr #1

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef { i64, i64 } @_Z9chevyshevnnn(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3, i64 noundef %4, i64 noundef %5) local_unnamed_addr #1 {
  %7 = alloca [2 x [2 x i128]], align 16
  %.sroa.216.0.insert.ext = zext i64 %1 to i128
  %.sroa.216.0.insert.shift = shl nuw i128 %.sroa.216.0.insert.ext, 64
  %.sroa.015.0.insert.ext = zext i64 %0 to i128
  %.sroa.015.0.insert.insert = or disjoint i128 %.sroa.216.0.insert.shift, %.sroa.015.0.insert.ext
  %8 = icmp eq i128 %.sroa.015.0.insert.insert, 1
  br i1 %8, label %20, label %9

9:                                                ; preds = %6
  %.sroa.214.0.insert.ext = zext i64 %3 to i128
  %.sroa.214.0.insert.shift = shl nuw i128 %.sroa.214.0.insert.ext, 64
  %.sroa.013.0.insert.ext = zext i64 %2 to i128
  %.sroa.013.0.insert.insert = or disjoint i128 %.sroa.214.0.insert.shift, %.sroa.013.0.insert.ext
  %.sroa.212.0.insert.ext = zext i64 %5 to i128
  %.sroa.212.0.insert.shift = shl nuw i128 %.sroa.212.0.insert.ext, 64
  %.sroa.011.0.insert.ext = zext i64 %4 to i128
  %.sroa.011.0.insert.insert = or disjoint i128 %.sroa.212.0.insert.shift, %.sroa.011.0.insert.ext
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %7) #3
  %10 = shl nsw i128 %.sroa.013.0.insert.insert, 1
  store i128 %10, ptr %7, align 16, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %7, i64 16
  store i128 -1, ptr %11, align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %7, i64 32
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %12, ptr noundef nonnull align 16 dereferenceable(32) @constinit.1, i64 32, i1 false), !tbaa.struct !9
  %13 = add nsw i128 %.sroa.015.0.insert.insert, -1
  %.sroa.01.0.extract.trunc = trunc i128 %13 to i64
  %.sroa.22.0.extract.shift = lshr i128 %13, 64
  %.sroa.22.0.extract.trunc = trunc nuw i128 %.sroa.22.0.extract.shift to i64
  call void @_Z3powPA2_nnnn(ptr noundef nonnull %7, i64 noundef %.sroa.01.0.extract.trunc, i64 noundef %.sroa.22.0.extract.trunc, i64 noundef %2, i64 noundef %3, i128 noundef %.sroa.011.0.insert.insert)
  %14 = load i128, ptr %7, align 16, !tbaa !5
  %15 = mul nsw i128 %14, %.sroa.013.0.insert.insert
  %16 = srem i128 %15, %.sroa.011.0.insert.insert
  %17 = load i128, ptr %11, align 16, !tbaa !5
  %18 = add nsw i128 %17, %16
  %19 = srem i128 %18, %.sroa.011.0.insert.insert
  %.sroa.017.0.extract.trunc18 = trunc i128 %19 to i64
  %.sroa.3.0.extract.shift19 = lshr i128 %19, 64
  %.sroa.3.0.extract.trunc20 = trunc nuw i128 %.sroa.3.0.extract.shift19 to i64
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %7) #3
  br label %20

20:                                               ; preds = %6, %9
  %.sroa.017.0 = phi i64 [ %.sroa.017.0.extract.trunc18, %9 ], [ %2, %6 ]
  %.sroa.3.0 = phi i64 [ %.sroa.3.0.extract.trunc20, %9 ], [ %3, %6 ]
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.sroa.017.0, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.sroa.3.0, 1
  ret { i64, i64 } %.fca.1.insert
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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,ReassociatePass,SROAPass,SimplifyCFGPass