; 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.block_list_t = type { ptr, ptr }

@elf_header_len = external dso_local global i32, align 4
@TYPES = external dso_local global ptr, align 8
@GLOBAL_IR = external dso_local global ptr, align 8
@PH1_IR = external dso_local global ptr, align 8
@PH2_IR_FLATTEN = external dso_local global ptr, align 8
@BB_ARENA = external dso_local global ptr, align 8
@BLOCKS = external dso_local global %struct.block_list_t, align 8
@ALIASES_MAP = external dso_local global ptr, align 8
@MACROS = external dso_local global ptr, align 8
@CONSTANTS_MAP = external dso_local global ptr, align 8
@FUNC_MAP = external dso_local global ptr, align 8
@INSN_ARENA = external dso_local global ptr, align 8
@elf_code_start = external dso_local global i32, align 4
@SOURCE = external dso_local global ptr, align 8
@INCLUSION_MAP = external dso_local global ptr, align 8
@elf_code = external dso_local global ptr, align 8
@elf_data = external dso_local global ptr, align 8
@elf_header = external dso_local global ptr, align 8
@elf_symtab = external dso_local global ptr, align 8
@elf_strtab = external dso_local global ptr, align 8
@elf_section = external dso_local global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @arena_init(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @hashmap_create(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @source_create(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @global_init() #1 {
  %1 = load i32, ptr @elf_header_len, align 4, !tbaa !5
  %2 = add nsw i32 65536, %1
  store i32 %2, ptr @elf_code_start, align 4, !tbaa !5
  store ptr null, ptr @BLOCKS, align 8, !tbaa !9
  store ptr null, ptr getelementptr inbounds (%struct.block_list_t, ptr @BLOCKS, i32 0, i32 1), align 8, !tbaa !12
  %3 = call noalias ptr @malloc(i64 noundef 7823360) #2
  store ptr %3, ptr @MACROS, align 8, !tbaa !13
  %4 = call ptr @hashmap_create(i32 noundef 64)
  store ptr %4, ptr @FUNC_MAP, align 8, !tbaa !13
  %5 = call noalias ptr @malloc(i64 noundef 3870720) #2
  store ptr %5, ptr @TYPES, align 8, !tbaa !13
  %6 = call noalias ptr @malloc(i64 noundef 18432) #2
  store ptr %6, ptr @GLOBAL_IR, align 8, !tbaa !13
  %7 = call noalias ptr @malloc(i64 noundef 4320000) #2
  store ptr %7, ptr @PH1_IR, align 8, !tbaa !13
  %8 = call ptr @arena_init(i32 noundef 262144)
  store ptr %8, ptr @INSN_ARENA, align 8, !tbaa !13
  %9 = call ptr @arena_init(i32 noundef 262144)
  store ptr %9, ptr @BB_ARENA, align 8, !tbaa !13
  %10 = call noalias ptr @malloc(i64 noundef 480000) #2
  store ptr %10, ptr @PH2_IR_FLATTEN, align 8, !tbaa !13
  %11 = call ptr @source_create(i32 noundef 524288)
  store ptr %11, ptr @SOURCE, align 8, !tbaa !13
  %12 = call ptr @hashmap_create(i32 noundef 16)
  store ptr %12, ptr @INCLUSION_MAP, align 8, !tbaa !13
  %13 = call ptr @hashmap_create(i32 noundef 1024)
  store ptr %13, ptr @ALIASES_MAP, align 8, !tbaa !13
  %14 = call ptr @hashmap_create(i32 noundef 1024)
  store ptr %14, ptr @CONSTANTS_MAP, align 8, !tbaa !13
  %15 = call noalias ptr @malloc(i64 noundef 262144) #2
  store ptr %15, ptr @elf_code, align 8, !tbaa !13
  %16 = call noalias ptr @malloc(i64 noundef 262144) #2
  store ptr %16, ptr @elf_data, align 8, !tbaa !13
  %17 = call noalias ptr @malloc(i64 noundef 1024) #2
  store ptr %17, ptr @elf_header, align 8, !tbaa !13
  %18 = call noalias ptr @malloc(i64 noundef 65536) #2
  store ptr %18, ptr @elf_symtab, align 8, !tbaa !13
  %19 = call noalias ptr @malloc(i64 noundef 65536) #2
  store ptr %19, ptr @elf_strtab, align 8, !tbaa !13
  %20 = call noalias ptr @malloc(i64 noundef 1024) #2
  store ptr %20, ptr @elf_section, align 8, !tbaa !13
  ret void
}

attributes #0 = { 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 #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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}


; 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.block_list_t = type { ptr, ptr }

@elf_header_len = external dso_local local_unnamed_addr global i32, align 4
@TYPES = external dso_local local_unnamed_addr global ptr, align 8
@GLOBAL_IR = external dso_local local_unnamed_addr global ptr, align 8
@PH1_IR = external dso_local local_unnamed_addr global ptr, align 8
@PH2_IR_FLATTEN = external dso_local local_unnamed_addr global ptr, align 8
@BB_ARENA = external dso_local local_unnamed_addr global ptr, align 8
@BLOCKS = external dso_local local_unnamed_addr global %struct.block_list_t, align 8
@ALIASES_MAP = external dso_local local_unnamed_addr global ptr, align 8
@MACROS = external dso_local local_unnamed_addr global ptr, align 8
@CONSTANTS_MAP = external dso_local local_unnamed_addr global ptr, align 8
@FUNC_MAP = external dso_local local_unnamed_addr global ptr, align 8
@INSN_ARENA = external dso_local local_unnamed_addr global ptr, align 8
@elf_code_start = external dso_local local_unnamed_addr global i32, align 4
@SOURCE = external dso_local local_unnamed_addr global ptr, align 8
@INCLUSION_MAP = external dso_local local_unnamed_addr global ptr, align 8
@elf_code = external dso_local local_unnamed_addr global ptr, align 8
@elf_data = external dso_local local_unnamed_addr global ptr, align 8
@elf_header = external dso_local local_unnamed_addr global ptr, align 8
@elf_symtab = external dso_local local_unnamed_addr global ptr, align 8
@elf_strtab = external dso_local local_unnamed_addr global ptr, align 8
@elf_section = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @arena_init(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @hashmap_create(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @source_create(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @global_init() local_unnamed_addr #1 {
  %1 = load i32, ptr @elf_header_len, align 4, !tbaa !5
  %2 = add nsw i32 %1, 65536
  store i32 %2, ptr @elf_code_start, align 4, !tbaa !5
  %3 = tail call noalias dereferenceable_or_null(7823360) ptr @malloc(i64 noundef 7823360) #3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) @BLOCKS, i8 0, i64 16, i1 false)
  store ptr %3, ptr @MACROS, align 8, !tbaa !9
  %4 = tail call ptr @hashmap_create(i32 noundef 64)
  store ptr %4, ptr @FUNC_MAP, align 8, !tbaa !9
  %5 = tail call noalias dereferenceable_or_null(3870720) ptr @malloc(i64 noundef 3870720) #3
  store ptr %5, ptr @TYPES, align 8, !tbaa !9
  %6 = tail call noalias dereferenceable_or_null(18432) ptr @malloc(i64 noundef 18432) #3
  store ptr %6, ptr @GLOBAL_IR, align 8, !tbaa !9
  %7 = tail call noalias dereferenceable_or_null(4320000) ptr @malloc(i64 noundef 4320000) #3
  store ptr %7, ptr @PH1_IR, align 8, !tbaa !9
  %8 = tail call ptr @arena_init(i32 noundef 262144)
  store ptr %8, ptr @INSN_ARENA, align 8, !tbaa !9
  %9 = tail call ptr @arena_init(i32 noundef 262144)
  store ptr %9, ptr @BB_ARENA, align 8, !tbaa !9
  %10 = tail call noalias dereferenceable_or_null(480000) ptr @malloc(i64 noundef 480000) #3
  store ptr %10, ptr @PH2_IR_FLATTEN, align 8, !tbaa !9
  %11 = tail call ptr @source_create(i32 noundef 524288)
  store ptr %11, ptr @SOURCE, align 8, !tbaa !9
  %12 = tail call ptr @hashmap_create(i32 noundef 16)
  store ptr %12, ptr @INCLUSION_MAP, align 8, !tbaa !9
  %13 = tail call ptr @hashmap_create(i32 noundef 1024)
  store ptr %13, ptr @ALIASES_MAP, align 8, !tbaa !9
  %14 = tail call ptr @hashmap_create(i32 noundef 1024)
  store ptr %14, ptr @CONSTANTS_MAP, align 8, !tbaa !9
  %15 = tail call noalias dereferenceable_or_null(262144) ptr @malloc(i64 noundef 262144) #3
  store ptr %15, ptr @elf_code, align 8, !tbaa !9
  %16 = tail call noalias dereferenceable_or_null(262144) ptr @malloc(i64 noundef 262144) #3
  store ptr %16, ptr @elf_data, align 8, !tbaa !9
  %17 = tail call noalias dereferenceable_or_null(1024) ptr @malloc(i64 noundef 1024) #3
  store ptr %17, ptr @elf_header, align 8, !tbaa !9
  %18 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #3
  store ptr %18, ptr @elf_symtab, align 8, !tbaa !9
  %19 = tail call noalias dereferenceable_or_null(65536) ptr @malloc(i64 noundef 65536) #3
  store ptr %19, ptr @elf_strtab, align 8, !tbaa !9
  %20 = tail call noalias dereferenceable_or_null(1024) ptr @malloc(i64 noundef 1024) #3
  store ptr %20, ptr @elf_section, align 8, !tbaa !9
  ret void
}

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

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


; Effective O3 passes: GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,TailCallElimPass