; LLVM IR from aap/librw :: src/image.ll (ZN2rw5Image18registerFileFormatEPKcPFPS0_S2_EPFvS3_S2_E)

; 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.rw::ImageGlobals" = type { ptr, i32, [10 x %"struct.rw::FileAssociation"], i32 }
%"struct.rw::FileAssociation" = type { ptr, ptr, ptr }

@_ZN2rw17imageModuleOffsetE = external dso_local global i32, align 4
@_ZN2rw6engineE = external global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [74 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare noundef ptr @_ZN2rw10strdup_LOCEPKcjS1_(ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN2rw5Image18registerFileFormatEPKcPFPS0_S2_EPFvS3_S2_E(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 align 2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %10 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %11 = load i32, ptr @_ZN2rw17imageModuleOffsetE, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  store ptr %13, ptr %8, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 8, !tbaa !11
  %17 = icmp sge i32 %16, 10
  br i1 %17, label %18, label %19

18:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %52

19:                                               ; preds = %3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = call noundef ptr @_ZN2rw10strdup_LOCEPKcjS1_(ptr noundef %20, i32 noundef 196608, ptr noundef @.str.20)
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %24, i32 0, i32 3
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [10 x %"struct.rw::FileAssociation"], ptr %23, i64 0, i64 %27
  %29 = getelementptr inbounds %"struct.rw::FileAssociation", ptr %28, i32 0, i32 0
  store ptr %21, ptr %29, align 8, !tbaa !13
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 8, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10 x %"struct.rw::FileAssociation"], ptr %32, i64 0, i64 %36
  %38 = getelementptr inbounds %"struct.rw::FileAssociation", ptr %37, i32 0, i32 1
  store ptr %30, ptr %38, align 8, !tbaa !15
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %40, i32 0, i32 2
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %42, i32 0, i32 3
  %44 = load i32, ptr %43, align 8, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [10 x %"struct.rw::FileAssociation"], ptr %41, i64 0, i64 %45
  %47 = getelementptr inbounds %"struct.rw::FileAssociation", ptr %46, i32 0, i32 2
  store ptr %39, ptr %47, align 8, !tbaa !16
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %"struct.rw::ImageGlobals", ptr %48, i32 0, i32 3
  %50 = load i32, ptr %49, align 8, !tbaa !11
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %49, align 8, !tbaa !11
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %52

52:                                               ; preds = %19, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %53 = load i32, ptr %4, align 4
  ret i32 %53
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = { 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 256}
!12 = !{!"_ZTSN2rw12ImageGlobalsE", !6, i64 0, !10, i64 8, !7, i64 16, !10, i64 256}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN2rw15FileAssociationE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !6, i64 16}


; 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.rw::FileAssociation" = type { ptr, ptr, ptr }

@_ZN2rw17imageModuleOffsetE = external dso_local local_unnamed_addr global i32, align 4
@_ZN2rw6engineE = external local_unnamed_addr global ptr, align 8
@.str.20 = external hidden unnamed_addr constant [74 x i8], align 1

declare noundef ptr @_ZN2rw10strdup_LOCEPKcjS1_(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 0, 2) i32 @_ZN2rw5Image18registerFileFormatEPKcPFPS0_S2_EPFvS3_S2_E(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %5 = load i32, ptr @_ZN2rw17imageModuleOffsetE, align 4, !tbaa !9
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds i8, ptr %4, i64 %6
  %8 = getelementptr inbounds i8, ptr %7, i64 256
  %9 = load i32, ptr %8, align 8, !tbaa !11
  %10 = icmp sgt i32 %9, 9
  br i1 %10, label %20, label %11

11:                                               ; preds = %3
  %12 = tail call noundef ptr @_ZN2rw10strdup_LOCEPKcjS1_(ptr noundef %0, i32 noundef 196608, ptr noundef nonnull @.str.20)
  %13 = getelementptr inbounds i8, ptr %7, i64 16
  %14 = load i32, ptr %8, align 8, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [10 x %"struct.rw::FileAssociation"], ptr %13, i64 0, i64 %15
  store ptr %12, ptr %16, align 8, !tbaa !13
  %17 = getelementptr inbounds [10 x %"struct.rw::FileAssociation"], ptr %13, i64 0, i64 %15, i32 1
  store ptr %1, ptr %17, align 8, !tbaa !15
  %18 = getelementptr inbounds [10 x %"struct.rw::FileAssociation"], ptr %13, i64 0, i64 %15, i32 2
  store ptr %2, ptr %18, align 8, !tbaa !16
  %19 = add nsw i32 %14, 1
  store i32 %19, ptr %8, align 8, !tbaa !11
  br label %20

20:                                               ; preds = %3, %11
  %.0 = phi i32 [ 1, %11 ], [ 0, %3 ]
  ret i32 %.0
}

attributes #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 #1 = { 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" }

!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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 256}
!12 = !{!"_ZTSN2rw12ImageGlobalsE", !6, i64 0, !10, i64 8, !7, i64 16, !10, i64 256}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTSN2rw15FileAssociationE", !6, i64 0, !6, i64 8, !6, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !6, i64 16}


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