; 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.44 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [41 x i8], align 1

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

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

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @merry_reader_read_st(ptr noundef %0) #2 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr @stdout, align 8, !tbaa !5
  %5 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %4, ptr noundef @.str.44, ptr noundef null) #4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.MerryReader, ptr %6, i32 0, i32 7
  %8 = getelementptr inbounds %struct.MerryST, ptr %7, i32 0, i32 1
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = call noalias ptr @malloc(i64 noundef %9) #5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MerryReader, ptr %11, i32 0, i32 7
  %13 = getelementptr inbounds %struct.MerryST, ptr %12, i32 0, i32 0
  store ptr %10, ptr %13, align 8, !tbaa !16
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MerryReader, ptr %14, i32 0, i32 7
  %16 = getelementptr inbounds %struct.MerryST, ptr %15, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = icmp eq ptr %17, null
  br i1 %18, label %19, label %22

19:                                               ; preds = %1
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.45) #4
  store i8 1, ptr %2, align 1
  br label %48

22:                                               ; preds = %1
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MerryReader, ptr %23, i32 0, i32 7
  %25 = getelementptr inbounds %struct.MerryST, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.MerryReader, ptr %27, i32 0, i32 7
  %29 = getelementptr inbounds %struct.MerryST, ptr %28, i32 0, i32 1
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.MerryReader, ptr %31, i32 0, i32 12
  %33 = load ptr, ptr %32, align 8, !tbaa !17
  %34 = call i64 @fread(ptr noundef %26, i64 noundef 1, i64 noundef %30, ptr noundef %33)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MerryReader, ptr %35, i32 0, i32 7
  %37 = getelementptr inbounds %struct.MerryST, ptr %36, i32 0, i32 1
  %38 = load i64, ptr %37, align 8, !tbaa !9
  %39 = icmp ne i64 %34, %38
  br i1 %39, label %40, label %47

40:                                               ; preds = %22
  %41 = load ptr, ptr @stderr, align 8, !tbaa !5
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %41, ptr noundef @.str.46) #4
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MerryReader, ptr %43, i32 0, i32 7
  %45 = getelementptr inbounds %struct.MerryST, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !16
  call void @free(ptr noundef %46) #4
  store i8 1, ptr %2, align 1
  br label %48

47:                                               ; preds = %22
  store i8 0, ptr %2, align 1
  br label %48

48:                                               ; preds = %47, %40, %19
  %49 = load i8, ptr %2, align 1
  ret i8 %49
}

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr 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 = { 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 #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 104}
!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, !6, i64 96}
!17 = !{!10, !6, i64 152}


; 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.44 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [41 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: 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_reader_read_st(ptr nocapture noundef %0) local_unnamed_addr #3 {
  %2 = load ptr, ptr @stdout, align 8, !tbaa !5
  %3 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %2, ptr noundef nonnull @.str.44, ptr noundef null) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 96
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  %6 = load i64, ptr %5, align 8, !tbaa !9
  %7 = tail call noalias ptr @malloc(i64 noundef %6) #5
  store ptr %7, ptr %4, align 8, !tbaa !16
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %12

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

12:                                               ; preds = %1
  %13 = getelementptr inbounds i8, ptr %0, i64 152
  %14 = load ptr, ptr %13, align 8, !tbaa !17
  %15 = tail call i64 @fread(ptr noundef nonnull %7, i64 noundef 1, i64 noundef %6, ptr noundef %14)
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %.not = icmp eq i64 %15, %16
  br i1 %.not, label %21, label %17

17:                                               ; preds = %12
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.46) #6
  %20 = load ptr, ptr %4, align 8, !tbaa !16
  tail call void @free(ptr noundef %20) #4
  br label %21

21:                                               ; preds = %12, %17, %9
  %.0 = phi i8 [ 1, %9 ], [ 1, %17 ], [ 0, %12 ]
  ret i8 %.0
}

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, 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 = { 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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 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) }
attributes #6 = { 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 104}
!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, !6, i64 96}
!17 = !{!10, !6, i64 152}


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