; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Tagl/Lib/dldlinker.ll (ZN9DLDLinker4InitEv)

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

%class.DLDLinker = type { %class.GraphicComponent, %class.Flags, ptr, ptr }
%class.GraphicComponent = type { ptr, i32, i32, [100 x %class.Flags], i32, %class.Flags, ptr, [8192 x i8] }
%class.Flags = type { i32 }

@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [39 x i8], align 1
@_ZN16GraphicComponent5_argvE = external global ptr, align 8
@.str.17 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind
declare ptr @getenv(ptr noundef) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624), i32 noundef) #2 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624), ptr noundef) #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9DLDLinker4InitEv(ptr noundef nonnull align 8 dereferenceable(8648) %0) #4 align 2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %7 = call ptr @getenv(ptr noundef @.str.15) #6
  store ptr %7, ptr %4, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %6, i32 noundef 3)
  %11 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %10, ptr noundef @.str.16)
  br label %16

12:                                               ; preds = %1
  %13 = load ptr, ptr @_ZN16GraphicComponent5_argvE, align 8, !tbaa !5
  %14 = getelementptr inbounds ptr, ptr %13, i64 0
  %15 = load ptr, ptr %14, align 8, !tbaa !5
  store ptr %15, ptr %4, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %12, %9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %28, label %19

19:                                               ; preds = %16
  %20 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %6, i32 noundef 1)
  %21 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %20, ptr noundef @.str.17)
  %22 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %6, i32 noundef 1)
  %23 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %22, ptr noundef @.str.18)
  %24 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %6, i32 noundef 1)
  %25 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %24, ptr noundef @.str.19)
  %26 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %6, i32 noundef 1)
  %27 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %26, ptr noundef @.str.20)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %37

28:                                               ; preds = %16
  %29 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %6, i32 noundef 3)
  %30 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %29, ptr noundef @.str.21)
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %30, ptr noundef %31)
  %33 = call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %32, ptr noundef @.str.5)
  br label %34

34:                                               ; preds = %28
  %35 = call i32 (ptr, ...) @printf(ptr noundef @.str.22)
  %36 = getelementptr inbounds %class.DLDLinker, ptr %6, i32 0, i32 1
  call void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4) %36, i32 noundef 3)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %37

37:                                               ; preds = %34, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %38 = load i32, ptr %2, align 4
  ret i32 %38
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare i32 @printf(ptr noundef, ...) #5

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


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

@.str.5 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [39 x i8], align 1
@_ZN16GraphicComponent5_argvE = external local_unnamed_addr global ptr, align 8
@.str.17 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [41 x i8], align 1
@.str.21 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: nofree nounwind memory(read)
declare noundef ptr @getenv(ptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624), ptr noundef) local_unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN9DLDLinker4InitEv(ptr noundef nonnull align 8 dereferenceable(8648) %0) local_unnamed_addr #3 align 2 {
  %2 = tail call ptr @getenv(ptr noundef nonnull @.str.15) #5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %5, label %.thread

.thread:                                          ; preds = %1
  %3 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %0, i32 noundef 3)
  %4 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %3, ptr noundef nonnull @.str.16)
  br label %17

5:                                                ; preds = %1
  %6 = load ptr, ptr @_ZN16GraphicComponent5_argvE, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %.not5 = icmp eq ptr %7, null
  br i1 %.not5, label %8, label %17

8:                                                ; preds = %5
  %9 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %0, i32 noundef 1)
  %10 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %9, ptr noundef nonnull @.str.17)
  %11 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %0, i32 noundef 1)
  %12 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %11, ptr noundef nonnull @.str.18)
  %13 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %0, i32 noundef 1)
  %14 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %13, ptr noundef nonnull @.str.19)
  %15 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %0, i32 noundef 1)
  %16 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %15, ptr noundef nonnull @.str.20)
  br label %24

17:                                               ; preds = %.thread, %5
  %.08 = phi ptr [ %2, %.thread ], [ %7, %5 ]
  %18 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentixEi(ptr noundef nonnull align 8 dereferenceable(8624) %0, i32 noundef 3)
  %19 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %18, ptr noundef nonnull @.str.21)
  %20 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %19, ptr noundef nonnull %.08)
  %21 = tail call noundef nonnull align 8 dereferenceable(8624) ptr @_ZN16GraphicComponentlsEPKc(ptr noundef nonnull align 8 dereferenceable(8624) %20, ptr noundef nonnull @.str.5)
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.22)
  %23 = getelementptr inbounds i8, ptr %0, i64 8624
  tail call void @_ZN5Flags3SetEi(ptr noundef nonnull align 4 dereferenceable(4) %23, i32 noundef 3)
  br label %24

24:                                               ; preds = %17, %8
  %.03 = phi i32 [ 1, %17 ], [ 0, %8 ]
  ret i32 %.03
}

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

attributes #0 = { nofree nounwind memory(read) "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 = { inlinehint mustprogress 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 = { inlinehint mustprogress 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 = { mustprogress 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 = { 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 #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++ TBAA"}


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