; 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 }

@stderr = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [78 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @merry_destroy_reader(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  br label %3

3:                                                ; preds = %1
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  %6 = xor i1 %5, true
  %7 = zext i1 %6 to i32
  %8 = sext i32 %7 to i64
  %9 = inttoptr i64 %8 to ptr
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %16

11:                                               ; preds = %3
  br label %12

12:                                               ; preds = %11
  %13 = load ptr, ptr @stderr, align 8, !tbaa !5
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef @.str.4, ptr noundef @.str.5, ptr noundef @.str.6, i32 noundef 104, ptr noundef @.str.7, ptr noundef @.str.8, ptr noundef @.str.6) #2
  br label %15

15:                                               ; preds = %12
  br label %16

16:                                               ; preds = %15, %3
  br label %17

17:                                               ; preds = %16
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MerryReader, ptr %18, i32 0, i32 5
  %20 = getelementptr inbounds %struct.MerryEAT, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %22 = icmp ne ptr %21, null
  br i1 %22, label %23, label %28

23:                                               ; preds = %17
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MerryReader, ptr %24, i32 0, i32 5
  %26 = getelementptr inbounds %struct.MerryEAT, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  call void @free(ptr noundef %27) #2
  br label %28

28:                                               ; preds = %23, %17
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MerryReader, ptr %29, i32 0, i32 6
  %31 = getelementptr inbounds %struct.MerrySsT, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %39

34:                                               ; preds = %28
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MerryReader, ptr %35, i32 0, i32 6
  %37 = getelementptr inbounds %struct.MerrySsT, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  call void @free(ptr noundef %38) #2
  br label %39

39:                                               ; preds = %34, %28
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.MerryReader, ptr %40, i32 0, i32 7
  %42 = getelementptr inbounds %struct.MerryST, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !17
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %50

45:                                               ; preds = %39
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MerryReader, ptr %46, i32 0, i32 7
  %48 = getelementptr inbounds %struct.MerryST, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  call void @free(ptr noundef %49) #2
  br label %50

50:                                               ; preds = %45, %39
  %51 = load ptr, ptr %2, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MerryReader, ptr %51, i32 0, i32 14
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %59

55:                                               ; preds = %50
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.MerryReader, ptr %56, i32 0, i32 14
  %58 = load ptr, ptr %57, align 8, !tbaa !18
  call void @free(ptr noundef %58) #2
  br label %59

59:                                               ; preds = %55, %50
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MerryReader, ptr %60, i32 0, i32 9
  %62 = getelementptr inbounds [2 x i64], ptr %61, i64 0, i64 0
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %68

64:                                               ; preds = %59
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MerryReader, ptr %65, i32 0, i32 9
  %67 = getelementptr inbounds [2 x i64], ptr %66, i64 0, i64 0
  call void @free(ptr noundef %67) #2
  br label %68

68:                                               ; preds = %64, %59
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %69) #2
  ret void
}

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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!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 80}
!17 = !{!10, !6, i64 96}
!18 = !{!10, !6, i64 168}


; 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [63 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [78 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @merry_destroy_reader(ptr noundef %0) local_unnamed_addr #2 {
  %.not.not = icmp eq ptr %0, null
  br i1 %.not.not, label %2, label %5

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

5:                                                ; preds = %1, %2
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %9, label %8

8:                                                ; preds = %5
  tail call void @free(ptr noundef nonnull %7) #4
  br label %9

9:                                                ; preds = %8, %5
  %10 = getelementptr inbounds i8, ptr %0, i64 80
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %.not16 = icmp eq ptr %11, null
  br i1 %.not16, label %13, label %12

12:                                               ; preds = %9
  tail call void @free(ptr noundef nonnull %11) #4
  br label %13

13:                                               ; preds = %12, %9
  %14 = getelementptr inbounds i8, ptr %0, i64 96
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %.not17 = icmp eq ptr %15, null
  br i1 %.not17, label %17, label %16

16:                                               ; preds = %13
  tail call void @free(ptr noundef nonnull %15) #4
  br label %17

17:                                               ; preds = %16, %13
  %18 = getelementptr inbounds i8, ptr %0, i64 168
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %.not18 = icmp eq ptr %19, null
  br i1 %.not18, label %21, label %20

20:                                               ; preds = %17
  tail call void @free(ptr noundef nonnull %19) #4
  br label %21

21:                                               ; preds = %17, %20
  %22 = getelementptr inbounds i8, ptr %0, i64 120
  tail call void @free(ptr noundef nonnull %22) #4
  tail call void @free(ptr noundef nonnull %0) #4
  ret void
}

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 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 #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 = { cold nounwind }
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, !6, i64 40}
!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 80}
!17 = !{!10, !6, i64 96}
!18 = !{!10, !6, i64 168}


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