; LLVM IR from ponylang/ponyc :: src/libponyc/ast (lexint)

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

%struct.lexint_t = type { i64, i64 }

; 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: nounwind uwtable
define dso_local zeroext i1 @lexint_accum(ptr noundef %0, i64 noundef %1, i64 noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i128, align 16
  %9 = alloca i128, align 16
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.lexint_t, ptr %11, i32 0, i32 1
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = zext i64 %13 to i128
  %15 = shl i128 %14, 64
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.lexint_t, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !13
  %19 = zext i64 %18 to i128
  %20 = or i128 %15, %19
  store i128 %20, ptr %8, align 16, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #2
  %21 = load i128, ptr %8, align 16, !tbaa !14
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = zext i64 %22 to i128
  %24 = mul i128 %21, %23
  store i128 %24, ptr %9, align 16, !tbaa !14
  %25 = load i128, ptr %9, align 16, !tbaa !14
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = zext i64 %26 to i128
  %28 = udiv i128 %25, %27
  %29 = load i128, ptr %8, align 16, !tbaa !14
  %30 = icmp ne i128 %28, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %51

32:                                               ; preds = %3
  %33 = load i64, ptr %6, align 8, !tbaa !9
  %34 = zext i64 %33 to i128
  %35 = load i128, ptr %9, align 16, !tbaa !14
  %36 = add i128 %35, %34
  store i128 %36, ptr %9, align 16, !tbaa !14
  %37 = load i128, ptr %9, align 16, !tbaa !14
  %38 = load i128, ptr %8, align 16, !tbaa !14
  %39 = icmp ult i128 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %32
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %51

41:                                               ; preds = %32
  %42 = load i128, ptr %9, align 16, !tbaa !14
  %43 = trunc i128 %42 to i64
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.lexint_t, ptr %44, i32 0, i32 0
  store i64 %43, ptr %45, align 8, !tbaa !13
  %46 = load i128, ptr %9, align 16, !tbaa !14
  %47 = lshr i128 %46, 64
  %48 = trunc i128 %47 to i64
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.lexint_t, ptr %49, i32 0, i32 1
  store i64 %48, ptr %50, align 8, !tbaa !11
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %51

51:                                               ; preds = %41, %40, %31
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #2
  %52 = load i1, ptr %4, align 1
  ret i1 %52
}

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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @lexint_accum(ptr nocapture noundef %0, i64 noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %6 = zext i64 %5 to i128
  %7 = shl nuw i128 %6, 64
  %8 = load i64, ptr %0, align 8, !tbaa !10
  %9 = zext i64 %8 to i128
  %10 = or disjoint i128 %7, %9
  %11 = zext i64 %2 to i128
  %mul = tail call { i128, i1 } @llvm.umul.with.overflow.i128(i128 %11, i128 %10)
  %mul.ov = extractvalue { i128, i1 } %mul, 1
  br i1 %mul.ov, label %20, label %12

12:                                               ; preds = %3
  %mul.val = extractvalue { i128, i1 } %mul, 0
  %13 = zext i64 %1 to i128
  %14 = add i128 %mul.val, %13
  %15 = icmp ult i128 %14, %10
  br i1 %15, label %20, label %16

16:                                               ; preds = %12
  %17 = trunc i128 %14 to i64
  store i64 %17, ptr %0, align 8, !tbaa !10
  %18 = lshr i128 %14, 64
  %19 = trunc nuw i128 %18 to i64
  store i64 %19, ptr %4, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %12, %3, %16
  %.0 = phi i1 [ true, %16 ], [ false, %3 ], [ false, %12 ]
  ret i1 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i128, i1 } @llvm.umul.with.overflow.i128(i128, i128) #1

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

!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, !7, i64 8}
!6 = !{!"lexint_t", !7, i64 0, !7, i64 8}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 0}


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