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

; 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.MerryDynLoader = type { ptr, i64, i64 }
%struct.MerryDynEntry = type { [255 x i8], ptr, i8 }

@stdout = external global ptr, align 8
@loader = external hidden global %struct.MerryDynLoader, align 8
@.str.4 = external hidden unnamed_addr constant [40 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 [50 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [47 x i8], align 1

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

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

14:                                               ; preds = %2
  br label %66

15:                                               ; preds = %2
  %16 = load i64, ptr getelementptr inbounds (%struct.MerryDynLoader, ptr @loader, i32 0, i32 2), align 8, !tbaa !13
  %17 = icmp ugt i64 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %15
  %19 = call i64 @merry_loader_find_free_handle()
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %19, ptr %20, align 8, !tbaa !9
  br label %32

21:                                               ; preds = %15
  %22 = call zeroext i8 @merry_loader_add_entry()
  %23 = zext i8 %22 to i32
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load ptr, ptr @stdout, align 8, !tbaa !5
  %27 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %26, ptr noundef @.str.7, ptr noundef null) #2
  br label %70

28:                                               ; preds = %21
  %29 = load i64, ptr getelementptr inbounds (%struct.MerryDynLoader, ptr @loader, i32 0, i32 1), align 8, !tbaa !11
  %30 = sub i64 %29, 1
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  store i64 %30, ptr %31, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %28, %18
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = call ptr @dlopen(ptr noundef %33, i32 noundef 258) #2
  %35 = load ptr, ptr @loader, align 8, !tbaa !14
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.MerryDynEntry, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.MerryDynEntry, ptr %38, i32 0, i32 1
  store ptr %34, ptr %39, align 8, !tbaa !15
  %40 = load ptr, ptr @loader, align 8, !tbaa !14
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = getelementptr inbounds %struct.MerryDynEntry, ptr %40, i64 %42
  %44 = getelementptr inbounds %struct.MerryDynEntry, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !15
  %46 = icmp eq ptr %45, null
  br i1 %46, label %47, label %50

47:                                               ; preds = %32
  %48 = load ptr, ptr @stdout, align 8, !tbaa !5
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str.8, ptr noundef null) #2
  br label %70

50:                                               ; preds = %32
  %51 = load ptr, ptr @loader, align 8, !tbaa !14
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load i64, ptr %52, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.MerryDynEntry, ptr %51, i64 %53
  %55 = getelementptr inbounds %struct.MerryDynEntry, ptr %54, i32 0, i32 2
  store i8 0, ptr %55, align 8, !tbaa !17
  %56 = load i64, ptr getelementptr inbounds (%struct.MerryDynLoader, ptr @loader, i32 0, i32 2), align 8, !tbaa !13
  %57 = add i64 %56, -1
  store i64 %57, ptr getelementptr inbounds (%struct.MerryDynLoader, ptr @loader, i32 0, i32 2), align 8, !tbaa !13
  %58 = load ptr, ptr @loader, align 8, !tbaa !14
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = getelementptr inbounds %struct.MerryDynEntry, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.MerryDynEntry, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds [255 x i8], ptr %62, i64 0, i64 0
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = call ptr @strcpy(ptr noundef %63, ptr noundef %64) #2
  br label %66

66:                                               ; preds = %50, %14
  %67 = load ptr, ptr @stdout, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.9, ptr noundef @.str.5, ptr noundef %68, ptr noundef @.str.6) #2
  store i8 1, ptr %3, align 1
  br label %74

70:                                               ; preds = %47, %25
  %71 = load ptr, ptr @stdout, align 8, !tbaa !5
  %72 = load ptr, ptr %4, align 8, !tbaa !5
  %73 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %71, ptr noundef @.str.10, ptr noundef @.str.5, ptr noundef %72, ptr noundef @.str.6) #2
  store i8 0, ptr %3, align 1
  br label %74

74:                                               ; preds = %70, %66
  %75 = load i8, ptr %3, align 1
  ret i8 %75
}

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

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i64 @merry_loader_find_free_handle() #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @merry_loader_add_entry() #1

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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"MerryDynLoader", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !6, i64 256}
!16 = !{!"MerryDynEntry", !7, i64 0, !6, i64 256, !7, i64 264}
!17 = !{!16, !7, i64 264}


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

%struct.MerryDynLoader = type { ptr, i64, i64 }
%struct.MerryDynEntry = type { [255 x i8], ptr, i8 }

@stdout = external local_unnamed_addr global ptr, align 8
@loader = external hidden local_unnamed_addr global %struct.MerryDynLoader, align 8
@.str.4 = external hidden unnamed_addr constant [40 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 [50 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [53 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [39 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [47 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: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @merry_loader_loadLib(ptr noundef %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr @stdout, 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 %0, ptr noundef nonnull @.str.6) #4
  %5 = tail call i64 @merry_loader_check_entry(ptr noundef %0)
  store i64 %5, ptr %1, align 8, !tbaa !9
  %6 = load i64, ptr getelementptr inbounds (i8, ptr @loader, i64 8), align 8, !tbaa !11
  %7 = icmp ult i64 %5, %6
  br i1 %7, label %34, label %8

8:                                                ; preds = %2
  %9 = load i64, ptr getelementptr inbounds (i8, ptr @loader, i64 16), align 8, !tbaa !13
  %.not = icmp eq i64 %9, 0
  br i1 %.not, label %12, label %10

10:                                               ; preds = %8
  %11 = tail call i64 @merry_loader_find_free_handle()
  br label %18

12:                                               ; preds = %8
  %13 = tail call zeroext i8 @merry_loader_add_entry()
  %14 = icmp eq i8 %13, 0
  br i1 %14, label %31, label %15

15:                                               ; preds = %12
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @loader, i64 8), align 8, !tbaa !11
  %17 = add i64 %16, -1
  br label %18

18:                                               ; preds = %15, %10
  %storemerge = phi i64 [ %17, %15 ], [ %11, %10 ]
  store i64 %storemerge, ptr %1, align 8, !tbaa !9
  %19 = tail call ptr @dlopen(ptr noundef %0, i32 noundef 258) #4
  %20 = load ptr, ptr @loader, align 8, !tbaa !14
  %21 = load i64, ptr %1, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.MerryDynEntry, ptr %20, i64 %21, i32 1
  store ptr %19, ptr %22, align 8, !tbaa !15
  %23 = icmp eq ptr %19, null
  br i1 %23, label %31, label %24

24:                                               ; preds = %18
  %25 = getelementptr inbounds %struct.MerryDynEntry, ptr %20, i64 %21, i32 2
  store i8 0, ptr %25, align 8, !tbaa !17
  %26 = load i64, ptr getelementptr inbounds (i8, ptr @loader, i64 16), align 8, !tbaa !13
  %27 = add i64 %26, -1
  store i64 %27, ptr getelementptr inbounds (i8, ptr @loader, i64 16), align 8, !tbaa !13
  %28 = load i64, ptr %1, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.MerryDynEntry, ptr %20, i64 %28
  %30 = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %29, ptr noundef nonnull dereferenceable(1) %0) #4
  br label %34

31:                                               ; preds = %18, %12
  %.str.8.sink = phi ptr [ @.str.7, %12 ], [ @.str.8, %18 ]
  %32 = load ptr, ptr @stdout, align 8, !tbaa !5
  %33 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef nonnull %.str.8.sink, ptr noundef null) #4
  br label %34

34:                                               ; preds = %24, %2, %31
  %.str.10.sink = phi ptr [ @.str.10, %31 ], [ @.str.9, %2 ], [ @.str.9, %24 ]
  %.0 = phi i8 [ 0, %31 ], [ 1, %2 ], [ 1, %24 ]
  %35 = load ptr, ptr @stdout, align 8, !tbaa !5
  %36 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef nonnull %.str.10.sink, ptr noundef nonnull @.str.5, ptr noundef %0, ptr noundef nonnull @.str.6) #4
  ret i8 %.0
}

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

; Function Attrs: nounwind
declare ptr @dlopen(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i64 @merry_loader_find_free_handle() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden zeroext i8 @merry_loader_add_entry() 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 "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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, !10, i64 8}
!12 = !{!"MerryDynLoader", !6, i64 0, !10, i64 8, !10, i64 16}
!13 = !{!12, !10, i64 16}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !6, i64 256}
!16 = !{!"MerryDynEntry", !7, i64 0, !6, i64 256, !7, i64 264}
!17 = !{!16, !7, i64 264}


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