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

; 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 uwtable
declare dso_local i32 @PSG_get(ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @PSG_isDiff(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @PSG_isLowDiffOnly(ptr noundef, ptr noundef, i32 noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @PSG_getDelta(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store ptr null, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %77, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 4
  br i1 %10, label %11, label %80

11:                                               ; preds = %8
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %73, %11
  %13 = load i32, ptr %6, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 2
  br i1 %14, label %15, label %76

15:                                               ; preds = %12
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %54

18:                                               ; preds = %15
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = call zeroext i1 @PSG_isLowDiffOnly(ptr noundef %19, ptr noundef %20, i32 noundef %21, i32 noundef %22)
  br i1 %23, label %24, label %35

24:                                               ; preds = %18
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = call i32 @PSG_get(ptr noundef %29, i32 noundef %30, i32 noundef %31)
  %33 = call ptr @PSG_createLowWriteCommand(ptr noundef %26, i32 noundef %27, i32 noundef %28, i32 noundef %32)
  %34 = call ptr @insertAfterLList(ptr noundef %25, ptr noundef %33)
  store ptr %34, ptr %7, align 8, !tbaa !5
  br label %53

35:                                               ; preds = %18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = call zeroext i1 @PSG_isDiff(ptr noundef %36, ptr noundef %37, i32 noundef %38, i32 noundef %39)
  br i1 %40, label %41, label %52

41:                                               ; preds = %35
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %6, align 4, !tbaa !9
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = call i32 @PSG_get(ptr noundef %46, i32 noundef %47, i32 noundef %48)
  %50 = call ptr @PSG_createWriteCommands(ptr noundef %43, i32 noundef %44, i32 noundef %45, i32 noundef %49)
  %51 = call ptr @insertAllAfterLList(ptr noundef %42, ptr noundef %50)
  store ptr %51, ptr %7, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %41, %35
  br label %53

53:                                               ; preds = %52, %24
  br label %72

54:                                               ; preds = %15
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = call zeroext i1 @PSG_isDiff(ptr noundef %55, ptr noundef %56, i32 noundef %57, i32 noundef %58)
  br i1 %59, label %60, label %71

60:                                               ; preds = %54
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = load i32, ptr %6, align 4, !tbaa !9
  %68 = call i32 @PSG_get(ptr noundef %65, i32 noundef %66, i32 noundef %67)
  %69 = call ptr @PSG_createWriteCommands(ptr noundef %62, i32 noundef %63, i32 noundef %64, i32 noundef %68)
  %70 = call ptr @insertAllAfterLList(ptr noundef %61, ptr noundef %69)
  store ptr %70, ptr %7, align 8, !tbaa !5
  br label %71

71:                                               ; preds = %60, %54
  br label %72

72:                                               ; preds = %71, %53
  br label %73

73:                                               ; preds = %72
  %74 = load i32, ptr %6, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %6, align 4, !tbaa !9
  br label %12, !llvm.loop !11

76:                                               ; preds = %12
  br label %77

77:                                               ; preds = %76
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = add nsw i32 %78, 1
  store i32 %79, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !13

80:                                               ; preds = %8
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = call ptr @getHeadLList(ptr noundef %81)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret ptr %82
}

declare ptr @insertAfterLList(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @PSG_createLowWriteCommand(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare ptr @insertAllAfterLList(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @PSG_createWriteCommands(ptr noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare ptr @getHeadLList(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: nounwind uwtable
declare dso_local i32 @PSG_get(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @PSG_isDiff(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @PSG_isLowDiffOnly(ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @PSG_getDelta(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i1 @PSG_isLowDiffOnly(ptr noundef %0, ptr noundef %1, i32 noundef 0, i32 noundef 0)
  br i1 %3, label %4, label %8

4:                                                ; preds = %2
  %5 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 0, i32 noundef 0)
  %6 = tail call ptr @PSG_createLowWriteCommand(ptr noundef %0, i32 noundef 0, i32 noundef 0, i32 noundef %5)
  %7 = tail call ptr @insertAfterLList(ptr noundef null, ptr noundef %6) #2
  br label %14

8:                                                ; preds = %2
  %9 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 0, i32 noundef 0)
  br i1 %9, label %10, label %14

10:                                               ; preds = %8
  %11 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 0, i32 noundef 0)
  %12 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 0, i32 noundef 0, i32 noundef %11)
  %13 = tail call ptr @insertAllAfterLList(ptr noundef null, ptr noundef %12) #2
  br label %14

14:                                               ; preds = %4, %10, %8
  %.2 = phi ptr [ %7, %4 ], [ %13, %10 ], [ null, %8 ]
  %15 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 0, i32 noundef 1)
  br i1 %15, label %16, label %20

16:                                               ; preds = %14
  %17 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 0, i32 noundef 1)
  %18 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 0, i32 noundef 1, i32 noundef %17)
  %19 = tail call ptr @insertAllAfterLList(ptr noundef %.2, ptr noundef %18) #2
  br label %20

20:                                               ; preds = %16, %14
  %.2.1 = phi ptr [ %19, %16 ], [ %.2, %14 ]
  %21 = tail call zeroext i1 @PSG_isLowDiffOnly(ptr noundef %0, ptr noundef %1, i32 noundef 1, i32 noundef 0)
  br i1 %21, label %28, label %22

22:                                               ; preds = %20
  %23 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 1, i32 noundef 0)
  br i1 %23, label %24, label %32

24:                                               ; preds = %22
  %25 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 1, i32 noundef 0)
  %26 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 1, i32 noundef 0, i32 noundef %25)
  %27 = tail call ptr @insertAllAfterLList(ptr noundef %.2.1, ptr noundef %26) #2
  br label %32

28:                                               ; preds = %20
  %29 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 1, i32 noundef 0)
  %30 = tail call ptr @PSG_createLowWriteCommand(ptr noundef %0, i32 noundef 1, i32 noundef 0, i32 noundef %29)
  %31 = tail call ptr @insertAfterLList(ptr noundef %.2.1, ptr noundef %30) #2
  br label %32

32:                                               ; preds = %28, %24, %22
  %.2.145 = phi ptr [ %31, %28 ], [ %27, %24 ], [ %.2.1, %22 ]
  %33 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 1, i32 noundef 1)
  br i1 %33, label %34, label %38

34:                                               ; preds = %32
  %35 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 1, i32 noundef 1)
  %36 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 1, i32 noundef 1, i32 noundef %35)
  %37 = tail call ptr @insertAllAfterLList(ptr noundef %.2.145, ptr noundef %36) #2
  br label %38

38:                                               ; preds = %34, %32
  %.2.1.1 = phi ptr [ %37, %34 ], [ %.2.145, %32 ]
  %39 = tail call zeroext i1 @PSG_isLowDiffOnly(ptr noundef %0, ptr noundef %1, i32 noundef 2, i32 noundef 0)
  br i1 %39, label %46, label %40

40:                                               ; preds = %38
  %41 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 2, i32 noundef 0)
  br i1 %41, label %42, label %50

42:                                               ; preds = %40
  %43 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 2, i32 noundef 0)
  %44 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 2, i32 noundef 0, i32 noundef %43)
  %45 = tail call ptr @insertAllAfterLList(ptr noundef %.2.1.1, ptr noundef %44) #2
  br label %50

46:                                               ; preds = %38
  %47 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 2, i32 noundef 0)
  %48 = tail call ptr @PSG_createLowWriteCommand(ptr noundef %0, i32 noundef 2, i32 noundef 0, i32 noundef %47)
  %49 = tail call ptr @insertAfterLList(ptr noundef %.2.1.1, ptr noundef %48) #2
  br label %50

50:                                               ; preds = %46, %42, %40
  %.2.2 = phi ptr [ %49, %46 ], [ %45, %42 ], [ %.2.1.1, %40 ]
  %51 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 2, i32 noundef 1)
  br i1 %51, label %52, label %56

52:                                               ; preds = %50
  %53 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 2, i32 noundef 1)
  %54 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 2, i32 noundef 1, i32 noundef %53)
  %55 = tail call ptr @insertAllAfterLList(ptr noundef %.2.2, ptr noundef %54) #2
  br label %56

56:                                               ; preds = %52, %50
  %.2.1.2 = phi ptr [ %55, %52 ], [ %.2.2, %50 ]
  %57 = tail call zeroext i1 @PSG_isLowDiffOnly(ptr noundef %0, ptr noundef %1, i32 noundef 3, i32 noundef 0)
  br i1 %57, label %64, label %58

58:                                               ; preds = %56
  %59 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 3, i32 noundef 0)
  br i1 %59, label %60, label %68

60:                                               ; preds = %58
  %61 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 3, i32 noundef 0)
  %62 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 3, i32 noundef 0, i32 noundef %61)
  %63 = tail call ptr @insertAllAfterLList(ptr noundef %.2.1.2, ptr noundef %62) #2
  br label %68

64:                                               ; preds = %56
  %65 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 3, i32 noundef 0)
  %66 = tail call ptr @PSG_createLowWriteCommand(ptr noundef %0, i32 noundef 3, i32 noundef 0, i32 noundef %65)
  %67 = tail call ptr @insertAfterLList(ptr noundef %.2.1.2, ptr noundef %66) #2
  br label %68

68:                                               ; preds = %64, %60, %58
  %.2.3 = phi ptr [ %67, %64 ], [ %63, %60 ], [ %.2.1.2, %58 ]
  %69 = tail call zeroext i1 @PSG_isDiff(ptr noundef %0, ptr noundef %1, i32 noundef 3, i32 noundef 1)
  br i1 %69, label %70, label %74

70:                                               ; preds = %68
  %71 = tail call i32 @PSG_get(ptr noundef %1, i32 noundef 3, i32 noundef 1)
  %72 = tail call ptr @PSG_createWriteCommands(ptr noundef %0, i32 noundef 3, i32 noundef 1, i32 noundef %71)
  %73 = tail call ptr @insertAllAfterLList(ptr noundef %.2.3, ptr noundef %72) #2
  br label %74

74:                                               ; preds = %70, %68
  %.2.1.3 = phi ptr [ %73, %70 ], [ %.2.3, %68 ]
  %75 = tail call ptr @getHeadLList(ptr noundef %.2.1.3) #2
  ret ptr %75
}

declare ptr @insertAfterLList(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @PSG_createLowWriteCommand(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @insertAllAfterLList(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @PSG_createWriteCommands(ptr noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare ptr @getHeadLList(ptr noundef) local_unnamed_addr #1

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


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass