; LLVM IR from aap/librw :: src/engine.ll (ZN2rw6Engine4stopEv)

; 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::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Error" = type { i32, i32 }
%"struct.rw::Engine" = type { ptr, ptr, %"struct.rw::LinkList", %"struct.rw::FileFunctions", [13 x ptr], %"struct.rw::Device", ptr }
%"struct.rw::FileFunctions" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%"struct.rw::Device" = type { float, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@_ZN2rw6engineE = external dso_local global ptr, align 8
@_ZN2rw6Engine9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw6Engine5stateE = external dso_local global i32, align 4
@_ZN2rw6Driver9s_plglistE = external dso_local global [13 x %"struct.rw::PluginList"], align 16
@stderr = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 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

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

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) #2

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw6Engine4stopEv() #3 align 2 {
  %1 = alloca %"struct.rw::Error", align 4
  %2 = alloca i32, align 4
  %3 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %8, label %5

5:                                                ; preds = %0
  %6 = load i32, ptr @_ZN2rw6Engine5stateE, align 4, !tbaa !9
  %7 = icmp ne i32 %6, 3
  br i1 %7, label %8, label %18

8:                                                ; preds = %5, %0
  br label %9

9:                                                ; preds = %8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  %10 = getelementptr inbounds %"struct.rw::Error", ptr %1, i32 0, i32 0
  store i32 0, ptr %10, align 4, !tbaa !11
  %11 = getelementptr inbounds %"struct.rw::Error", ptr %1, i32 0, i32 1
  store i32 -2147483647, ptr %11, align 4, !tbaa !14
  %12 = load ptr, ptr @stderr, align 8, !tbaa !5
  %13 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef @.str.3, ptr noundef @.str.4, i32 noundef 366) #4
  %14 = load ptr, ptr @stderr, align 8, !tbaa !5
  %15 = call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483647)
  %16 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef @.str.5, ptr noundef %15) #4
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  br label %17

17:                                               ; preds = %9
  br label %43

18:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !15
  br label %19

19:                                               ; preds = %33, %18
  %20 = load i32, ptr %2, align 4, !tbaa !15
  %21 = icmp ult i32 %20, 13
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %36

23:                                               ; preds = %19
  %24 = load i32, ptr %2, align 4, !tbaa !15
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds [13 x %"struct.rw::PluginList"], ptr @_ZN2rw6Driver9s_plglistE, i64 0, i64 %25
  %27 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %28 = getelementptr inbounds %"struct.rw::Engine", ptr %27, i32 0, i32 4
  %29 = load i32, ptr %2, align 4, !tbaa !15
  %30 = zext i32 %29 to i64
  %31 = getelementptr inbounds [13 x ptr], ptr %28, i64 0, i64 %30
  %32 = load ptr, ptr %31, align 8, !tbaa !5
  call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) %26, ptr noundef %32)
  br label %33

33:                                               ; preds = %23
  %34 = load i32, ptr %2, align 4, !tbaa !15
  %35 = add i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !15
  br label %19, !llvm.loop !16

36:                                               ; preds = %22
  %37 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw6Engine9s_plglistE, ptr noundef %37)
  %38 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.rw::Engine", ptr %38, i32 0, i32 5
  %40 = getelementptr inbounds %"struct.rw::Device", ptr %39, i32 0, i32 17
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = call noundef i32 %41(i32 noundef 1, ptr noundef null, i32 noundef 0)
  store i32 2, ptr @_ZN2rw6Engine5stateE, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %36, %17
  ret void
}

declare void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #2

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 = { "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 = { 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 = !{!"_ZTSN2rw6Engine5StateE", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTSN2rw5ErrorE", !13, i64 0, !13, i64 4}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 4}
!15 = !{!13, !13, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 320}
!19 = !{!"_ZTSN2rw6EngineE", !6, i64 0, !6, i64 8, !20, i64 16, !22, i64 32, !7, i64 88, !23, i64 192, !6, i64 328}
!20 = !{!"_ZTSN2rw8LinkListE", !21, i64 0}
!21 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!22 = !{!"_ZTSN2rw13FileFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!23 = !{!"_ZTSN2rw6DeviceE", !24, i64 0, !24, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!24 = !{!"float", !7, i64 0}


; 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::PluginList" = type { i32, i32, %"struct.rw::LinkList" }
%"struct.rw::LinkList" = type { %"struct.rw::LLLink" }
%"struct.rw::LLLink" = type { ptr, ptr }
%"struct.rw::Error" = type { i32, i32 }

@_ZN2rw6engineE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN2rw6Engine9s_plglistE = external dso_local global %"struct.rw::PluginList", align 8
@_ZN2rw6Engine5stateE = external dso_local local_unnamed_addr global i32, align 4
@_ZN2rw6Driver9s_plglistE = external dso_local global [13 x %"struct.rw::PluginList"], align 16
@stderr = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [58 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

declare noundef ptr @_ZN2rw9dbgsprintEjz(i32 noundef, ...) local_unnamed_addr #2

declare void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw6Engine4stopEv() local_unnamed_addr #3 align 2 {
  %1 = alloca %"struct.rw::Error", align 4
  %2 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  %4 = load i32, ptr @_ZN2rw6Engine5stateE, align 4
  %5 = icmp ne i32 %4, 3
  %or.cond = select i1 %3, i1 true, i1 %5
  br i1 %or.cond, label %49, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %6 = getelementptr inbounds i8, ptr %2, i64 88
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw6Driver9s_plglistE, ptr noundef %7)
  %8 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 96
  %10 = load ptr, ptr %9, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 24), ptr noundef %10)
  %11 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i64 104
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 48), ptr noundef %13)
  %14 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 112
  %16 = load ptr, ptr %15, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 72), ptr noundef %16)
  %17 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 120
  %19 = load ptr, ptr %18, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 96), ptr noundef %19)
  %20 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 128
  %22 = load ptr, ptr %21, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 120), ptr noundef %22)
  %23 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i64 136
  %25 = load ptr, ptr %24, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 144), ptr noundef %25)
  %26 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 144
  %28 = load ptr, ptr %27, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 168), ptr noundef %28)
  %29 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 152
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 192), ptr noundef %31)
  %32 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 160
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 216), ptr noundef %34)
  %35 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %35, i64 168
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 240), ptr noundef %37)
  %38 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i64 176
  %40 = load ptr, ptr %39, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 264), ptr noundef %40)
  %41 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i64 184
  %43 = load ptr, ptr %42, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) getelementptr inbounds (i8, ptr @_ZN2rw6Driver9s_plglistE, i64 288), ptr noundef %43)
  %44 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  tail call void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24) @_ZN2rw6Engine9s_plglistE, ptr noundef %44)
  %45 = load ptr, ptr @_ZN2rw6engineE, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 320
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = tail call noundef i32 %47(i32 noundef 1, ptr noundef null, i32 noundef 0)
  store i32 2, ptr @_ZN2rw6Engine5stateE, align 4, !tbaa !16
  br label %56

49:                                               ; preds = %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  store i32 0, ptr %1, align 4, !tbaa !18
  %50 = getelementptr inbounds i8, ptr %1, i64 4
  store i32 -2147483647, ptr %50, align 4, !tbaa !21
  %51 = load ptr, ptr @stderr, align 8, !tbaa !5
  %52 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %51, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, i32 noundef 366) #5
  %53 = load ptr, ptr @stderr, align 8, !tbaa !5
  %54 = tail call noundef ptr (i32, ...) @_ZN2rw9dbgsprintEjz(i32 noundef -2147483647)
  %55 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %53, ptr noundef nonnull @.str.5, ptr noundef %54) #5
  call void @_ZN2rw8setErrorEPNS_5ErrorE(ptr noundef nonnull %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  br label %56

56:                                               ; preds = %.preheader.preheader, %49
  ret void
}

declare void @_ZN2rw10PluginList8destructEPv(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { "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 = { nounwind }
attributes #5 = { 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++ TBAA"}
!9 = !{!10, !6, i64 320}
!10 = !{!"_ZTSN2rw6EngineE", !6, i64 0, !6, i64 8, !11, i64 16, !13, i64 32, !7, i64 88, !14, i64 192, !6, i64 328}
!11 = !{!"_ZTSN2rw8LinkListE", !12, i64 0}
!12 = !{!"_ZTSN2rw6LLLinkE", !6, i64 0, !6, i64 8}
!13 = !{!"_ZTSN2rw13FileFunctionsE", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48}
!14 = !{!"_ZTSN2rw6DeviceE", !15, i64 0, !15, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!15 = !{!"float", !7, i64 0}
!16 = !{!17, !17, i64 0}
!17 = !{!"_ZTSN2rw6Engine5StateE", !7, i64 0}
!18 = !{!19, !20, i64 0}
!19 = !{!"_ZTSN2rw5ErrorE", !20, i64 0, !20, i64 4}
!20 = !{!"int", !7, i64 0}
!21 = !{!19, !20, i64 4}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,SROAPass,SimplifyCFGPass,TailCallElimPass