; 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.23 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [72 x i8], align 1

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

; 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

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #2

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

15:                                               ; preds = %3
  store i8 0, ptr %4, align 1
  br label %90

16:                                               ; preds = %3
  %17 = call ptr @merry_reader_get_mem_from_os(i64 noundef 1)
  store ptr %17, ptr %6, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %29, label %20

20:                                               ; preds = %16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MerryReader, ptr %21, i32 0, i32 4
  %23 = getelementptr inbounds %struct.MerryInstSection, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MerryReader, ptr %25, i32 0, i32 4
  %27 = getelementptr inbounds %struct.MerryInstSection, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !17
  call void @merry_reader_give_mem_to_os(ptr noundef %24, i64 noundef %28)
  store i8 1, ptr %4, align 1
  br label %90

29:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %30 = load ptr, ptr %5, 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 3
  %33 = load i64, ptr %32, align 8, !tbaa !18
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = mul i64 %34, 1048576
  %36 = add i64 %33, %35
  store i64 %36, ptr %8, align 8, !tbaa !9
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.MerryReader, ptr %37, i32 0, i32 12
  %39 = load ptr, ptr %38, align 8, !tbaa !19
  %40 = load i64, ptr %8, align 8, !tbaa !9
  %41 = call i32 @fseek(ptr noundef %39, i64 noundef %40, i32 noundef 0)
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MerryReader, ptr %43, i32 0, i32 4
  %45 = getelementptr inbounds %struct.MerryInstSection, ptr %44, i32 0, i32 2
  %46 = load i64, ptr %45, align 8, !tbaa !17
  %47 = sub i64 %46, 1
  %48 = icmp eq i64 %42, %47
  br i1 %48, label %49, label %76

49:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.MerryReader, ptr %50, i32 0, i32 4
  %52 = getelementptr inbounds %struct.MerryInstSection, ptr %51, i32 0, i32 0
  %53 = load i64, ptr %52, align 8, !tbaa !20
  %54 = load i64, ptr %7, align 8, !tbaa !9
  %55 = mul i64 %54, 1048576
  %56 = sub i64 %53, %55
  %57 = udiv i64 %56, 8
  store i64 %57, ptr %9, align 8, !tbaa !9
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load i64, ptr %9, align 8, !tbaa !9
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MerryReader, ptr %60, i32 0, i32 12
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = call i64 @fread(ptr noundef %58, i64 noundef 8, i64 noundef %59, ptr noundef %62)
  %64 = load i64, ptr %9, align 8, !tbaa !9
  %65 = icmp ne i64 %63, %64
  br i1 %65, label %66, label %69

66:                                               ; preds = %49
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.24) #4
  store i8 1, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %73

69:                                               ; preds = %49
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = load i64, ptr %9, align 8, !tbaa !9
  %72 = mul i64 %71, 8
  call void @merry_convert_to_big_endian(ptr noundef %70, i64 noundef %72)
  store i32 0, ptr %10, align 4
  br label %73

73:                                               ; preds = %69, %66
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %74 = load i32, ptr %10, align 4
  switch i32 %74, label %89 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  br label %88

76:                                               ; preds = %29
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.MerryReader, ptr %78, i32 0, i32 12
  %80 = load ptr, ptr %79, align 8, !tbaa !19
  %81 = call i64 @fread(ptr noundef %77, i64 noundef 8, i64 noundef 131072, ptr noundef %80)
  %82 = icmp ne i64 %81, 131072
  br i1 %82, label %83, label %86

83:                                               ; preds = %76
  %84 = load ptr, ptr @stderr, align 8, !tbaa !5
  %85 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %84, ptr noundef @.str.24) #4
  store i8 1, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %89

86:                                               ; preds = %76
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  call void @merry_convert_to_big_endian(ptr noundef %87, i64 noundef 1048576)
  br label %88

88:                                               ; preds = %86, %75
  store i8 0, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %89

89:                                               ; preds = %88, %83, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %90

90:                                               ; preds = %89, %20, %15
  %91 = load i8, ptr %4, align 1
  ret i8 %91
}

; Function Attrs: nounwind uwtable
declare hidden ptr @merry_reader_get_mem_from_os(i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @merry_reader_give_mem_to_os(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @merry_convert_to_big_endian(ptr noundef, i64 noundef) #3

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

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


; 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.23 = external hidden unnamed_addr constant [45 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [72 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_reader_read_inst_page(ptr nocapture noundef readonly %0, ptr noundef readnone %1, i64 noundef %2) local_unnamed_addr #1 {
  %4 = load ptr, ptr @stdout, align 8, !tbaa !5
  %5 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef nonnull @.str.23, ptr noundef null) #2
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %6, label %43

6:                                                ; preds = %3
  %7 = tail call ptr @merry_reader_get_mem_from_os(i64 noundef 1)
  %.not25 = icmp eq ptr %7, null
  br i1 %.not25, label %8, label %13

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load i64, ptr %11, align 8, !tbaa !16
  tail call void @merry_reader_give_mem_to_os(ptr noundef %10, i64 noundef %12)
  br label %43

13:                                               ; preds = %6
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i64, ptr %14, align 8, !tbaa !17
  %16 = shl i64 %2, 20
  %17 = add i64 %15, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 152
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = tail call i32 @fseek(ptr noundef %19, i64 noundef %17, i32 noundef 0)
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  %22 = load i64, ptr %21, align 8, !tbaa !16
  %23 = add i64 %22, -1
  %24 = icmp eq i64 %23, %2
  br i1 %24, label %25, label %36

25:                                               ; preds = %13
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !19
  %28 = sub i64 %27, %16
  %29 = lshr i64 %28, 3
  %30 = load ptr, ptr %18, align 8, !tbaa !18
  %31 = tail call i64 @fread(ptr noundef nonnull %7, i64 noundef 8, i64 noundef %29, ptr noundef %30)
  %.not27 = icmp eq i64 %31, %29
  br i1 %.not27, label %.thread, label %33

.thread:                                          ; preds = %25
  %32 = and i64 %28, -8
  tail call void @merry_convert_to_big_endian(ptr noundef nonnull %7, i64 noundef %32)
  br label %43

33:                                               ; preds = %25
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.24) #3
  br label %43

36:                                               ; preds = %13
  %37 = load ptr, ptr %18, align 8, !tbaa !18
  %38 = tail call i64 @fread(ptr noundef nonnull %7, i64 noundef 8, i64 noundef 131072, ptr noundef %37)
  %.not26 = icmp eq i64 %38, 131072
  br i1 %.not26, label %42, label %39

39:                                               ; preds = %36
  %40 = load ptr, ptr @stderr, align 8, !tbaa !5
  %41 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %40, ptr noundef nonnull @.str.24) #3
  br label %43

42:                                               ; preds = %36
  tail call void @merry_convert_to_big_endian(ptr noundef nonnull %7, i64 noundef 1048576)
  br label %43

43:                                               ; preds = %42, %.thread, %33, %39, %3, %8
  %.2 = phi i8 [ 1, %8 ], [ 0, %3 ], [ 1, %33 ], [ 1, %39 ], [ 0, %.thread ], [ 0, %42 ]
  ret i8 %.2
}

; Function Attrs: nounwind uwtable
declare hidden ptr @merry_reader_get_mem_from_os(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @merry_reader_give_mem_to_os(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @merry_convert_to_big_endian(ptr noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 }
attributes #3 = { 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 16}
!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, !12, i64 32}
!18 = !{!10, !6, i64 152}
!19 = !{!10, !12, i64 8}


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