; LLVM IR from Farama-Foundation/stable-retro :: cores/32x/pico/sound (sn76496)

; 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.SN76496 = type { i32, i32, [16 x i32], [8 x i32], i32, [4 x i32], i32, i32, [4 x i32], [4 x i32], [4 x i32], [1 x i32] }

@ono_sn = external hidden global %struct.SN76496, align 4
@sn76496_regs = external dso_local global ptr, align 8

; 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
define dso_local i32 @SN76496_init(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store ptr @ono_sn, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %7 = load ptr, ptr %5, align 8, !tbaa !9
  %8 = getelementptr inbounds %struct.SN76496, ptr %7, i32 0, i32 3
  %9 = getelementptr inbounds [8 x i32], ptr %8, i64 0, i64 0
  store ptr %9, ptr @sn76496_regs, align 8, !tbaa !9
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.SN76496, ptr %11, i32 0, i32 0
  store i32 %10, ptr %12, align 4, !tbaa !11
  %13 = load ptr, ptr %5, align 8, !tbaa !9
  %14 = load i32, ptr %3, align 4, !tbaa !5
  call void @SN76496_set_clock(ptr noundef %13, i32 noundef %14)
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %24, %2
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 4
  br i1 %17, label %18, label %27

18:                                               ; preds = %15
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.SN76496, ptr %19, i32 0, i32 5
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [4 x i32], ptr %20, i64 0, i64 %22
  store i32 0, ptr %23, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %6, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %6, align 4, !tbaa !5
  br label %15, !llvm.loop !13

27:                                               ; preds = %15
  %28 = load ptr, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.SN76496, ptr %28, i32 0, i32 4
  store i32 0, ptr %29, align 4, !tbaa !15
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %45, %27
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = icmp slt i32 %31, 8
  br i1 %32, label %33, label %48

33:                                               ; preds = %30
  %34 = load ptr, ptr %5, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.SN76496, ptr %34, i32 0, i32 3
  %36 = load i32, ptr %6, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [8 x i32], ptr %35, i64 0, i64 %37
  store i32 0, ptr %38, align 4, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.SN76496, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %6, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [8 x i32], ptr %40, i64 0, i64 %43
  store i32 15, ptr %44, align 4, !tbaa !5
  br label %45

45:                                               ; preds = %33
  %46 = load i32, ptr %6, align 4, !tbaa !5
  %47 = add nsw i32 %46, 2
  store i32 %47, ptr %6, align 4, !tbaa !5
  br label %30, !llvm.loop !16

48:                                               ; preds = %30
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %49

49:                                               ; preds = %76, %48
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = icmp slt i32 %50, 4
  br i1 %51, label %52, label %79

52:                                               ; preds = %49
  %53 = load ptr, ptr %5, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.SN76496, ptr %53, i32 0, i32 9
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [4 x i32], ptr %54, i64 0, i64 %56
  store i32 0, ptr %57, align 4, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.SN76496, ptr %58, i32 0, i32 10
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [4 x i32], ptr %59, i64 0, i64 %61
  store i32 0, ptr %62, align 4, !tbaa !5
  %63 = load ptr, ptr %5, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.SN76496, ptr %63, i32 0, i32 5
  %65 = load i32, ptr %6, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [4 x i32], ptr %64, i64 0, i64 %66
  store i32 0, ptr %67, align 4, !tbaa !5
  %68 = load ptr, ptr %5, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.SN76496, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !17
  %71 = load ptr, ptr %5, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.SN76496, ptr %71, i32 0, i32 8
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [4 x i32], ptr %72, i64 0, i64 %74
  store i32 %70, ptr %75, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %52
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %6, align 4, !tbaa !5
  br label %49, !llvm.loop !18

79:                                               ; preds = %49
  %80 = load ptr, ptr %5, align 8, !tbaa !9
  %81 = getelementptr inbounds %struct.SN76496, ptr %80, i32 0, i32 6
  store i32 32768, ptr %81, align 4, !tbaa !19
  %82 = load ptr, ptr %5, align 8, !tbaa !9
  %83 = getelementptr inbounds %struct.SN76496, ptr %82, i32 0, i32 6
  %84 = load i32, ptr %83, align 4, !tbaa !19
  %85 = and i32 %84, 1
  %86 = load ptr, ptr %5, align 8, !tbaa !9
  %87 = getelementptr inbounds %struct.SN76496, ptr %86, i32 0, i32 10
  %88 = getelementptr inbounds [4 x i32], ptr %87, i64 0, i64 3
  store i32 %85, ptr %88, align 4, !tbaa !5
  %89 = load ptr, ptr %5, align 8, !tbaa !9
  call void @SN76496_set_gain(ptr noundef %89, i32 noundef 0)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  ret i32 0
}

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

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

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"SN76496", !6, i64 0, !6, i64 4, !7, i64 8, !7, i64 72, !6, i64 104, !7, i64 108, !6, i64 124, !6, i64 128, !7, i64 132, !7, i64 148, !7, i64 164, !7, i64 180}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !6, i64 104}
!16 = distinct !{!16, !14}
!17 = !{!12, !6, i64 4}
!18 = distinct !{!18, !14}
!19 = !{!12, !6, i64 124}


; 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.SN76496 = type { i32, i32, [16 x i32], [8 x i32], i32, [4 x i32], i32, i32, [4 x i32], [4 x i32], [4 x i32], [1 x i32] }

@ono_sn = external hidden global %struct.SN76496, align 4
@sn76496_regs = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @SN76496_init(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
.preheader:
  store ptr getelementptr inbounds (i8, ptr @ono_sn, i64 72), ptr @sn76496_regs, align 8, !tbaa !5
  store i32 %1, ptr @ono_sn, align 4, !tbaa !9
  tail call void @SN76496_set_clock(ptr noundef nonnull @ono_sn, i32 noundef %0)
  store i32 0, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 104), align 4
  store <4 x i32> <i32 0, i32 15, i32 0, i32 15>, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 72), align 4, !tbaa !12
  store <4 x i32> <i32 0, i32 15, i32 0, i32 15>, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 88), align 4, !tbaa !12
  %2 = load <4 x i32>, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 4), align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) getelementptr inbounds (i8, ptr @ono_sn, i64 108), i8 0, i64 16, i1 false), !tbaa !12
  store <4 x i32> zeroinitializer, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 148), align 4, !tbaa !12
  %3 = shufflevector <4 x i32> %2, <4 x i32> poison, <4 x i32> zeroinitializer
  store <4 x i32> %3, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 132), align 4, !tbaa !12
  store i32 32768, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 124), align 4, !tbaa !13
  store <4 x i32> zeroinitializer, ptr getelementptr inbounds (i8, ptr @ono_sn, i64 164), align 4, !tbaa !12
  tail call void @SN76496_set_gain(ptr noundef nonnull @ono_sn, i32 noundef 0)
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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 0}
!10 = !{!"SN76496", !11, i64 0, !11, i64 4, !7, i64 8, !7, i64 72, !11, i64 104, !7, i64 108, !11, i64 124, !11, i64 128, !7, i64 132, !7, i64 148, !7, i64 164, !7, i64 180}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 124}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass