; LLVM IR from ryanlayer/giggle :: src (offset_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.offset_index = type { ptr, ptr, i32, ptr, i32 }
%struct.file_id_offset_pairs = type { i64, i64, ptr }

@offset_data_size = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @offset_index_init(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %7 = call noalias ptr @malloc(i64 noundef 40) #7
  store ptr %7, ptr %5, align 8, !tbaa !9
  %8 = load ptr, ptr %5, align 8, !tbaa !9
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.1) #8
  unreachable

11:                                               ; preds = %2
  %12 = load i32, ptr @offset_data_size, align 4, !tbaa !5
  %13 = zext i32 %12 to i64
  %14 = add i64 16, %13
  %15 = trunc i64 %14 to i32
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds %struct.offset_index, ptr %16, i32 0, i32 2
  store i32 %15, ptr %17, align 8, !tbaa !11
  %18 = call noalias ptr @malloc(i64 noundef 24) #7
  %19 = load ptr, ptr %5, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.offset_index, ptr %19, i32 0, i32 0
  store ptr %18, ptr %20, align 8, !tbaa !13
  %21 = load ptr, ptr %5, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.offset_index, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %11
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.1) #8
  unreachable

26:                                               ; preds = %11
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  %28 = getelementptr inbounds %struct.offset_index, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %29, i32 0, i32 0
  store i64 0, ptr %30, align 8, !tbaa !14
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = getelementptr inbounds %struct.offset_index, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %35, i32 0, i32 1
  store i64 %32, ptr %36, align 8, !tbaa !17
  %37 = load ptr, ptr %5, align 8, !tbaa !9
  %38 = getelementptr inbounds %struct.offset_index, ptr %37, i32 0, i32 1
  store ptr null, ptr %38, align 8, !tbaa !18
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %46

41:                                               ; preds = %26
  %42 = load ptr, ptr %4, align 8, !tbaa !9
  %43 = call noalias ptr @strdup(ptr noundef %42) #6
  %44 = load ptr, ptr %5, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.offset_index, ptr %44, i32 0, i32 1
  store ptr %43, ptr %45, align 8, !tbaa !18
  br label %46

46:                                               ; preds = %41, %26
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.offset_index, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = call noalias ptr @fopen(ptr noundef %49, ptr noundef @.str.2)
  %51 = load ptr, ptr %5, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.offset_index, ptr %51, i32 0, i32 3
  store ptr %50, ptr %52, align 8, !tbaa !19
  %53 = load ptr, ptr %5, align 8, !tbaa !9
  %54 = getelementptr inbounds %struct.offset_index, ptr %53, i32 0, i32 3
  %55 = load ptr, ptr %54, align 8, !tbaa !19
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %61

57:                                               ; preds = %46
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.offset_index, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !18
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.3, ptr noundef %60) #8
  unreachable

61:                                               ; preds = %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %62 = load ptr, ptr %5, align 8, !tbaa !9
  %63 = getelementptr inbounds %struct.offset_index, ptr %62, i32 0, i32 3
  %64 = load ptr, ptr %63, align 8, !tbaa !19
  %65 = call i32 @fileno(ptr noundef %64) #6
  %66 = load ptr, ptr %5, align 8, !tbaa !9
  %67 = getelementptr inbounds %struct.offset_index, ptr %66, i32 0, i32 0
  %68 = load ptr, ptr %67, align 8, !tbaa !13
  %69 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %68, i32 0, i32 1
  %70 = load i64, ptr %69, align 8, !tbaa !17
  %71 = load ptr, ptr %5, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.offset_index, ptr %71, i32 0, i32 2
  %73 = load i32, ptr %72, align 8, !tbaa !11
  %74 = zext i32 %73 to i64
  %75 = mul i64 %70, %74
  %76 = add i64 12, %75
  %77 = call i32 @ftruncate(i32 noundef %65, i64 noundef %76) #6
  store i32 %77, ptr %6, align 4, !tbaa !5
  %78 = load i32, ptr %6, align 4, !tbaa !5
  %79 = icmp ne i32 %78, 0
  br i1 %79, label %80, label %84

80:                                               ; preds = %61
  %81 = load ptr, ptr %5, align 8, !tbaa !9
  %82 = getelementptr inbounds %struct.offset_index, ptr %81, i32 0, i32 1
  %83 = load ptr, ptr %82, align 8, !tbaa !18
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.4, ptr noundef %83) #8
  unreachable

84:                                               ; preds = %61
  %85 = load ptr, ptr %5, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.offset_index, ptr %85, i32 0, i32 0
  %87 = load ptr, ptr %86, align 8, !tbaa !13
  %88 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %87, i32 0, i32 1
  %89 = load i64, ptr %88, align 8, !tbaa !17
  %90 = load ptr, ptr %5, align 8, !tbaa !9
  %91 = getelementptr inbounds %struct.offset_index, ptr %90, i32 0, i32 2
  %92 = load i32, ptr %91, align 8, !tbaa !11
  %93 = zext i32 %92 to i64
  %94 = mul i64 %89, %93
  %95 = load ptr, ptr %5, align 8, !tbaa !9
  %96 = getelementptr inbounds %struct.offset_index, ptr %95, i32 0, i32 3
  %97 = load ptr, ptr %96, align 8, !tbaa !19
  %98 = call i32 @fileno(ptr noundef %97) #6
  %99 = call ptr @mmap(ptr noundef null, i64 noundef %94, i32 noundef 3, i32 noundef 1, i32 noundef %98, i64 noundef 0) #6
  %100 = load ptr, ptr %5, align 8, !tbaa !9
  %101 = getelementptr inbounds %struct.offset_index, ptr %100, i32 0, i32 0
  %102 = load ptr, ptr %101, align 8, !tbaa !13
  %103 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %102, i32 0, i32 2
  store ptr %99, ptr %103, align 8, !tbaa !20
  %104 = load ptr, ptr %5, align 8, !tbaa !9
  %105 = getelementptr inbounds %struct.offset_index, ptr %104, i32 0, i32 0
  %106 = load ptr, ptr %105, align 8, !tbaa !13
  %107 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %106, i32 0, i32 2
  %108 = load ptr, ptr %107, align 8, !tbaa !20
  %109 = icmp eq ptr %108, inttoptr (i64 -1 to ptr)
  br i1 %109, label %110, label %111

110:                                              ; preds = %84
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.5) #8
  unreachable

111:                                              ; preds = %84
  %112 = load ptr, ptr %5, align 8, !tbaa !9
  %113 = getelementptr inbounds %struct.offset_index, ptr %112, i32 0, i32 4
  store i32 1, ptr %113, align 8, !tbaa !21
  %114 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  ret ptr %114
}

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

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

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

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

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

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) #4

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #4

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) #4

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 #5 = { "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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { 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 = !{!"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}
!11 = !{!12, !6, i64 16}
!12 = !{!"offset_index", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24, !6, i64 32}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !16, i64 0}
!15 = !{!"file_id_offset_pairs", !16, i64 0, !16, i64 8, !10, i64 16}
!16 = !{!"long", !7, i64 0}
!17 = !{!15, !16, i64 8}
!18 = !{!12, !10, i64 8}
!19 = !{!12, !10, i64 24}
!20 = !{!15, !10, i64 16}
!21 = !{!12, !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"

@offset_data_size = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @offset_index_init(i32 noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(40) ptr @malloc(i64 noundef 40) #6
  %4 = icmp eq ptr %3, null
  br i1 %4, label %5, label %6

5:                                                ; preds = %2
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.1) #7
  unreachable

6:                                                ; preds = %2
  %7 = load i32, ptr @offset_data_size, align 4, !tbaa !5
  %8 = add i32 %7, 16
  %9 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 %8, ptr %9, align 8, !tbaa !9
  %10 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #6
  store ptr %10, ptr %3, align 8, !tbaa !12
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %6
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.1) #7
  unreachable

13:                                               ; preds = %6
  store i64 0, ptr %10, align 8, !tbaa !13
  %14 = zext i32 %0 to i64
  %15 = getelementptr inbounds i8, ptr %10, i64 8
  store i64 %14, ptr %15, align 8, !tbaa !16
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr null, ptr %16, align 8, !tbaa !17
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %19, label %17

17:                                               ; preds = %13
  %18 = tail call noalias ptr @strdup(ptr noundef nonnull %1) #8
  store ptr %18, ptr %16, align 8, !tbaa !17
  br label %19

19:                                               ; preds = %17, %13
  %20 = phi ptr [ %18, %17 ], [ null, %13 ]
  %21 = tail call noalias ptr @fopen(ptr noundef %20, ptr noundef nonnull @.str.2)
  %22 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %21, ptr %22, align 8, !tbaa !18
  %23 = icmp eq ptr %21, null
  br i1 %23, label %24, label %25

24:                                               ; preds = %19
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.3, ptr noundef %20) #7
  unreachable

25:                                               ; preds = %19
  %26 = tail call i32 @fileno(ptr noundef nonnull %21) #8
  %27 = load i64, ptr %15, align 8, !tbaa !16
  %28 = zext i32 %8 to i64
  %29 = mul i64 %27, %28
  %30 = add i64 %29, 12
  %31 = tail call i32 @ftruncate(i32 noundef %26, i64 noundef %30) #8
  %.not29 = icmp eq i32 %31, 0
  br i1 %.not29, label %33, label %32

32:                                               ; preds = %25
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.4, ptr noundef %20) #7
  unreachable

33:                                               ; preds = %25
  %34 = load i64, ptr %15, align 8, !tbaa !16
  %35 = mul i64 %34, %28
  %36 = tail call i32 @fileno(ptr noundef nonnull %21) #8
  %37 = tail call ptr @mmap(ptr noundef null, i64 noundef %35, i32 noundef 3, i32 noundef 1, i32 noundef %36, i64 noundef 0) #8
  %38 = getelementptr inbounds i8, ptr %10, i64 16
  store ptr %37, ptr %38, align 8, !tbaa !19
  %39 = icmp eq ptr %37, inttoptr (i64 -1 to ptr)
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.5) #7
  unreachable

41:                                               ; preds = %33
  %42 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 1, ptr %42, align 8, !tbaa !20
  ret ptr %3
}

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @ftruncate(i32 noundef, i64 noundef) local_unnamed_addr #5

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

; Function Attrs: nounwind
declare ptr @mmap(ptr noundef, i64 noundef, i32 noundef, i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #5

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 = { 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 #2 = { 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 #3 = { 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 #4 = { 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 #5 = { 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 #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"offset_index", !11, i64 0, !11, i64 8, !6, i64 16, !11, i64 24, !6, i64 32}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"file_id_offset_pairs", !15, i64 0, !15, i64 8, !11, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!14, !15, i64 8}
!17 = !{!10, !11, i64 8}
!18 = !{!10, !11, i64 24}
!19 = !{!14, !11, i64 16}
!20 = !{!10, !6, i64 32}


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