; LLVM IR from aap/librw :: src/ps2/ps2.ll (ZN2rw3ps28printDMAEPNS0_12InstanceDataE)

; 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::ps2::InstanceData" = type { i32, ptr, ptr, ptr }

@.str.35 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [16 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 i32 @printf(ptr noundef, ...) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN2rw3ps28printDMAEPNS0_12InstanceDataE(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %"struct.rw::ps2::InstanceData", ptr %5, i32 0, i32 2
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  br label %8

8:                                                ; preds = %43, %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds i32, ptr %9, i64 0
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = and i32 %11, 65535
  store i32 %12, ptr %4, align 4, !tbaa !12
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds i32, ptr %13, i64 0
  %15 = load i32, ptr %14, align 4, !tbaa !12
  %16 = and i32 %15, 1879048192
  switch i32 %16, label %43 [
    i32 268435456, label %17
    i32 805306368, label %29
    i32 1610612736, label %37
  ]

17:                                               ; preds = %8
  %18 = load i32, ptr %4, align 4, !tbaa !12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds i32, ptr %19, i64 1
  %21 = load i32, ptr %20, align 4, !tbaa !12
  %22 = call i32 (ptr, ...) @printf(ptr noundef @.str.35, i32 noundef %18, i32 noundef %21)
  %23 = load i32, ptr %4, align 4, !tbaa !12
  %24 = add i32 1, %23
  %25 = mul i32 %24, 4
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = zext i32 %25 to i64
  %28 = getelementptr inbounds i32, ptr %26, i64 %27
  store ptr %28, ptr %3, align 8, !tbaa !5
  br label %43

29:                                               ; preds = %8
  %30 = load i32, ptr %4, align 4, !tbaa !12
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds i32, ptr %31, i64 1
  %33 = load i32, ptr %32, align 4, !tbaa !12
  %34 = call i32 (ptr, ...) @printf(ptr noundef @.str.36, i32 noundef %30, i32 noundef %33)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds i32, ptr %35, i64 4
  store ptr %36, ptr %3, align 8, !tbaa !5
  br label %43

37:                                               ; preds = %8
  %38 = load i32, ptr %4, align 4, !tbaa !12
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds i32, ptr %39, i64 1
  %41 = load i32, ptr %40, align 4, !tbaa !12
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.37, i32 noundef %38, i32 noundef %41)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void

43:                                               ; preds = %29, %17, %8
  br label %8, !llvm.loop !13
}

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, !6, i64 16}
!10 = !{!"_ZTSN2rw3ps212InstanceDataE", !11, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; 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.35 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [16 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_ZN2rw3ps28printDMAEPNS0_12InstanceDataE(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  br label %.outer

.outer:                                           ; preds = %.outer.backedge, %1
  %.0.ph = phi ptr [ %3, %1 ], [ %.0.ph.be, %.outer.backedge ]
  %4 = load i32, ptr %.0.ph, align 4, !tbaa !11
  %5 = and i32 %4, 1879048192
  br label %6

6:                                                ; preds = %.outer, %6
  switch i32 %5, label %6 [
    i32 268435456, label %7
    i32 805306368, label %16
    i32 1610612736, label %22
  ], !llvm.loop !12

7:                                                ; preds = %6
  %8 = and i32 %4, 65535
  %9 = getelementptr inbounds i8, ptr %.0.ph, i64 4
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.35, i32 noundef %8, i32 noundef %10)
  %12 = shl nuw nsw i32 %8, 2
  %13 = add nuw nsw i32 %12, 4
  %14 = zext nneg i32 %13 to i64
  %15 = getelementptr inbounds i32, ptr %.0.ph, i64 %14
  br label %.outer.backedge

16:                                               ; preds = %6
  %17 = and i32 %4, 65535
  %18 = getelementptr inbounds i8, ptr %.0.ph, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.36, i32 noundef %17, i32 noundef %19)
  %21 = getelementptr inbounds i8, ptr %.0.ph, i64 16
  br label %.outer.backedge

.outer.backedge:                                  ; preds = %16, %7
  %.0.ph.be = phi ptr [ %15, %7 ], [ %21, %16 ]
  br label %.outer, !llvm.loop !12

22:                                               ; preds = %6
  %23 = and i32 %4, 65535
  %24 = getelementptr inbounds i8, ptr %.0.ph, i64 4
  %25 = load i32, ptr %24, align 4, !tbaa !11
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.37, i32 noundef %23, i32 noundef %25)
  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 nofree 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" }

!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, !10, i64 16}
!6 = !{!"_ZTSN2rw3ps212InstanceDataE", !7, i64 0, !10, i64 8, !10, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass