; 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
@.str.10 = external hidden unnamed_addr constant [43 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

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_reader_is_file_fit_to_read(ptr noundef %0) #2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MerryReader, ptr %6, i32 0, i32 12
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = call i32 @fseek(ptr noundef %8, i64 noundef 0, i32 noundef 2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MerryReader, ptr %10, i32 0, i32 12
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = call i64 @ftell(ptr noundef %12)
  store i64 %13, ptr %4, align 8, !tbaa !16
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MerryReader, ptr %14, i32 0, i32 12
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  call void @rewind(ptr noundef %16)
  %17 = load i64, ptr %4, align 8, !tbaa !16
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MerryReader, ptr %18, i32 0, i32 13
  store i64 %17, ptr %19, align 8, !tbaa !17
  %20 = load i64, ptr %4, align 8, !tbaa !16
  %21 = icmp ult i64 %20, 40
  %22 = xor i1 %21, true
  %23 = xor i1 %22, true
  %24 = zext i1 %23 to i32
  %25 = sext i32 %24 to i64
  %26 = call i64 @llvm.expect.i64(i64 %25, i64 0)
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %1
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %32

29:                                               ; preds = %1
  %30 = load ptr, ptr @stdout, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.10, ptr noundef null) #5
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %32

32:                                               ; preds = %29, %28
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %33 = load i8, ptr %2, align 1
  ret i8 %33
}

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

declare i64 @ftell(ptr noundef) #3

declare void @rewind(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #4

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 = { 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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(none) }
attributes #5 = { 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 152}
!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 160}


; 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
@.str.10 = external hidden unnamed_addr constant [43 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 uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_reader_is_file_fit_to_read(ptr nocapture noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 152
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = tail call i32 @fseek(ptr noundef %3, i64 noundef 0, i32 noundef 2)
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = tail call i64 @ftell(ptr noundef %5)
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @rewind(ptr noundef %7)
  %8 = getelementptr inbounds i8, ptr %0, i64 160
  store i64 %6, ptr %8, align 8, !tbaa !15
  %9 = icmp ult i64 %6, 40
  br i1 %9, label %13, label %10, !prof !16

10:                                               ; preds = %1
  %11 = load ptr, ptr @stdout, align 8, !tbaa !17
  %12 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %11, ptr noundef nonnull @.str.10, ptr noundef null) #2
  br label %13

13:                                               ; preds = %1, %10
  %.0 = phi i8 [ 0, %10 ], [ 1, %1 ]
  ret i8 %.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 @ftell(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #0

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 = { 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 #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, !11, i64 152}
!6 = !{!"MerryReader", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 3, !9, i64 8, !12, i64 40, !13, i64 64, !14, i64 96, !11, i64 112, !7, i64 120, !10, i64 136, !10, i64 144, !11, i64 152, !10, i64 160, !11, i64 168, !10, i64 176, !11, i64 184, !11, i64 192, !11, i64 200, !11, i64 208, !10, i64 216, !10, i64 224}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"MerryInstSection", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24}
!10 = !{!"long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"MerryEAT", !11, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!"MerrySsT", !10, i64 0, !10, i64 8, !11, i64 16, !7, i64 24}
!14 = !{!"MerryST", !11, i64 0, !10, i64 8}
!15 = !{!6, !10, i64 160}
!16 = !{!"branch_weights", !"expected", i32 1, i32 2000}
!17 = !{!11, !11, i64 0}


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