; LLVM IR from Aeternum-Veritas/Merry :: merry (merry_dynl)

; 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.MerryDynLoader = type { ptr, i64, i64 }
%struct.MerryDynEntry = type { [255 x i8], ptr, i8 }

@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [53 x i8], align 1
@loader = external hidden global %struct.MerryDynLoader, align 8
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_loader_init(i64 noundef %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i64 %0, ptr %3, align 8, !tbaa !5
  %5 = load ptr, ptr @stdout, align 8, !tbaa !9
  %6 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef @.str, ptr noundef null) #4
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = mul i64 272, %7
  %9 = call noalias ptr @malloc(i64 noundef %8) #5
  store ptr %9, ptr @loader, align 8, !tbaa !11
  %10 = load ptr, ptr @loader, align 8, !tbaa !11
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %15

12:                                               ; preds = %1
  %13 = load ptr, ptr @stderr, align 8, !tbaa !9
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str.1) #4
  store i8 0, ptr %2, align 1
  br label %34

15:                                               ; preds = %1
  %16 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %16, ptr getelementptr inbounds (%struct.MerryDynLoader, ptr @loader, i32 0, i32 2), align 8, !tbaa !13
  %17 = load i64, ptr %3, align 8, !tbaa !5
  store i64 %17, ptr getelementptr inbounds (%struct.MerryDynLoader, ptr @loader, i32 0, i32 1), align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %28, %15
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %31

23:                                               ; preds = %18
  %24 = load ptr, ptr @loader, align 8, !tbaa !11
  %25 = load i64, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MerryDynEntry, ptr %24, i64 %25
  %27 = getelementptr inbounds %struct.MerryDynEntry, ptr %26, i32 0, i32 2
  store i8 1, ptr %27, align 8, !tbaa !15
  br label %28

28:                                               ; preds = %23
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = add i64 %29, 1
  store i64 %30, ptr %4, align 8, !tbaa !5
  br label %18, !llvm.loop !17

31:                                               ; preds = %22
  %32 = load ptr, ptr @stdout, align 8, !tbaa !9
  %33 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.2, ptr noundef null) #4
  store i8 1, ptr %2, align 1
  br label %34

34:                                               ; preds = %31, %12
  %35 = load i8, ptr %2, align 1
  ret i8 %35
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

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

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

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

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 = { nounwind "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!12 = !{!"MerryDynLoader", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 16}
!14 = !{!12, !6, i64 8}
!15 = !{!16, !7, i64 264}
!16 = !{!"MerryDynEntry", !7, i64 0, !10, i64 256, !7, i64 264}
!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.MerryDynLoader = type { ptr, i64, i64 }
%struct.MerryDynEntry = type { [255 x i8], ptr, i8 }

@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [53 x i8], align 1
@loader = external hidden local_unnamed_addr global %struct.MerryDynLoader, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [65 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [65 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_loader_init(i64 noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @stdout, align 8, !tbaa !5
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str, ptr noundef null) #3
  %4 = mul i64 %0, 272
  %5 = tail call noalias ptr @malloc(i64 noundef %4) #4
  store ptr %5, ptr @loader, align 8, !tbaa !9
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %10

7:                                                ; preds = %1
  %8 = load ptr, ptr @stderr, align 8, !tbaa !5
  %9 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %8, ptr noundef nonnull @.str.1) #5
  br label %24

10:                                               ; preds = %1
  store i64 %0, ptr getelementptr inbounds (i8, ptr @loader, i64 16), align 8, !tbaa !12
  store i64 %0, ptr getelementptr inbounds (i8, ptr @loader, i64 8), align 8, !tbaa !13
  %.not = icmp eq i64 %0, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %10
  %xtraiter = and i64 %0, 3
  %11 = icmp ult i64 %0, 4
  br i1 %11, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %0, -4
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.09.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %23, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.09.epil = phi i64 [ %13, %.lr.ph.epil ], [ %.09.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %12 = getelementptr inbounds %struct.MerryDynEntry, ptr %5, i64 %.09.epil, i32 2
  store i8 1, ptr %12, align 8, !tbaa !14
  %13 = add nuw i64 %.09.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !16

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %10
  %14 = load ptr, ptr @stdout, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.2, ptr noundef null) #3
  br label %24

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.09 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %23, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %16 = getelementptr inbounds %struct.MerryDynEntry, ptr %5, i64 %.09, i32 2
  store i8 1, ptr %16, align 8, !tbaa !14
  %17 = or disjoint i64 %.09, 1
  %18 = getelementptr inbounds %struct.MerryDynEntry, ptr %5, i64 %17, i32 2
  store i8 1, ptr %18, align 8, !tbaa !14
  %19 = or disjoint i64 %.09, 2
  %20 = getelementptr inbounds %struct.MerryDynEntry, ptr %5, i64 %19, i32 2
  store i8 1, ptr %20, align 8, !tbaa !14
  %21 = or disjoint i64 %.09, 3
  %22 = getelementptr inbounds %struct.MerryDynEntry, ptr %5, i64 %21, i32 2
  store i8 1, ptr %22, align 8, !tbaa !14
  %23 = add nuw i64 %.09, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !18

24:                                               ; preds = %._crit_edge, %7
  %.08 = phi i8 [ 0, %7 ], [ 1, %._crit_edge ]
  ret i8 %.08
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

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

attributes #0 = { nofree 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 = { nofree nounwind "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 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 #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { cold 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, !6, i64 0}
!10 = !{!"MerryDynLoader", !6, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !7, i64 264}
!15 = !{!"MerryDynEntry", !7, i64 0, !6, i64 256, !7, i64 264}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.unroll.disable"}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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