; LLVM IR from sysprog21/shecc :: src (ssa)

; 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.func = type { %struct.var, [8 x %struct.var], i32, i32, i32, ptr, ptr, %struct.symbol_list_t, i32, i32, ptr }
%struct.var = type { [32 x i8], [32 x i8], i32, i8, i8, i32, i32, i32, i32, i32, ptr, i32, [64 x ptr], i32, %struct.rename_t, %struct.ref_block_list, ptr, ptr, ptr, i32, i8, i8, i8 }
%struct.rename_t = type { i32, [64 x i32], i32 }
%struct.ref_block_list = type { ptr, ptr }
%struct.symbol_list_t = type { ptr, ptr }
%struct.symbol = type { ptr, i32, ptr }

; 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,1)
declare noalias ptr @calloc(i64 noundef, 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 void @fn_add_global(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  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 1, ptr %5) #3
  store i8 0, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.func, ptr %8, i32 0, i32 7
  %10 = getelementptr inbounds %struct.symbol_list_t, ptr %9, i32 0, i32 0
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  store ptr %11, ptr %6, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %23, %2
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %27

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.symbol, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !18
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = icmp eq ptr %18, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %15
  store i8 1, ptr %5, align 1, !tbaa !9
  br label %27

22:                                               ; preds = %15
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.symbol, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !20
  store ptr %26, ptr %6, align 8, !tbaa !5
  br label %12, !llvm.loop !21

27:                                               ; preds = %21, %12
  %28 = load i8, ptr %5, align 1, !tbaa !9, !range !23, !noundef !24
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %31

30:                                               ; preds = %27
  store i32 1, ptr %7, align 4
  br label %73

31:                                               ; preds = %27
  %32 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 24) #4
  store ptr %32, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.symbol, ptr %34, i32 0, i32 0
  store ptr %33, ptr %35, align 8, !tbaa !18
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.func, ptr %36, i32 0, i32 7
  %38 = getelementptr inbounds %struct.symbol_list_t, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = icmp ne ptr %39, null
  br i1 %40, label %52, label %41

41:                                               ; preds = %31
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.symbol, ptr %42, i32 0, i32 1
  store i32 0, ptr %43, align 8, !tbaa !25
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.func, ptr %45, i32 0, i32 7
  %47 = getelementptr inbounds %struct.symbol_list_t, ptr %46, i32 0, i32 0
  store ptr %44, ptr %47, align 8, !tbaa !11
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.func, ptr %49, i32 0, i32 7
  %51 = getelementptr inbounds %struct.symbol_list_t, ptr %50, i32 0, i32 1
  store ptr %48, ptr %51, align 8, !tbaa !26
  br label %72

52:                                               ; preds = %31
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.func, ptr %53, i32 0, i32 7
  %55 = getelementptr inbounds %struct.symbol_list_t, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !26
  %57 = getelementptr inbounds %struct.symbol, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !25
  %59 = add nsw i32 %58, 1
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.symbol, ptr %60, i32 0, i32 1
  store i32 %59, ptr %61, align 8, !tbaa !25
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.func, ptr %63, i32 0, i32 7
  %65 = getelementptr inbounds %struct.symbol_list_t, ptr %64, i32 0, i32 1
  %66 = load ptr, ptr %65, align 8, !tbaa !26
  %67 = getelementptr inbounds %struct.symbol, ptr %66, i32 0, i32 2
  store ptr %62, ptr %67, align 8, !tbaa !20
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.func, ptr %69, i32 0, i32 7
  %71 = getelementptr inbounds %struct.symbol_list_t, ptr %70, i32 0, i32 1
  store ptr %68, ptr %71, align 8, !tbaa !26
  br label %72

72:                                               ; preds = %52, %41
  store i32 0, ptr %7, align 4
  br label %73

73:                                               ; preds = %72, %30
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  %74 = load i32, ptr %7, align 4
  switch i32 %74, label %76 [
    i32 0, label %75
    i32 1, label %75
  ]

75:                                               ; preds = %73, %73
  ret void

