; LLVM IR from aap/pdp6 :: emu (mem)

; 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.Membus = type { i64, i64, i64, i64, i64, i64, ptr, [16 x ptr] }
%struct.CMem = type { ptr, i32, i32, ptr, i64, i32, i8, i8, i8, i8, i8, i8 }
%struct.Mem = type { %struct.Device, ptr, [4 x ptr], ptr, ptr, ptr }
%struct.Device = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@cmem_ident = external dso_local global ptr, align 8
@stderr = external global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [1 x i8], align 1
@memterm = external dso_local global %struct.Membus, 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: nounwind
declare i32 @fprintf(ptr noundef, ptr 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 @makecoremem(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %9 = call noalias ptr @malloc(i64 noundef 48) #6
  store ptr %9, ptr %6, align 8, !tbaa !5
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 48, i1 false)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call noalias ptr @strdup(ptr noundef %11) #5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.CMem, ptr %13, i32 0, i32 0
  store ptr %12, ptr %14, align 8, !tbaa !11
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.CMem, ptr %16, i32 0, i32 1
  store i32 %15, ptr %17, align 8, !tbaa !14
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.CMem, ptr %20, i32 0, i32 2
  store i32 %19, ptr %21, align 4, !tbaa !15
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.CMem, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.CMem, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 4, !tbaa !15
  %28 = and i32 %24, %27
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %40

30:                                               ; preds = %2
  %31 = load ptr, ptr @stderr, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.CMem, ptr %32, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !14
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef @.str.8, i32 noundef %34) #5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.CMem, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !11
  call void @free(ptr noundef %38) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void @free(ptr noundef %39) #5
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %88

40:                                               ; preds = %2
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.CMem, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !14
  %44 = sext i32 %43 to i64
  %45 = mul i64 %44, 8
  %46 = call noalias ptr @malloc(i64 noundef %45) #6
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.CMem, ptr %47, i32 0, i32 3
  store ptr %46, ptr %48, align 8, !tbaa !16
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.CMem, ptr %49, i32 0, i32 3
  %51 = load ptr, ptr %50, align 8, !tbaa !16
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.CMem, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !14
  %55 = sext i32 %54 to i64
  %56 = mul i64 %55, 8
  call void @llvm.memset.p0.i64(ptr align 8 %51, i8 0, i64 %56, i1 false)
  %57 = call noalias ptr @malloc(i64 noundef 128) #6
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %58, i8 0, i64 128, i1 false)
  %59 = load ptr, ptr @cmem_ident, align 8, !tbaa !5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Mem, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds %struct.Device, ptr %61, i32 0, i32 1
  store ptr %59, ptr %62, align 8, !tbaa !17
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.Mem, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds %struct.Device, ptr %64, i32 0, i32 2
  store ptr @.str.9, ptr %65, align 8, !tbaa !20
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Mem, ptr %67, i32 0, i32 1
  store ptr %66, ptr %68, align 8, !tbaa !21
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Mem, ptr %69, i32 0, i32 2
  %71 = getelementptr inbounds [4 x ptr], ptr %70, i64 0, i64 0
  store ptr @memterm, ptr %71, align 8, !tbaa !5
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.Mem, ptr %72, i32 0, i32 2
  %74 = getelementptr inbounds [4 x ptr], ptr %73, i64 0, i64 1
  store ptr @memterm, ptr %74, align 8, !tbaa !5
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.Mem, ptr %75, i32 0, i32 2
  %77 = getelementptr inbounds [4 x ptr], ptr %76, i64 0, i64 2
  store ptr @memterm, ptr %77, align 8, !tbaa !5
  %78 = load ptr, ptr %7, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.Mem, ptr %78, i32 0, i32 2
  %80 = getelementptr inbounds [4 x ptr], ptr %79, i64 0, i64 3
  store ptr @memterm, ptr %80, align 8, !tbaa !5
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.Mem, ptr %81, i32 0, i32 3
  store ptr @wakecore, ptr %82, align 8, !tbaa !22
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Mem, ptr %83, i32 0, i32 4
  store ptr @powercore, ptr %84, align 8, !tbaa !23
  %85 = load ptr, ptr %7, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.Mem, ptr %85, i32 0, i32 5
  store ptr @synccore, ptr %86, align 8, !tbaa !24
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %87, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %88

88:                                               ; preds = %40, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %89 = load ptr, ptr %3, align 8
  ret ptr %89
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #1

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden void @powercore(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @synccore(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 = { 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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"CMem", !6, i64 0, !10, i64 8, !10, i64 12, !6, i64 16, !13, i64 24, !10, i64 32, !7, i64 36, !7, i64 37, !7, i64 38, !7, i64 39, !7, i64 40, !7, i64 41}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !10, i64 8}
!15 = !{!12, !10, i64 12}
!16 = !{!12, !6, i64 16}
!17 = !{!18, !6, i64 8}
!18 = !{!"Mem", !19, i64 0, !6, i64 64, !7, i64 72, !6, i64 104, !6, i64 112, !6, i64 120}
!19 = !{!"Device", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!20 = !{!18, !6, i64 16}
!21 = !{!18, !6, i64 64}
!22 = !{!18, !6, i64 104}
!23 = !{!18, !6, i64 112}
!24 = !{!18, !6, i64 120}


; 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.Membus = type { i64, i64, i64, i64, i64, i64, ptr, [16 x ptr] }

@cmem_ident = external dso_local local_unnamed_addr global ptr, align 8
@stderr = external local_unnamed_addr global ptr, align 8
@.str.8 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [1 x i8], align 1
@memterm = external dso_local global %struct.Membus, align 8

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

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @makecoremem(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %calloc30 = tail call dereferenceable_or_null(48) ptr @calloc(i64 1, i64 48)
  %3 = tail call noalias ptr @strdup(ptr noundef %0) #6
  store ptr %3, ptr %calloc30, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %calloc30, i64 8
  store i32 %1, ptr %4, align 8, !tbaa !12
  %5 = add nsw i32 %1, -1
  %6 = getelementptr inbounds i8, ptr %calloc30, i64 12
  store i32 %5, ptr %6, align 4, !tbaa !13
  %7 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %1)
  %.not = icmp ult i32 %7, 2
  br i1 %.not, label %11, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr @stderr, align 8, !tbaa !14
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.8, i32 noundef %1) #7
  tail call void @free(ptr noundef %3) #6
  tail call void @free(ptr noundef nonnull %calloc30) #6
  br label %26

11:                                               ; preds = %2
  %12 = sext i32 %1 to i64
  %13 = shl nsw i64 %12, 3
  %calloc = tail call ptr @calloc(i64 1, i64 %13)
  %14 = getelementptr inbounds i8, ptr %calloc30, i64 16
  store ptr %calloc, ptr %14, align 8, !tbaa !15
  %calloc29 = tail call dereferenceable_or_null(128) ptr @calloc(i64 1, i64 128)
  %15 = load ptr, ptr @cmem_ident, align 8, !tbaa !14
  %16 = getelementptr inbounds i8, ptr %calloc29, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !16
  %17 = getelementptr inbounds i8, ptr %calloc29, i64 16
  store ptr @.str.9, ptr %17, align 8, !tbaa !19
  %18 = getelementptr inbounds i8, ptr %calloc29, i64 64
  store ptr %calloc30, ptr %18, align 8, !tbaa !20
  %19 = getelementptr inbounds i8, ptr %calloc29, i64 72
  store ptr @memterm, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds i8, ptr %calloc29, i64 80
  store ptr @memterm, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %calloc29, i64 88
  store ptr @memterm, ptr %21, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %calloc29, i64 96
  store ptr @memterm, ptr %22, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %calloc29, i64 104
  store ptr @wakecore, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %calloc29, i64 112
  store ptr @powercore, ptr %24, align 8, !tbaa !22
  %25 = getelementptr inbounds i8, ptr %calloc29, i64 120
  store ptr @synccore, ptr %25, align 8, !tbaa !23
  br label %26

26:                                               ; preds = %11, %8
  %.0 = phi ptr [ null, %8 ], [ %calloc29, %11 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #3

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

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.ctpop.i32(i32) #4

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #5

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 = { 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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, 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 #3 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #6 = { nounwind }
attributes #7 = { 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, !7, i64 0}
!6 = !{!"CMem", !7, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !11, i64 24, !10, i64 32, !8, i64 36, !8, i64 37, !8, i64 38, !8, i64 39, !8, i64 40, !8, i64 41}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 12}
!14 = !{!7, !7, i64 0}
!15 = !{!6, !7, i64 16}
!16 = !{!17, !7, i64 8}
!17 = !{!"Mem", !18, i64 0, !7, i64 64, !8, i64 72, !7, i64 104, !7, i64 112, !7, i64 120}
!18 = !{!"Device", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!19 = !{!17, !7, i64 16}
!20 = !{!17, !7, i64 64}
!21 = !{!17, !7, i64 104}
!22 = !{!17, !7, i64 112}
!23 = !{!17, !7, i64 120}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass