; LLVM IR from m-boutaleb/LZS :: src (data_repository)

; 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.generaldata = type { ptr, ptr, [100 x i8], [100 x i8], i64, i64, i64, i64 }

@read_byte.current_pos = external hidden global i64, align 8
@buffer_reader_size = external hidden global i32, align 4
@buffer_reader = external hidden global [1048576 x i8], align 16
@data_info = external hidden global %struct.generaldata, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @read_byte(ptr noundef %0) #0 {
  %2 = alloca i8, align 1
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load i64, ptr @read_byte.current_pos, align 8, !tbaa !9
  %5 = load i32, ptr @buffer_reader_size, align 4, !tbaa !11
  %6 = zext i32 %5 to i64
  %7 = icmp eq i64 %4, %6
  br i1 %7, label %8, label %16

8:                                                ; preds = %1
  %9 = load ptr, ptr @data_info, align 8, !tbaa !13
  %10 = call i64 @fread(ptr noundef @buffer_reader, i64 noundef 1, i64 noundef 1048576, ptr noundef %9)
  %11 = trunc i64 %10 to i32
  store i32 %11, ptr @buffer_reader_size, align 4, !tbaa !11
  store i64 0, ptr @read_byte.current_pos, align 8, !tbaa !9
  %12 = load i32, ptr @buffer_reader_size, align 4, !tbaa !11
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %8
  store i8 0, ptr %2, align 1
  br label %22

15:                                               ; preds = %8
  br label %16

16:                                               ; preds = %15, %1
  %17 = load i64, ptr @read_byte.current_pos, align 8, !tbaa !9
  %18 = add i64 %17, 1
  store i64 %18, ptr @read_byte.current_pos, align 8, !tbaa !9
  %19 = getelementptr inbounds [1048576 x i8], ptr @buffer_reader, i64 0, i64 %17
  %20 = load i8, ptr %19, align 1, !tbaa !15
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  store i8 %20, ptr %21, align 1, !tbaa !15
  store i8 1, ptr %2, align 1
  br label %22

22:                                               ; preds = %16, %14
  %23 = load i8, ptr %2, align 1
  ret i8 %23
}

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #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 = { "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" }

!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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"generaldata", !6, i64 0, !6, i64 8, !7, i64 16, !7, i64 116, !10, i64 216, !10, i64 224, !10, i64 232, !10, i64 240}
!15 = !{!7, !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.generaldata = type { ptr, ptr, [100 x i8], [100 x i8], i64, i64, i64, i64 }

@read_byte.current_pos = external hidden local_unnamed_addr global i64, align 8
@buffer_reader_size = external hidden local_unnamed_addr global i32, align 4
@buffer_reader = external hidden global [1048576 x i8], align 16
@data_info = external hidden local_unnamed_addr global %struct.generaldata, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @read_byte(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @read_byte.current_pos, align 8, !tbaa !5
  %3 = load i32, ptr @buffer_reader_size, align 4, !tbaa !9
  %4 = zext i32 %3 to i64
  %5 = icmp eq i64 %2, %4
  br i1 %5, label %6, label %11

6:                                                ; preds = %1
  %7 = load ptr, ptr @data_info, align 8, !tbaa !11
  %8 = tail call i64 @fread(ptr noundef nonnull @buffer_reader, i64 noundef 1, i64 noundef 1048576, ptr noundef %7)
  %9 = trunc i64 %8 to i32
  store i32 %9, ptr @buffer_reader_size, align 4, !tbaa !9
  store i64 0, ptr @read_byte.current_pos, align 8, !tbaa !5
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %16, label %11

11:                                               ; preds = %6, %1
  %12 = phi i64 [ 0, %6 ], [ %2, %1 ]
  %13 = add i64 %12, 1
  store i64 %13, ptr @read_byte.current_pos, align 8, !tbaa !5
  %14 = getelementptr inbounds [1048576 x i8], ptr @buffer_reader, i64 0, i64 %12
  %15 = load i8, ptr %14, align 1, !tbaa !14
  store i8 %15, ptr %0, align 1, !tbaa !14
  br label %16

16:                                               ; preds = %6, %11
  %.0 = phi i8 [ 1, %11 ], [ 0, %6 ]
  ret i8 %.0
}

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

attributes #0 = { nofree 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 = { 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" }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"generaldata", !13, i64 0, !13, i64 8, !7, i64 16, !7, i64 116, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!7, !7, i64 0}


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