76:                                               ; preds = %73
  unreachable
}

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 }
attributes #4 = { 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, !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 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 8528}
!12 = !{!"func", !13, i64 0, !7, i64 944, !14, i64 8496, !14, i64 8500, !14, i64 8504, !6, i64 8512, !6, i64 8520, !17, i64 8528, !14, i64 8544, !14, i64 8548, !6, i64 8552}
!13 = !{!"var", !7, i64 0, !7, i64 32, !14, i64 64, !10, i64 68, !10, i64 69, !14, i64 72, !14, i64 76, !14, i64 80, !14, i64 84, !14, i64 88, !6, i64 96, !14, i64 104, !7, i64 112, !14, i64 624, !15, i64 628, !16, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !14, i64 936, !10, i64 940, !10, i64 941, !10, i64 942}
!14 = !{!"int", !7, i64 0}
!15 = !{!"", !14, i64 0, !7, i64 4, !14, i64 260}
!16 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!17 = !{!"", !6, i64 0, !6, i64 8}
!18 = !{!19, !6, i64 0}
!19 = !{!"symbol", !6, i64 0, !14, i64 8, !6, i64 16}
!20 = !{!19, !6, i64 16}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{i8 0, i8 2}
!24 = !{}
!25 = !{!19, !14, i64 8}
!26 = !{!12, !6, i64 8536}


; 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,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind uwtable
define dso_local void @fn_add_global(ptr nocapture noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8528
  %.020 = load ptr, ptr %3, align 8, !tbaa !5
  %.not.not21 = icmp eq ptr %.020, null
  br i1 %.not.not21, label %.critedge.thread, label %.lr.ph

.critedge.thread:                                 ; preds = %2
  %4 = tail call noalias dereferenceable_or_null(24) ptr @calloc(i64 noundef 1, i64 noundef 24) #2
  store ptr %1, ptr %4, align 8, !tbaa !9
  br label %10

5:                                                ; preds = %.lr.ph
  %6 = getelementptr inbounds i8, ptr %.022, i64 16
  %.0 = load ptr, ptr %6, align 8, !tbaa !5
  %.not.not = icmp eq ptr %.0, null
  br i1 %.not.not, label %.critedge, label %.lr.ph, !llvm.loop !12

.lr.ph:                                           ; preds = %2, %5
  %.022 = phi ptr [ %.0, %5 ], [ %.020, %2 ]
  %7 = load ptr, ptr %.022, align 8, !tbaa !9
  %8 = icmp eq ptr %7, %1
  br i1 %8, label %.loopexit, label %5

.critedge:                                        ; preds = %5
  %9 = tail call noalias dereferenceable_or_null(24) ptr @calloc(i64 noundef 1, i64 noundef 24) #2
  store ptr %1, ptr %9, align 8, !tbaa !9
  br i1 %.not.not21, label %10, label %14

10:                                               ; preds = %.critedge.thread, %.critedge
  %11 = phi ptr [ %4, %.critedge.thread ], [ %9, %.critedge ]
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 0, ptr %12, align 8, !tbaa !14
  store ptr %11, ptr %3, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %0, i64 8536
  store ptr %11, ptr %13, align 8, !tbaa !22
  br label %.loopexit

14:                                               ; preds = %.critedge
  %15 = getelementptr inbounds i8, ptr %0, i64 8536
  %16 = load ptr, ptr %15, align 8, !tbaa !22
  %17 = getelementptr inbounds i8, ptr %16, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !14
  %19 = add nsw i32 %18, 1
  %20 = getelementptr inbounds i8, ptr %9, i64 8
  store i32 %19, ptr %20, align 8, !tbaa !14
  %21 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %9, ptr %21, align 8, !tbaa !23
  store ptr %9, ptr %15, align 8, !tbaa !22
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %10, %14
  ret void
}

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 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"symbol", !6, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!10, !11, i64 8}
!15 = !{!16, !6, i64 8528}
!16 = !{!"func", !17, i64 0, !7, i64 944, !11, i64 8496, !11, i64 8500, !11, i64 8504, !6, i64 8512, !6, i64 8520, !21, i64 8528, !11, i64 8544, !11, i64 8548, !6, i64 8552}
!17 = !{!"var", !7, i64 0, !7, i64 32, !11, i64 64, !18, i64 68, !18, i64 69, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88, !6, i64 96, !11, i64 104, !7, i64 112, !11, i64 624, !19, i64 628, !20, i64 896, !6, i64 912, !6, i64 920, !6, i64 928, !11, i64 936, !18, i64 940, !18, i64 941, !18, i64 942}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!"", !11, i64 0, !7, i64 4, !11, i64 260}
!20 = !{!"ref_block_list", !6, i64 0, !6, i64 8}
!21 = !{!"", !6, i64 0, !6, i64 8}
!22 = !{!16, !6, i64 8536}
!23 = !{!10, !6, i64 16}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass