; LLVM IR from ryanlayer/giggle :: src (giggle_index)

; 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.giggle_def = type { %struct.cache_handler, %struct.cache_handler, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.cache_handler = type { ptr, ptr, ptr }
%struct.giggle_index = type { ptr, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.chrm_index = type { ptr, ptr }

@giggle_data_handler = external dso_local global %struct.giggle_def, align 8
@.str.28 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: noreturn
declare void @err(i32 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

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @giggle_store(ptr noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.giggle_index, ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  %9 = getelementptr inbounds %struct.chrm_index, ptr %8, i32 0, i32 0
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  br label %70

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %14 = load ptr, ptr getelementptr inbounds (%struct.giggle_def, ptr @giggle_data_handler, i32 0, i32 10), align 8, !tbaa !14
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  call void %14(ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.giggle_index, ptr %16, i32 0, i32 8
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  %19 = call noalias ptr @fopen(ptr noundef %18, ptr noundef @.str.28)
  store ptr %19, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.giggle_index, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i64 @fwrite(ptr noundef %21, i64 noundef 4, i64 noundef 1, ptr noundef %22)
  %24 = icmp ne i64 %23, 1
  br i1 %24, label %25, label %29

25:                                               ; preds = %13
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.giggle_index, ptr %26, i32 0, i32 8
  %28 = load ptr, ptr %27, align 8, !tbaa !17
  call void (i32, ptr, ...) @err(i32 noundef 74, ptr noundef @.str.29, ptr noundef %28) #5
  unreachable

29:                                               ; preds = %13
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.giggle_index, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = call i64 @fwrite(ptr noundef %31, i64 noundef 4, i64 noundef 1, ptr noundef %32)
  %34 = icmp ne i64 %33, 1
  br i1 %34, label %35, label %39

35:                                               ; preds = %29
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.giggle_index, ptr %36, i32 0, i32 8
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  call void (i32, ptr, ...) @err(i32 noundef 74, ptr noundef @.str.30, ptr noundef %38) #5
  unreachable

39:                                               ; preds = %29
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.giggle_index, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !18
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.giggle_index, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !19
  %46 = zext i32 %45 to i64
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call i64 @fwrite(ptr noundef %42, i64 noundef 4, i64 noundef %46, ptr noundef %47)
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.giggle_index, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = zext i32 %51 to i64
  %53 = icmp ne i64 %48, %52
  br i1 %53, label %54, label %58

54:                                               ; preds = %39
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.giggle_index, ptr %55, i32 0, i32 8
  %57 = load ptr, ptr %56, align 8, !tbaa !17
  call void (i32, ptr, ...) @err(i32 noundef 74, ptr noundef @.str.31, ptr noundef %57) #5
  unreachable

58:                                               ; preds = %39
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = call i32 @fclose(ptr noundef %59)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.giggle_index, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !9
  call void @chrm_index_store(ptr noundef %63)
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.giggle_index, ptr %64, i32 0, i32 4
  %66 = load ptr, ptr %65, align 8, !tbaa !20
  call void @file_index_store(ptr noundef %66)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.giggle_index, ptr %67, i32 0, i32 5
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  call void @offset_index_store(ptr noundef %69)
  store i32 0, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %70

70:                                               ; preds = %58, %12
  %71 = load i32, ptr %2, align 4
  ret i32 %71
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @chrm_index_store(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local void @file_index_store(ptr noundef) #3

declare void @offset_index_store(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn "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 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 #4 = { nounwind }
attributes #5 = { noreturn }

!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 16}
!10 = !{!"giggle_index", !6, i64 0, !11, i64 8, !11, i64 12, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"chrm_index", !6, i64 0, !6, i64 8}
!14 = !{!15, !6, i64 112}
!15 = !{!"giggle_def", !16, i64 0, !16, i64 24, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128}
!16 = !{!"cache_handler", !6, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!10, !6, i64 56}
!18 = !{!10, !6, i64 0}
!19 = !{!10, !11, i64 8}
!20 = !{!10, !6, i64 24}
!21 = !{!10, !6, i64 32}


; 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.giggle_def = type { %struct.cache_handler, %struct.cache_handler, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.cache_handler = type { ptr, ptr, ptr }

@giggle_data_handler = external dso_local local_unnamed_addr global %struct.giggle_def, align 8
@.str.28 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.29 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.30 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.31 = external hidden unnamed_addr constant [29 x i8], align 1

; Function Attrs: noreturn
declare void @err(i32 noundef, ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @giggle_store(ptr noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !11
  %5 = icmp eq ptr %4, null
  br i1 %5, label %36, label %6

6:                                                ; preds = %1
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @giggle_data_handler, i64 112), align 8, !tbaa !13
  tail call void %7(ptr noundef nonnull %0) #4
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %9 = load ptr, ptr %8, align 8, !tbaa !16
  %10 = tail call noalias ptr @fopen(ptr noundef %9, ptr noundef nonnull @.str.28)
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = tail call i64 @fwrite(ptr noundef nonnull %11, i64 noundef 4, i64 noundef 1, ptr noundef %10)
  %.not = icmp eq i64 %12, 1
  br i1 %.not, label %15, label %13

13:                                               ; preds = %6
  %14 = load ptr, ptr %8, align 8, !tbaa !16
  tail call void (i32, ptr, ...) @err(i32 noundef 74, ptr noundef nonnull @.str.29, ptr noundef %14) #5
  unreachable

15:                                               ; preds = %6
  %16 = getelementptr inbounds i8, ptr %0, i64 12
  %17 = tail call i64 @fwrite(ptr noundef nonnull %16, i64 noundef 4, i64 noundef 1, ptr noundef %10)
  %.not18 = icmp eq i64 %17, 1
  br i1 %.not18, label %20, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr %8, align 8, !tbaa !16
  tail call void (i32, ptr, ...) @err(i32 noundef 74, ptr noundef nonnull @.str.30, ptr noundef %19) #5
  unreachable

20:                                               ; preds = %15
  %21 = load ptr, ptr %0, align 8, !tbaa !17
  %22 = load i32, ptr %11, align 8, !tbaa !18
  %23 = zext i32 %22 to i64
  %24 = tail call i64 @fwrite(ptr noundef %21, i64 noundef 4, i64 noundef %23, ptr noundef %10)
  %25 = load i32, ptr %11, align 8, !tbaa !18
  %26 = zext i32 %25 to i64
  %.not19 = icmp eq i64 %24, %26
  br i1 %.not19, label %29, label %27

27:                                               ; preds = %20
  %28 = load ptr, ptr %8, align 8, !tbaa !16
  tail call void (i32, ptr, ...) @err(i32 noundef 74, ptr noundef nonnull @.str.31, ptr noundef %28) #5
  unreachable

29:                                               ; preds = %20
  %30 = tail call i32 @fclose(ptr noundef %10)
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  tail call void @chrm_index_store(ptr noundef %31)
  %32 = getelementptr inbounds i8, ptr %0, i64 24
  %33 = load ptr, ptr %32, align 8, !tbaa !19
  tail call void @file_index_store(ptr noundef %33)
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load ptr, ptr %34, align 8, !tbaa !20
  tail call void @offset_index_store(ptr noundef %35) #4
  br label %36

36:                                               ; preds = %1, %29
  %.0 = phi i32 [ 0, %29 ], [ 1, %1 ]
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @chrm_index_store(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @file_index_store(ptr noundef) local_unnamed_addr #2

declare void @offset_index_store(ptr noundef) local_unnamed_addr #3

attributes #0 = { noreturn "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 "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 = { "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 = { nounwind }
attributes #5 = { noreturn 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 16}
!6 = !{!"giggle_index", !7, i64 0, !10, i64 8, !10, i64 12, !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 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"chrm_index", !7, i64 0, !7, i64 8}
!13 = !{!14, !7, i64 112}
!14 = !{!"giggle_def", !15, i64 0, !15, i64 24, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120, !7, i64 128}
!15 = !{!"cache_handler", !7, i64 0, !7, i64 8, !7, i64 16}
!16 = !{!6, !7, i64 56}
!17 = !{!6, !7, i64 0}
!18 = !{!6, !10, i64 8}
!19 = !{!6, !7, i64 24}
!20 = !{!6, !7, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass