; 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 }

@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 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: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

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

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

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

; 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 ptr @offset_index_load(ptr noundef %0) #5 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  %6 = call noalias ptr @malloc(i64 noundef 40) #7
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = call noalias ptr @strdup(ptr noundef %11) #6
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.offset_index, ptr %13, i32 0, i32 1
  store ptr %12, ptr %14, align 8, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = call noalias ptr @fopen(ptr noundef %15, ptr noundef @.str.10)
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.offset_index, ptr %17, i32 0, i32 3
  store ptr %16, ptr %18, align 8, !tbaa !12
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.offset_index, ptr %19, i32 0, i32 3
  %21 = load ptr, ptr %20, align 8, !tbaa !12
  %22 = icmp eq ptr %21, null
  br i1 %22, label %23, label %27

23:                                               ; preds = %10
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.offset_index, ptr %24, i32 0, i32 1
  %26 = load ptr, ptr %25, align 8, !tbaa !9
  call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef @.str.3, ptr noundef %26) #8
  unreachable

27:                                               ; preds = %10
  %28 = call noalias ptr @malloc(i64 noundef 24) #7
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.offset_index, ptr %29, i32 0, i32 0
  store ptr %28, ptr %30, align 8, !tbaa !13
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.offset_index, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !13
  %34 = icmp eq ptr %33, null
  br i1 %34, label %35, label %36

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

36:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.offset_index, ptr %37, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.offset_index, ptr %41, i32 0, i32 3
  %43 = load ptr, ptr %42, align 8, !tbaa !12
  %44 = call i64 @fread(ptr noundef %40, i64 noundef 8, i64 noundef 1, ptr noundef %43)
  store i64 %44, ptr %4, align 8, !tbaa !14
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.offset_index, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !9
  %48 = load ptr, ptr %3, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.offset_index, ptr %48, i32 0, i32 3
  %50 = load ptr, ptr %49, align 8, !tbaa !12
  %51 = load i64, ptr %4, align 8, !tbaa !14
  call void @check_file_read(ptr noundef %47, ptr noundef %50, i64 noundef 1, i64 noundef %51)
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.offset_index, ptr %52, i32 0, i32 2
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.offset_index, ptr %54, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !12
  %57 = call i64 @fread(ptr noundef %53, i64 noundef 4, i64 noundef 1, ptr noundef %56)
  store i64 %57, ptr %4, align 8, !tbaa !14
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.offset_index, ptr %58, i32 0, i32 1
  %60 = load ptr, ptr %59, align 8, !tbaa !9
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.offset_index, ptr %61, i32 0, i32 3
  %63 = load ptr, ptr %62, align 8, !tbaa !12
  %64 = load i64, ptr %4, align 8, !tbaa !14
  call void @check_file_read(ptr noundef %60, ptr noundef %63, i64 noundef 1, i64 noundef %64)
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.offset_index, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !13
  %68 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %67, i32 0, i32 0
  %69 = load i64, ptr %68, align 8, !tbaa !16
  %70 = load ptr, ptr %3, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.offset_index, ptr %70, i32 0, i32 0
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %72, i32 0, i32 1
  store i64 %69, ptr %73, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #6
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.offset_index, ptr %74, i32 0, i32 3
  %76 = load ptr, ptr %75, align 8, !tbaa !12
  %77 = call i32 @fileno(ptr noundef %76) #6
  %78 = call i64 @lseek(i32 noundef %77, i64 noundef 0, i32 noundef 2) #6
  store i64 %78, ptr %5, align 8, !tbaa !14
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.offset_index, ptr %79, i32 0, i32 3
  %81 = load ptr, ptr %80, align 8, !tbaa !12
  call void @rewind(ptr noundef %81)
  %82 = load i64, ptr %5, align 8, !tbaa !14
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.offset_index, ptr %83, i32 0, i32 3
  %85 = load ptr, ptr %84, align 8, !tbaa !12
  %86 = call i32 @fileno(ptr noundef %85) #6
  %87 = call ptr @mmap(ptr noundef null, i64 noundef %82, i32 noundef 1, i32 noundef 1, i32 noundef %86, i64 noundef 0) #6
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.offset_index, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !13
  %91 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %90, i32 0, i32 2
  store ptr %87, ptr %91, align 8, !tbaa !19
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.offset_index, ptr %92, i32 0, i32 0
  %94 = load ptr, ptr %93, align 8, !tbaa !13
  %95 = getelementptr inbounds %struct.file_id_offset_pairs, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !19
  %97 = icmp eq ptr %96, inttoptr (i64 -1 to ptr)
  br i1 %97, label %98, label %99

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

99:                                               ; preds = %36
  %100 = load ptr, ptr %3, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.offset_index, ptr %100, i32 0, i32 4
  store i32 1, ptr %101, align 8, !tbaa !20
  %102 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret ptr %102
}

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #4

declare void @check_file_read(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #4

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) #3

declare void @rewind(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 = { "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 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"offset_index", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24, !11, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 24}
!13 = !{!10, !6, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !15, i64 0}
!17 = !{!"file_id_offset_pairs", !15, i64 0, !15, i64 8, !6, i64 16}
!18 = !{!17, !15, i64 8}
!19 = !{!17, !6, i64 16}
!20 = !{!10, !11, 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"

@.str.3 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [38 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [3 x i8], align 1

; 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: noreturn
declare void @err(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: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

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

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

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

4:                                                ; preds = %1
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.9) #8
  unreachable

5:                                                ; preds = %1
  %6 = tail call noalias ptr @strdup(ptr noundef %0) #9
  %7 = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %6, ptr %7, align 8, !tbaa !5
  %8 = tail call noalias ptr @fopen(ptr noundef %0, ptr noundef nonnull @.str.10)
  %9 = getelementptr inbounds i8, ptr %2, i64 24
  store ptr %8, ptr %9, align 8, !tbaa !11
  %10 = icmp eq ptr %8, null
  br i1 %10, label %11, label %12

11:                                               ; preds = %5
  tail call void (i32, ptr, ...) @err(i32 noundef 1, ptr noundef nonnull @.str.3, ptr noundef %6) #8
  unreachable

12:                                               ; preds = %5
  %13 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #7
  store ptr %13, ptr %2, align 8, !tbaa !12
  %14 = icmp eq ptr %13, null
  br i1 %14, label %15, label %16

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

16:                                               ; preds = %12
  %17 = tail call i64 @fread(ptr noundef nonnull %13, i64 noundef 8, i64 noundef 1, ptr noundef nonnull %8)
  tail call void @check_file_read(ptr noundef %6, ptr noundef nonnull %8, i64 noundef 1, i64 noundef %17) #9
  %18 = getelementptr inbounds i8, ptr %2, i64 16
  %19 = tail call i64 @fread(ptr noundef nonnull %18, i64 noundef 4, i64 noundef 1, ptr noundef nonnull %8)
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load ptr, ptr %9, align 8, !tbaa !11
  tail call void @check_file_read(ptr noundef %20, ptr noundef %21, i64 noundef 1, i64 noundef %19) #9
  %22 = load ptr, ptr %2, align 8, !tbaa !12
  %23 = load i64, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %22, i64 8
  store i64 %23, ptr %24, align 8, !tbaa !16
  %25 = tail call i32 @fileno(ptr noundef %21) #9
  %26 = tail call i64 @lseek(i32 noundef %25, i64 noundef 0, i32 noundef 2) #9
  tail call void @rewind(ptr noundef %21)
  %27 = tail call i32 @fileno(ptr noundef %21) #9
  %28 = tail call ptr @mmap(ptr noundef null, i64 noundef %26, i32 noundef 1, i32 noundef 1, i32 noundef %27, i64 noundef 0) #9
  %29 = getelementptr inbounds i8, ptr %22, i64 16
  store ptr %28, ptr %29, align 8, !tbaa !17
  %30 = icmp eq ptr %28, inttoptr (i64 -1 to ptr)
  br i1 %30, label %31, label %32

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

32:                                               ; preds = %16
  %33 = getelementptr inbounds i8, ptr %2, i64 32
  store i32 1, ptr %33, align 8, !tbaa !18
  ret ptr %2
}

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

declare void @check_file_read(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #6

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

; Function Attrs: nofree nounwind
declare void @rewind(ptr nocapture noundef) local_unnamed_addr #3

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


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