; LLVM IR from attractivechaos/plb2 :: src/c (bedcov)

; 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.intv_t = type { i64, i64, 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 ptr @gen_intv(i64 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i64, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  store i64 %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !11
  store i32 %3, ptr %8, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %13 = load i32, ptr %7, align 4, !tbaa !11
  %14 = shl i32 1, %13
  %15 = sub nsw i32 %14, 1
  %16 = sext i32 %15 to i64
  store i64 %16, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %17 = load i32, ptr %8, align 4, !tbaa !11
  %18 = shl i32 1, %17
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  store i64 %20, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %21 = load i64, ptr %5, align 8, !tbaa !5
  %22 = mul i64 %21, 32
  %23 = call noalias ptr @malloc(i64 noundef %22) #5
  store ptr %23, ptr %11, align 8, !tbaa !9
  store i64 0, ptr %12, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %58, %4
  %25 = load i64, ptr %12, align 8, !tbaa !5
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = icmp ult i64 %25, %26
  br i1 %27, label %28, label %61

28:                                               ; preds = %24
  %29 = load ptr, ptr %6, align 8, !tbaa !9
  %30 = call i32 @splitmix32(ptr noundef %29)
  %31 = zext i32 %30 to i64
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = and i64 %31, %32
  %34 = load ptr, ptr %11, align 8, !tbaa !9
  %35 = load i64, ptr %12, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.intv_t, ptr %34, i64 %35
  %37 = getelementptr inbounds %struct.intv_t, ptr %36, i32 0, i32 0
  store i64 %33, ptr %37, align 8, !tbaa !13
  %38 = load ptr, ptr %11, align 8, !tbaa !9
  %39 = load i64, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.intv_t, ptr %38, i64 %39
  %41 = getelementptr inbounds %struct.intv_t, ptr %40, i32 0, i32 0
  %42 = load i64, ptr %41, align 8, !tbaa !13
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = call i32 @splitmix32(ptr noundef %43)
  %45 = zext i32 %44 to i64
  %46 = load i64, ptr %10, align 8, !tbaa !5
  %47 = and i64 %45, %46
  %48 = add nsw i64 %42, %47
  %49 = load ptr, ptr %11, align 8, !tbaa !9
  %50 = load i64, ptr %12, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.intv_t, ptr %49, i64 %50
  %52 = getelementptr inbounds %struct.intv_t, ptr %51, i32 0, i32 1
  store i64 %48, ptr %52, align 8, !tbaa !15
  %53 = load i64, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %11, align 8, !tbaa !9
  %55 = load i64, ptr %12, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.intv_t, ptr %54, i64 %55
  %57 = getelementptr inbounds %struct.intv_t, ptr %56, i32 0, i32 3
  store i64 %53, ptr %57, align 8, !tbaa !16
  br label %58

58:                                               ; preds = %28
  %59 = load i64, ptr %12, align 8, !tbaa !5
  %60 = add i64 %59, 1
  store i64 %60, ptr %12, align 8, !tbaa !5
  br label %24, !llvm.loop !17

61:                                               ; preds = %24
  %62 = load ptr, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  ret ptr %62
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @splitmix32(ptr noundef) #3

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 allocsize(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 = { inlinehint 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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0) }

!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", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !6, i64 24}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.intv_t = type { i64, i64, i64, i64 }

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @gen_intv(i64 noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %notmask = shl nsw i32 -1, %2
  %5 = xor i32 %notmask, -1
  %notmask19 = shl nsw i32 -1, %3
  %6 = xor i32 %notmask19, -1
  %7 = shl i64 %0, 5
  %8 = tail call noalias ptr @malloc(i64 noundef %7) #3
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.020 = phi i64 [ %18, %.lr.ph ], [ 0, %4 ]
  %9 = tail call i32 @splitmix32(ptr noundef %1)
  %10 = and i32 %9, %5
  %11 = zext nneg i32 %10 to i64
  %12 = getelementptr inbounds %struct.intv_t, ptr %8, i64 %.020
  store i64 %11, ptr %12, align 8, !tbaa !5
  %13 = tail call i32 @splitmix32(ptr noundef %1)
  %14 = and i32 %13, %6
  %narrow = add nuw i32 %14, %10
  %15 = zext i32 %narrow to i64
  %16 = getelementptr inbounds i8, ptr %12, i64 8
  store i64 %15, ptr %16, align 8, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %12, i64 24
  store i64 %.020, ptr %17, align 8, !tbaa !11
  %18 = add nuw i64 %.020, 1
  %exitcond.not = icmp eq i64 %18, %0
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %4
  ret ptr %8
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @splitmix32(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { inlinehint 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 #3 = { nounwind allocsize(0) }

!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 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 24}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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