; LLVM IR from EarlGray/language-incubator :: fp/secd (secd)

; 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.secd = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.cell = type { i64, %union.anon, i64 }
%union.anon = type { %struct.atom }
%struct.atom = type { i32, %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { i64, ptr }
%struct.cons = type { ptr, ptr }

; 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 allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @init_secd(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = call noalias ptr @calloc(i64 noundef 262144, i64 noundef 40) #3
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.secd, ptr %7, i32 0, i32 5
  store ptr %6, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !11
  br label %9

9:                                                ; preds = %34, %1
  %10 = load i32, ptr %3, align 4, !tbaa !11
  %11 = icmp slt i32 %10, 262143
  br i1 %11, label %12, label %37

12:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.secd, ptr %13, i32 0, i32 5
  %15 = load ptr, ptr %14, align 8, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds %struct.cell, ptr %15, i64 %17
  store ptr %18, ptr %4, align 8, !tbaa !5
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = ptrtoint ptr %19 to i64
  %21 = or i64 %20, 2
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.cell, ptr %22, i32 0, i32 0
  store i64 %21, ptr %23, align 8, !tbaa !13
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.secd, ptr %24, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  %27 = load i32, ptr %3, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds %struct.cell, ptr %26, i64 %28
  %30 = getelementptr inbounds %struct.cell, ptr %29, i64 1
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cell, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.cons, ptr %32, i32 0, i32 1
  store ptr %30, ptr %33, align 8, !tbaa !16
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %34

34:                                               ; preds = %12
  %35 = load i32, ptr %3, align 4, !tbaa !11
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %3, align 4, !tbaa !11
  br label %9, !llvm.loop !17

37:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.secd, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !9
  %41 = getelementptr inbounds %struct.cell, ptr %40, i64 262144
  %42 = getelementptr inbounds %struct.cell, ptr %41, i64 -1
  store ptr %42, ptr %5, align 8, !tbaa !5
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.secd, ptr %44, i32 0, i32 6
  store ptr %43, ptr %45, align 8, !tbaa !19
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = ptrtoint ptr %46 to i64
  %48 = or i64 %47, 2
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.cell, ptr %49, i32 0, i32 0
  store i64 %48, ptr %50, align 8, !tbaa !13
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.cell, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.cons, ptr %52, i32 0, i32 1
  store ptr null, ptr %53, align 8, !tbaa !16
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.secd, ptr %54, i32 0, i32 5
  %56 = load ptr, ptr %55, align 8, !tbaa !9
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.secd, ptr %57, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !20
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.secd, ptr %59, i32 0, i32 6
  %61 = load ptr, ptr %60, align 8, !tbaa !19
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.secd, ptr %62, i32 0, i32 3
  store ptr %61, ptr %63, align 8, !tbaa !21
  %64 = load ptr, ptr %2, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.secd, ptr %64, i32 0, i32 0
  store ptr %61, ptr %65, align 8, !tbaa !22
  %66 = load ptr, ptr %2, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.secd, ptr %66, i32 0, i32 6
  %68 = load ptr, ptr %67, align 8, !tbaa !19
  %69 = load ptr, ptr %2, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.secd, ptr %69, i32 0, i32 1
  store ptr %68, ptr %70, align 8, !tbaa !23
  %71 = load ptr, ptr %2, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.secd, ptr %71, i32 0, i32 2
  store ptr %68, ptr %72, align 8, !tbaa !24
  %73 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret ptr %73
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(0,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 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,1) }
attributes #4 = { 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, !6, i64 40}
!10 = !{!"secd", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"cell", !15, i64 0, !7, i64 8, !15, i64 32}
!15 = !{!"long", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!10, !6, i64 48}
!20 = !{!10, !6, i64 32}
!21 = !{!10, !6, i64 24}
!22 = !{!10, !6, i64 0}
!23 = !{!10, !6, i64 8}
!24 = !{!10, !6, i64 16}


; 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.cell = type { i64, %union.anon, i64 }
%union.anon = type { %struct.atom }
%struct.atom = type { i32, %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { i64, ptr }

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

; Function Attrs: nofree nounwind memory(write, argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local noundef ptr @init_secd(ptr noundef returned %0) local_unnamed_addr #1 {
  %2 = tail call noalias dereferenceable_or_null(10485760) ptr @calloc(i64 noundef 262144, i64 noundef 40) #2
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %2, ptr %3, align 8, !tbaa !5
  %4 = ptrtoint ptr %0 to i64
  %5 = or i64 %4, 2
  br label %6

6:                                                ; preds = %6, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.2, %6 ]
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.cell, ptr %7, i64 %indvars.iv
  store i64 %5, ptr %8, align 8, !tbaa !10
  %9 = getelementptr inbounds i8, ptr %8, i64 40
  %10 = getelementptr inbounds i8, ptr %8, i64 16
  store ptr %9, ptr %10, align 8, !tbaa !13
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.cell, ptr %11, i64 %indvars.iv
  %13 = getelementptr inbounds i8, ptr %12, i64 40
  store i64 %5, ptr %13, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %12, i64 80
  %15 = getelementptr inbounds i8, ptr %12, i64 56
  store ptr %14, ptr %15, align 8, !tbaa !13
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.cell, ptr %16, i64 %indvars.iv
  %18 = getelementptr inbounds i8, ptr %17, i64 80
  store i64 %5, ptr %18, align 8, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %17, i64 120
  %20 = getelementptr inbounds i8, ptr %17, i64 96
  store ptr %19, ptr %20, align 8, !tbaa !13
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 262143
  br i1 %exitcond.not.2, label %21, label %6, !llvm.loop !14

21:                                               ; preds = %6
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 10485720
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr %23, ptr %24, align 8, !tbaa !16
  store i64 %5, ptr %23, align 8, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %22, i64 10485736
  store ptr null, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %26, ptr %27, align 8, !tbaa !17
  %28 = load ptr, ptr %24, align 8, !tbaa !16
  %29 = insertelement <4 x ptr> poison, ptr %28, i64 0
  %30 = shufflevector <4 x ptr> %29, <4 x ptr> poison, <4 x i32> zeroinitializer
  store <4 x ptr> %30, ptr %0, align 8, !tbaa !18
  ret ptr %0
}

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

!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 40}
!6 = !{!"secd", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"cell", !12, i64 0, !8, i64 8, !12, i64 32}
!12 = !{!"long", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 48}
!17 = !{!6, !7, i64 32}
!18 = !{!7, !7, i64 0}


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