; LLVM IR from eyangch/competitive-programming :: AdventOfCode/2020/day13/2.ll (Z4fexpnx)

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

@MOD = external dso_local global i128, align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef { i64, i64 } @_Z4fexpnx(i64 noundef %0, i64 noundef %1, i64 noundef %2) #0 {
  %4 = alloca i128, align 16
  %5 = alloca i128, align 16
  %6 = alloca i128, align 16
  %7 = alloca i64, align 8
  %8 = alloca i128, align 16
  %9 = alloca i128, align 16
  %10 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 0
  store i64 %0, ptr %10, align 16
  %11 = getelementptr inbounds { i64, i64 }, ptr %5, i32 0, i32 1
  store i64 %1, ptr %11, align 8
  %12 = load i128, ptr %5, align 16, !tbaa !5
  store i128 %12, ptr %6, align 16, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #2
  store i128 1, ptr %8, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #2
  store i128 0, ptr %9, align 16, !tbaa !5
  br label %13

13:                                               ; preds = %38, %3
  %14 = load i128, ptr %9, align 16, !tbaa !5
  %15 = icmp slt i128 %14, 63
  br i1 %15, label %17, label %16

16:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #2
  br label %41

17:                                               ; preds = %13
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = load i128, ptr %9, align 16, !tbaa !5
  %20 = trunc i128 %19 to i64
  %21 = shl i64 1, %20
  %22 = and i64 %18, %21
  %23 = icmp ne i64 %22, 0
  br i1 %23, label %24, label %28

24:                                               ; preds = %17
  %25 = load i128, ptr %6, align 16, !tbaa !5
  %26 = load i128, ptr %8, align 16, !tbaa !5
  %27 = mul nsw i128 %26, %25
  store i128 %27, ptr %8, align 16, !tbaa !5
  br label %28

28:                                               ; preds = %24, %17
  %29 = load i128, ptr %6, align 16, !tbaa !5
  %30 = load i128, ptr %6, align 16, !tbaa !5
  %31 = mul nsw i128 %30, %29
  store i128 %31, ptr %6, align 16, !tbaa !5
  %32 = load i128, ptr @MOD, align 16, !tbaa !5
  %33 = load i128, ptr %6, align 16, !tbaa !5
  %34 = srem i128 %33, %32
  store i128 %34, ptr %6, align 16, !tbaa !5
  %35 = load i128, ptr @MOD, align 16, !tbaa !5
  %36 = load i128, ptr %8, align 16, !tbaa !5
  %37 = srem i128 %36, %35
  store i128 %37, ptr %8, align 16, !tbaa !5
  br label %38

38:                                               ; preds = %28
  %39 = load i128, ptr %9, align 16, !tbaa !5
  %40 = add nsw i128 %39, 1
  store i128 %40, ptr %9, align 16, !tbaa !5
  br label %13, !llvm.loop !11

41:                                               ; preds = %16
  %42 = load i128, ptr %8, align 16, !tbaa !5
  store i128 %42, ptr %4, align 16
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #2
  %43 = load { i64, i64 }, ptr %4, align 16
  ret { i64, i64 } %43
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = !{!"long long", !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"

@MOD = external dso_local local_unnamed_addr global i128, align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef { i64, i64 } @_Z4fexpnx(i64 noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.sroa.2.0.insert.ext = zext i64 %1 to i128
  %.sroa.2.0.insert.shift = shl nuw i128 %.sroa.2.0.insert.ext, 64
  %.sroa.0.0.insert.ext = zext i64 %0 to i128
  %.sroa.0.0.insert.insert = or disjoint i128 %.sroa.2.0.insert.shift, %.sroa.0.0.insert.ext
  %4 = load i128, ptr @MOD, align 16, !tbaa !5
  br label %6

5:                                                ; preds = %6
  %.sroa.011.0.extract.trunc = trunc i128 %13 to i64
  %.sroa.212.0.extract.shift = lshr i128 %13, 64
  %.sroa.212.0.extract.trunc = trunc nuw i128 %.sroa.212.0.extract.shift to i64
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.sroa.011.0.extract.trunc, 0
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.sroa.212.0.extract.trunc, 1
  ret { i64, i64 } %.fca.1.insert

6:                                                ; preds = %3, %6
  %.017 = phi i128 [ 0, %3 ], [ %14, %6 ]
  %.01316 = phi i128 [ 1, %3 ], [ %13, %6 ]
  %.01415 = phi i128 [ %.sroa.0.0.insert.insert, %3 ], [ %12, %6 ]
  %7 = trunc nuw i128 %.017 to i64
  %8 = shl nuw nsw i64 1, %7
  %9 = and i64 %8, %2
  %.not = icmp eq i64 %9, 0
  %10 = select i1 %.not, i128 1, i128 %.01415
  %.1 = mul nsw i128 %10, %.01316
  %11 = mul nsw i128 %.01415, %.01415
  %12 = srem i128 %11, %4
  %13 = srem i128 %.1, %4
  %14 = add nuw nsw i128 %.017, 1
  %15 = icmp ult i128 %.017, 62
  br i1 %15, label %6, label %5, !llvm.loop !9
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 = !{!6, !6, i64 0}
!6 = !{!"__int128", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass