; LLVM IR from Stephane-D/SGDK :: tools/xgmtool/src (psg)

; 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.PSG = type { [4 x [2 x i32]], [4 x [2 x i8]], i32, i32 }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @PSG_copy(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
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %5 = call noalias ptr @malloc(i64 noundef 48) #4
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.PSG, ptr %6, i32 0, i32 2
  store i32 -1, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.PSG, ptr %8, i32 0, i32 3
  store i32 -1, ptr %9, align 4, !tbaa !12
  store i32 0, ptr %4, align 4, !tbaa !13
  br label %10

10:                                               ; preds = %70, %1
  %11 = load i32, ptr %4, align 4, !tbaa !13
  %12 = icmp slt i32 %11, 4
  br i1 %12, label %13, label %73

13:                                               ; preds = %10
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.PSG, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %4, align 4, !tbaa !13
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [4 x [2 x i32]], ptr %15, i64 0, i64 %17
  %19 = getelementptr inbounds [2 x i32], ptr %18, i64 0, i64 0
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.PSG, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %4, align 4, !tbaa !13
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [4 x [2 x i32]], ptr %22, i64 0, i64 %24
  %26 = getelementptr inbounds [2 x i32], ptr %25, i64 0, i64 0
  store i32 %20, ptr %26, align 4, !tbaa !13
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.PSG, ptr %27, i32 0, i32 0
  %29 = load i32, ptr %4, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [4 x [2 x i32]], ptr %28, i64 0, i64 %30
  %32 = getelementptr inbounds [2 x i32], ptr %31, i64 0, i64 1
  %33 = load i32, ptr %32, align 4, !tbaa !13
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.PSG, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %4, align 4, !tbaa !13
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [4 x [2 x i32]], ptr %35, i64 0, i64 %37
  %39 = getelementptr inbounds [2 x i32], ptr %38, i64 0, i64 1
  store i32 %33, ptr %39, align 4, !tbaa !13
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.PSG, ptr %40, i32 0, i32 1
  %42 = load i32, ptr %4, align 4, !tbaa !13
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [4 x [2 x i8]], ptr %41, i64 0, i64 %43
  %45 = getelementptr inbounds [2 x i8], ptr %44, i64 0, i64 0
  %46 = load i8, ptr %45, align 2, !tbaa !14, !range !16, !noundef !17
  %47 = trunc i8 %46 to i1
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.PSG, ptr %48, i32 0, i32 1
  %50 = load i32, ptr %4, align 4, !tbaa !13
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [4 x [2 x i8]], ptr %49, i64 0, i64 %51
  %53 = getelementptr inbounds [2 x i8], ptr %52, i64 0, i64 0
  %54 = zext i1 %47 to i8
  store i8 %54, ptr %53, align 2, !tbaa !14
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.PSG, ptr %55, i32 0, i32 1
  %57 = load i32, ptr %4, align 4, !tbaa !13
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [4 x [2 x i8]], ptr %56, i64 0, i64 %58
  %60 = getelementptr inbounds [2 x i8], ptr %59, i64 0, i64 1
  %61 = load i8, ptr %60, align 1, !tbaa !14, !range !16, !noundef !17
  %62 = trunc i8 %61 to i1
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.PSG, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %4, align 4, !tbaa !13
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4 x [2 x i8]], ptr %64, i64 0, i64 %66
  %68 = getelementptr inbounds [2 x i8], ptr %67, i64 0, i64 1
  %69 = zext i1 %62 to i8
  store i8 %69, ptr %68, align 1, !tbaa !14
  br label %70

70:                                               ; preds = %13
  %71 = load i32, ptr %4, align 4, !tbaa !13
  %72 = add nsw i32 %71, 1
  store i32 %72, ptr %4, align 4, !tbaa !13
  br label %10, !llvm.loop !18

73:                                               ; preds = %10
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %74
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 }
attributes #4 = { nounwind allocsize(0) }

!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, !11, i64 40}
!10 = !{!"", !7, i64 0, !7, i64 32, !11, i64 40, !11, i64 44}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 44}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"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"

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: read, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @PSG_copy(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #2
  %3 = getelementptr inbounds i8, ptr %2, i64 40
  store i32 -1, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %2, i64 44
  store i32 -1, ptr %4, align 4, !tbaa !10
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %2, i64 32
  %7 = load <2 x i32>, ptr %0, align 4, !tbaa !11
  store <2 x i32> %7, ptr %2, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = load <2 x i32>, ptr %8, align 4, !tbaa !11
  store <2 x i32> %10, ptr %9, align 4, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 16
  %12 = getelementptr inbounds i8, ptr %2, i64 16
  %13 = load <2 x i32>, ptr %11, align 4, !tbaa !11
  store <2 x i32> %13, ptr %12, align 4, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = getelementptr inbounds i8, ptr %2, i64 24
  %16 = load <2 x i32>, ptr %14, align 4, !tbaa !11
  store <2 x i32> %16, ptr %15, align 4, !tbaa !11
  %17 = load <8 x i8>, ptr %5, align 2, !tbaa !12
  store <8 x i8> %17, ptr %6, align 2, !tbaa !12
  ret ptr %2
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 willreturn memory(write, argmem: read, inaccessiblemem: readwrite) 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 allocsize(0) }

!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, !9, i64 40}
!6 = !{!"", !7, i64 0, !7, i64 32, !9, i64 40, !9, i64 44}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 44}
!11 = !{!9, !9, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"_Bool", !7, i64 0}


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