; LLVM IR from theolundqvist/parallax-voxel-ray-marcher :: src/core/LogView.ll (ZN3Log4View4FeedENS_4TypeEPKc)

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

@_ZN3Log4View7mBufferE = external dso_local global [64 x [512 x i8]], align 16
@_ZN3Log4View4mLenE = external dso_local global [64 x i32], align 16
@_ZN3Log4View5mTypeE = external dso_local global [64 x i32], align 16
@_ZN3Log4View10mBufferPtrE = external dso_local global i32, align 4
@_ZN3Log4View15mScrollToBottomE = external dso_local global i8, align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3Log4View4FeedENS_4TypeEPKc(i32 noundef %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  %5 = load i32, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !11
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [64 x [512 x i8]], ptr @_ZN3Log4View7mBufferE, i64 0, i64 %6
  %8 = getelementptr inbounds [512 x i8], ptr %7, i64 0, i64 0
  %9 = load ptr, ptr %4, align 8, !tbaa !9
  %10 = call ptr @strncpy(ptr noundef %8, ptr noundef %9, i64 noundef 511) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !9
  %12 = call i64 @strlen(ptr noundef %11) #4
  %13 = trunc i64 %12 to i32
  %14 = load i32, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [64 x i32], ptr @_ZN3Log4View4mLenE, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !11
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !11
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [64 x i32], ptr @_ZN3Log4View5mTypeE, i64 0, i64 %19
  store i32 %17, ptr %20, align 4, !tbaa !5
  %21 = load i32, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !11
  %22 = add nsw i32 %21, 1
  %23 = srem i32 %22, 64
  store i32 %23, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !11
  store i8 1, ptr @_ZN3Log4View15mScrollToBottomE, align 1, !tbaa !13
  ret void
}

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

attributes #0 = { mustprogress 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 = { 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 willreturn memory(read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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 = !{!"_ZTSN3Log4TypeE", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !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"

@_ZN3Log4View7mBufferE = external dso_local global [64 x [512 x i8]], align 16
@_ZN3Log4View4mLenE = external dso_local local_unnamed_addr global [64 x i32], align 16
@_ZN3Log4View5mTypeE = external dso_local local_unnamed_addr global [64 x i32], align 16
@_ZN3Log4View10mBufferPtrE = external dso_local local_unnamed_addr global i32, align 4
@_ZN3Log4View15mScrollToBottomE = external dso_local local_unnamed_addr global i8, align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_ZN3Log4View4FeedENS_4TypeEPKc(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 align 2 {
  %3 = load i32, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [64 x [512 x i8]], ptr @_ZN3Log4View7mBufferE, i64 0, i64 %4
  %6 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %5, ptr noundef nonnull dereferenceable(1) %1, i64 noundef 511) #3
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #4
  %8 = trunc i64 %7 to i32
  %9 = getelementptr inbounds [64 x i32], ptr @_ZN3Log4View4mLenE, i64 0, i64 %4
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds [64 x i32], ptr @_ZN3Log4View5mTypeE, i64 0, i64 %4
  store i32 %0, ptr %10, align 4, !tbaa !9
  %11 = add nsw i32 %3, 1
  %12 = srem i32 %11, 64
  store i32 %12, ptr @_ZN3Log4View10mBufferPtrE, align 4, !tbaa !5
  store i8 1, ptr @_ZN3Log4View15mScrollToBottomE, align 1, !tbaa !11
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: none) 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 memory(argmem: readwrite) "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: read) "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 }
attributes #4 = { nounwind willreturn memory(read) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTSN3Log4TypeE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}


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