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

@data_info = external hidden global %struct.generaldata, align 8
@write_byte.current_pos = external hidden global i64, align 8
@buffer_writer = external hidden global [1048576 x i8], align 16
@buffer_writer_size = external hidden global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @write_byte(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load i64, ptr @write_byte.current_pos, align 8, !tbaa !9
  %4 = icmp eq i64 %3, 1048576
  br i1 %4, label %5, label %9

5:                                                ; preds = %1
  %6 = load i64, ptr @write_byte.current_pos, align 8, !tbaa !9
  %7 = load ptr, ptr getelementptr inbounds (%struct.generaldata, ptr @data_info, i32 0, i32 1), align 8, !tbaa !11
  %8 = call i64 @fwrite(ptr noundef @buffer_writer, i64 noundef 1, i64 noundef %6, ptr noundef %7)
  store i64 0, ptr @write_byte.current_pos, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %5, %1
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !13
  %12 = load i64, ptr @write_byte.current_pos, align 8, !tbaa !9
  %13 = add i64 %12, 1
  store i64 %13, ptr @write_byte.current_pos, align 8, !tbaa !9
  %14 = getelementptr inbounds [1048576 x i8], ptr @buffer_writer, i64 0, i64 %12
  store i8 %11, ptr %14, align 1, !tbaa !13
  %15 = load i64, ptr @write_byte.current_pos, align 8, !tbaa !9
  %16 = trunc i64 %15 to i32
  store i32 %16, ptr @buffer_writer_size, align 4, !tbaa !14
  %17 = load i32, ptr @buffer_writer_size, align 4, !tbaa !14
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds [1048576 x i8], ptr @buffer_writer, i64 0, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !13
  ret i8 %20
}

declare i64 @fwrite(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, !6, i64 8}
!12 = !{!"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}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"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.generaldata = type { ptr, ptr, [100 x i8], [100 x i8], i64, i64, i64, i64 }

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

; Function Attrs: nofree nounwind uwtable
define dso_local zeroext i8 @write_byte(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i64, ptr @write_byte.current_pos, align 8, !tbaa !5
  %3 = icmp eq i64 %2, 1048576
  br i1 %3, label %4, label %7

4:                                                ; preds = %1
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @data_info, i64 8), align 8, !tbaa !9
  %6 = tail call i64 @fwrite(ptr noundef nonnull @buffer_writer, i64 noundef 1, i64 noundef 1048576, ptr noundef %5)
  store i64 0, ptr @write_byte.current_pos, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %4, %1
  %8 = phi i64 [ 0, %4 ], [ %2, %1 ]
  %9 = load i8, ptr %0, align 1, !tbaa !12
  %10 = add i64 %8, 1
  store i64 %10, ptr @write_byte.current_pos, align 8, !tbaa !5
  %11 = getelementptr inbounds [1048576 x i8], ptr @buffer_writer, i64 0, i64 %8
  store i8 %9, ptr %11, align 1, !tbaa !12
  %12 = trunc i64 %10 to i32
  store i32 %12, ptr @buffer_writer_size, align 4, !tbaa !13
  %13 = and i64 %10, 4294967295
  %14 = getelementptr inbounds [1048576 x i8], ptr @buffer_writer, i64 0, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !12
  ret i8 %15
}

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(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, !11, i64 8}
!10 = !{!"generaldata", !11, i64 0, !11, i64 8, !7, i64 16, !7, i64 116, !6, i64 216, !6, i64 224, !6, i64 232, !6, i64 240}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}


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