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

; 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.MerryReader = type { i8, i8, i8, i8, %struct.MerryInstSection, %struct.MerryEAT, %struct.MerrySsT, %struct.MerryST, ptr, [2 x i64], i64, i64, ptr, i64, ptr, i64, ptr, ptr, ptr, ptr, i64, i64 }
%struct.MerryInstSection = type { i64, ptr, i64, i64 }
%struct.MerryEAT = type { ptr, i64, i64 }
%struct.MerrySsT = type { i64, i64, ptr, i8 }
%struct.MerryST = type { ptr, i64 }

@stdout = external global ptr, align 8
@stderr = external global ptr, align 8
@.str.25 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @merry_reader_addr_to_pg_index(i64 noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_reader_read_instructions(ptr noundef %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %9 = load ptr, ptr @stdout, align 8, !tbaa !5
  %10 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str.25, ptr noundef null) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MerryReader, ptr %11, i32 0, i32 4
  %13 = getelementptr inbounds %struct.MerryInstSection, ptr %12, i32 0, i32 0
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = udiv i64 %14, 8
  store i64 %15, ptr %4, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %16 = load i64, ptr %4, align 8, !tbaa !16
  %17 = udiv i64 %16, 131072
  store i64 %17, ptr %5, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %18 = load i64, ptr %4, align 8, !tbaa !16
  %19 = urem i64 %18, 131072
  store i64 %19, ptr %6, align 8, !tbaa !16
  %20 = load i64, ptr %5, align 8, !tbaa !16
  %21 = load i64, ptr %6, align 8, !tbaa !16
  %22 = icmp ugt i64 %21, 0
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, i32 1, i32 0
  %25 = sext i32 %24 to i64
  %26 = add i64 %20, %25
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MerryReader, ptr %27, i32 0, i32 4
  %29 = getelementptr inbounds %struct.MerryInstSection, ptr %28, i32 0, i32 2
  store i64 %26, ptr %29, align 8, !tbaa !17
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MerryReader, ptr %30, i32 0, i32 4
  %32 = getelementptr inbounds %struct.MerryInstSection, ptr %31, i32 0, i32 2
  %33 = load i64, ptr %32, align 8, !tbaa !17
  %34 = call noalias ptr @calloc(i64 noundef %33, i64 noundef 8) #6
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MerryReader, ptr %35, i32 0, i32 4
  %37 = getelementptr inbounds %struct.MerryInstSection, ptr %36, i32 0, i32 1
  store ptr %34, ptr %37, align 8, !tbaa !18
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.MerryReader, ptr %38, i32 0, i32 4
  %40 = getelementptr inbounds %struct.MerryInstSection, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = icmp ne ptr %41, null
  br i1 %42, label %46, label %43

43:                                               ; preds = %1
  %44 = load ptr, ptr @stderr, align 8, !tbaa !5
  %45 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %44, ptr noundef @.str.26) #5
  store i8 1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %90

46:                                               ; preds = %1
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.MerryReader, ptr %47, i32 0, i32 12
  %49 = load ptr, ptr %48, align 8, !tbaa !19
  %50 = call i64 @ftell(ptr noundef %49)
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MerryReader, ptr %51, i32 0, i32 4
  %53 = getelementptr inbounds %struct.MerryInstSection, ptr %52, i32 0, i32 3
  store i64 %50, ptr %53, align 8, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  store i64 0, ptr %8, align 8, !tbaa !16
  br label %54

54:                                               ; preds = %84, %46
  %55 = load i64, ptr %8, align 8, !tbaa !16
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MerryReader, ptr %56, i32 0, i32 5
  %58 = getelementptr inbounds %struct.MerryEAT, ptr %57, i32 0, i32 1
  %59 = load i64, ptr %58, align 8, !tbaa !21
  %60 = icmp ult i64 %55, %59
  br i1 %60, label %62, label %61

61:                                               ; preds = %54
  store i32 2, ptr %7, align 4
  br label %87

62:                                               ; preds = %54
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.MerryReader, ptr %64, i32 0, i32 4
  %66 = getelementptr inbounds %struct.MerryInstSection, ptr %65, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !18
  %68 = load i64, ptr %8, align 8, !tbaa !16
  %69 = getelementptr inbounds ptr, ptr %67, i64 %68
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MerryReader, ptr %71, i32 0, i32 5
  %73 = getelementptr inbounds %struct.MerryEAT, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !22
  %75 = load i64, ptr %8, align 8, !tbaa !16
  %76 = getelementptr inbounds i64, ptr %74, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !16
  %78 = call i64 @merry_reader_addr_to_pg_index(i64 noundef %77)
  %79 = call zeroext i8 @merry_reader_read_inst_page(ptr noundef %63, ptr noundef %70, i64 noundef %78)
  %80 = zext i8 %79 to i32
  %81 = icmp eq i32 %80, 1
  br i1 %81, label %82, label %83

82:                                               ; preds = %62
  store i8 1, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %87

83:                                               ; preds = %62
  br label %84

84:                                               ; preds = %83
  %85 = load i64, ptr %8, align 8, !tbaa !16
  %86 = add i64 %85, 1
  store i64 %86, ptr %8, align 8, !tbaa !16
  br label %54, !llvm.loop !23

87:                                               ; preds = %82, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %88 = load i32, ptr %7, align 4
  switch i32 %88, label %90 [
    i32 2, label %89
  ]

89:                                               ; preds = %87
  store i8 0, ptr %2, align 1
  store i32 1, ptr %7, align 4
  br label %90

90:                                               ; preds = %89, %87, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %91 = load i8, ptr %2, align 1
  ret i8 %91
}

declare i64 @ftell(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @merry_reader_read_inst_page(ptr noundef, ptr noundef, i64 noundef) #0

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #4

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 allocsize(0,1) "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0,1) }

!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, !12, i64 8}
!10 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 8, !13, i64 40, !14, i64 64, !15, i64 96, !6, i64 112, !7, i64 120, !12, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !6, i64 168, !12, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !12, i64 216, !12, i64 224}
!11 = !{!"MerryInstSection", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"long", !7, i64 0}
!13 = !{!"MerryEAT", !6, i64 0, !12, i64 8, !12, i64 16}
!14 = !{!"MerrySsT", !12, i64 0, !12, i64 8, !6, i64 16, !7, i64 24}
!15 = !{!"MerryST", !6, i64 0, !12, i64 8}
!16 = !{!12, !12, i64 0}
!17 = !{!10, !12, i64 24}
!18 = !{!10, !6, i64 16}
!19 = !{!10, !6, i64 152}
!20 = !{!10, !12, i64 32}
!21 = !{!10, !12, i64 48}
!22 = !{!10, !6, i64 40}
!23 = distinct !{!23, !24}
!24 = !{!"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"

@stdout = external local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.25 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [63 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i64 @merry_reader_addr_to_pg_index(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_reader_read_instructions(ptr 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.25, ptr noundef null) #3
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = lshr i64 %5, 20
  %7 = and i64 %5, 1048568
  %.not = icmp ne i64 %7, 0
  %8 = zext i1 %.not to i64
  %9 = add nuw nsw i64 %6, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %9, ptr %10, align 8, !tbaa !16
  %11 = tail call noalias ptr @calloc(i64 noundef %9, i64 noundef 8) #4
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %11, ptr %12, align 8, !tbaa !17
  %.not22 = icmp eq ptr %11, null
  br i1 %.not22, label %13, label %16

13:                                               ; preds = %1
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.26) #5
  br label %._crit_edge

16:                                               ; preds = %1
  %17 = getelementptr inbounds i8, ptr %0, i64 152
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = tail call i64 @ftell(ptr noundef %18)
  %20 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %19, ptr %20, align 8, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  %22 = getelementptr inbounds i8, ptr %0, i64 48
  %23 = load i64, ptr %22, align 8, !tbaa !20
  %.not2324.not = icmp eq i64 %23, 0
  br i1 %.not2324.not, label %._crit_edge, label %.lr.ph

24:                                               ; preds = %.lr.ph
  %25 = add nuw i64 %.025, 1
  %26 = load i64, ptr %22, align 8, !tbaa !20
  %.not23 = icmp ult i64 %25, %26
  br i1 %.not23, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !21

.lr.ph:                                           ; preds = %16, %24
  %.025 = phi i64 [ %25, %24 ], [ 0, %16 ]
  %27 = load ptr, ptr %12, align 8, !tbaa !17
  %28 = getelementptr inbounds ptr, ptr %27, i64 %.025
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %21, align 8, !tbaa !23
  %31 = getelementptr inbounds i64, ptr %30, i64 %.025
  %32 = load i64, ptr %31, align 8, !tbaa !24
  %33 = tail call i64 @merry_reader_addr_to_pg_index(i64 noundef %32)
  %34 = tail call zeroext i8 @merry_reader_read_inst_page(ptr noundef nonnull %0, ptr noundef %29, i64 noundef %33)
  %35 = icmp eq i8 %34, 1
  br i1 %35, label %._crit_edge.loopexit, label %24

._crit_edge.loopexit:                             ; preds = %.lr.ph, %24
  %36 = zext i1 %35 to i8
  br label %._crit_edge

._crit_edge:                                      ; preds = %16, %._crit_edge.loopexit, %13
  %.1 = phi i8 [ 1, %13 ], [ 0, %16 ], [ %36, %._crit_edge.loopexit ]
  ret i8 %.1
}

; Function Attrs: nofree nounwind
declare noundef i64 @ftell(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @merry_reader_read_inst_page(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 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 = { 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,zeroed") allocsize(0,1) 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,1) }
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, !12, i64 8}
!10 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !11, i64 8, !13, i64 40, !14, i64 64, !15, i64 96, !6, i64 112, !7, i64 120, !12, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !6, i64 168, !12, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !6, i64 208, !12, i64 216, !12, i64 224}
!11 = !{!"MerryInstSection", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 24}
!12 = !{!"long", !7, i64 0}
!13 = !{!"MerryEAT", !6, i64 0, !12, i64 8, !12, i64 16}
!14 = !{!"MerrySsT", !12, i64 0, !12, i64 8, !6, i64 16, !7, i64 24}
!15 = !{!"MerryST", !6, i64 0, !12, i64 8}
!16 = !{!10, !12, i64 24}
!17 = !{!10, !6, i64 16}
!18 = !{!10, !6, i64 152}
!19 = !{!10, !12, i64 32}
!20 = !{!10, !12, i64 48}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!10, !6, i64 40}
!24 = !{!12, !12, i64 0}


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