; LLVM IR from ohler55/agoo :: ext/agoo (page)

; 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._cache = type { [1024 x ptr], [1024 x ptr], [64 x ptr], ptr, ptr, ptr }
%struct._mime = type { ptr, ptr }
%struct._agooErr = type { i32, [256 x i8] }

@cache = external hidden global %struct._cache, align 8
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@mime_map = external hidden global [44 x %struct._mime], align 16

; 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
declare dso_local i32 @mime_set(ptr noundef, ptr noundef, ptr noundef) #1

declare i32 @agoo_err_set(ptr noundef, i32 noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @agoo_pages_init(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.memset.p0.i64(ptr align 8 @cache, i8 0, i64 16920, i1 false)
  %6 = call noalias ptr @strdup(ptr noundef @.str.4) #5
  store ptr %6, ptr getelementptr inbounds (%struct._cache, ptr @cache, i32 0, i32 3), align 8, !tbaa !9
  %7 = icmp eq ptr null, %6
  br i1 %7, label %8, label %11

8:                                                ; preds = %1
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 (ptr, i32, ptr, ...) @agoo_err_set(ptr noundef %9, i32 noundef 304, ptr noundef @.str.5)
  store i32 %10, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %33

11:                                               ; preds = %1
  store ptr @mime_map, ptr %4, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %26, %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._mime, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  %16 = icmp ne ptr null, %15
  br i1 %16, label %17, label %29

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct._mime, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._mime, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = call i32 @mime_set(ptr noundef %18, ptr noundef %21, ptr noundef %24)
  br label %26

26:                                               ; preds = %17
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._mime, ptr %27, i32 1
  store ptr %28, ptr %4, align 8, !tbaa !5
  br label %12, !llvm.loop !14

29:                                               ; preds = %12
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._agooErr, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !16
  store i32 %32, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %33

33:                                               ; preds = %29, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %34 = load i32, ptr %2, align 4
  ret i32 %34
}

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

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 = { "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 "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 }

!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 16896}
!10 = !{!"_cache", !7, i64 0, !7, i64 8192, !7, i64 16384, !6, i64 16896, !6, i64 16904, !6, i64 16912}
!11 = !{!12, !6, i64 0}
!12 = !{!"_mime", !6, i64 0, !6, i64 8}
!13 = !{!12, !6, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !18, i64 0}
!17 = !{!"_agooErr", !18, i64 0, !7, i64 4}
!18 = !{!"int", !7, 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._cache = type { [1024 x ptr], [1024 x ptr], [64 x ptr], ptr, ptr, ptr }
%struct._mime = type { ptr, ptr }

@cache = external hidden local_unnamed_addr global %struct._cache, align 8
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [35 x i8], align 1
@mime_map = external hidden local_unnamed_addr global [44 x %struct._mime], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @mime_set(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare i32 @agoo_err_set(ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; 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: nounwind uwtable
define dso_local i32 @agoo_pages_init(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16920) @cache, i8 0, i64 16920, i1 false)
  %2 = tail call noalias ptr @strdup(ptr noundef nonnull @.str.4) #4
  store ptr %2, ptr getelementptr inbounds (i8, ptr @cache, i64 16896), align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %5, label %.preheader

.preheader:                                       ; preds = %1
  %4 = load ptr, ptr @mime_map, align 16, !tbaa !10
  %.not9 = icmp eq ptr %4, null
  br i1 %.not9, label %._crit_edge, label %.lr.ph

5:                                                ; preds = %1
  %6 = tail call i32 (ptr, i32, ptr, ...) @agoo_err_set(ptr noundef %0, i32 noundef 304, ptr noundef nonnull @.str.5) #4
  br label %14

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %7 = phi ptr [ %12, %.lr.ph ], [ %4, %.preheader ]
  %.010 = phi ptr [ %11, %.lr.ph ], [ @mime_map, %.preheader ]
  %8 = getelementptr inbounds i8, ptr %.010, i64 8
  %9 = load ptr, ptr %8, align 8, !tbaa !12
  %10 = tail call i32 @mime_set(ptr noundef %0, ptr noundef nonnull %7, ptr noundef %9)
  %11 = getelementptr inbounds i8, ptr %.010, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !10
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %13 = load i32, ptr %0, align 4, !tbaa !15
  br label %14

14:                                               ; preds = %._crit_edge, %5
  %.07 = phi i32 [ %6, %5 ], [ %13, %._crit_edge ]
  ret i32 %.07
}

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

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 = { "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 nocallback nofree nounwind willreturn memory(argmem: write) }
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, !9, i64 16896}
!6 = !{!"_cache", !7, i64 0, !7, i64 8192, !7, i64 16384, !9, i64 16896, !9, i64 16904, !9, i64 16912}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!11, !9, i64 0}
!11 = !{!"_mime", !9, i64 0, !9, i64 8}
!12 = !{!11, !9, i64 8}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !17, i64 0}
!16 = !{!"_agooErr", !17, i64 0, !7, i64 4}
!17 = !{!"int", !7, i64 0}


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