; LLVM IR from ElsevierSoftwareX/SOFTX-D-20-00016 :: GameplayFootball/src/libs/glee/GLee.ll_ (GLeeWriteError)

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

@GLeeErrorString = external dso_local global [256 x i8], align 16

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

; 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 void @__GLeeWriteError(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 0, ptr %3, align 4, !tbaa !9
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %4

4:                                                ; preds = %16, %1
  %5 = load i32, ptr %3, align 4, !tbaa !9
  %6 = icmp slt i32 %5, 256
  br i1 %6, label %7, label %19

7:                                                ; preds = %4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = load i32, ptr %3, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i8, ptr %8, i64 %10
  %12 = load i8, ptr %11, align 1, !tbaa !11
  %13 = load i32, ptr %3, align 4, !tbaa !9
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [256 x i8], ptr @GLeeErrorString, i64 0, i64 %14
  store i8 %12, ptr %15, align 1, !tbaa !11
  br label %16

16:                                               ; preds = %7
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %3, align 4, !tbaa !9
  br label %4, !llvm.loop !12

19:                                               ; preds = %4
  store i8 0, ptr getelementptr inbounds ([256 x i8], ptr @GLeeErrorString, i64 0, i64 255), align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = !{!"any pointer", !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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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

@GLeeErrorString = external dso_local local_unnamed_addr global [256 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(write, argmem: read, inaccessiblemem: none) uwtable
define dso_local void @__GLeeWriteError(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
vector.memcheck:
  %1 = ptrtoint ptr %0 to i64
  %2 = sub i64 ptrtoint (ptr @GLeeErrorString to i64), %1
  %diff.check = icmp ult i64 %2, 32
  br i1 %diff.check, label %scalar.ph, label %vector.body

vector.body:                                      ; preds = %vector.memcheck
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %wide.load = load <16 x i8>, ptr %0, align 1, !tbaa !5
  %wide.load6 = load <16 x i8>, ptr %3, align 1, !tbaa !5
  store <16 x i8> %wide.load, ptr @GLeeErrorString, align 16, !tbaa !5
  store <16 x i8> %wide.load6, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 16), align 16, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  %wide.load.1 = load <16 x i8>, ptr %4, align 1, !tbaa !5
  %wide.load6.1 = load <16 x i8>, ptr %5, align 1, !tbaa !5
  store <16 x i8> %wide.load.1, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 32), align 16, !tbaa !5
  store <16 x i8> %wide.load6.1, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 48), align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  %wide.load.2 = load <16 x i8>, ptr %6, align 1, !tbaa !5
  %wide.load6.2 = load <16 x i8>, ptr %7, align 1, !tbaa !5
  store <16 x i8> %wide.load.2, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 64), align 16, !tbaa !5
  store <16 x i8> %wide.load6.2, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 80), align 16, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 96
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  %wide.load.3 = load <16 x i8>, ptr %8, align 1, !tbaa !5
  %wide.load6.3 = load <16 x i8>, ptr %9, align 1, !tbaa !5
  store <16 x i8> %wide.load.3, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 96), align 16, !tbaa !5
  store <16 x i8> %wide.load6.3, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 112), align 16, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  %11 = getelementptr inbounds i8, ptr %0, i64 144
  %wide.load.4 = load <16 x i8>, ptr %10, align 1, !tbaa !5
  %wide.load6.4 = load <16 x i8>, ptr %11, align 1, !tbaa !5
  store <16 x i8> %wide.load.4, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 128), align 16, !tbaa !5
  store <16 x i8> %wide.load6.4, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 144), align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 160
  %13 = getelementptr inbounds i8, ptr %0, i64 176
  %wide.load.5 = load <16 x i8>, ptr %12, align 1, !tbaa !5
  %wide.load6.5 = load <16 x i8>, ptr %13, align 1, !tbaa !5
  store <16 x i8> %wide.load.5, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 160), align 16, !tbaa !5
  store <16 x i8> %wide.load6.5, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 176), align 16, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 192
  %15 = getelementptr inbounds i8, ptr %0, i64 208
  %wide.load.6 = load <16 x i8>, ptr %14, align 1, !tbaa !5
  %wide.load6.6 = load <16 x i8>, ptr %15, align 1, !tbaa !5
  store <16 x i8> %wide.load.6, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 192), align 16, !tbaa !5
  store <16 x i8> %wide.load6.6, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 208), align 16, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 224
  %17 = getelementptr inbounds i8, ptr %0, i64 240
  %wide.load.7 = load <16 x i8>, ptr %16, align 1, !tbaa !5
  %wide.load6.7 = load <16 x i8>, ptr %17, align 1, !tbaa !5
  store <16 x i8> %wide.load.7, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 224), align 16, !tbaa !5
  store <16 x i8> %wide.load6.7, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 240), align 16, !tbaa !5
  br label %middle.block

scalar.ph:                                        ; preds = %vector.memcheck, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ 0, %vector.memcheck ]
  %18 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = getelementptr inbounds [256 x i8], ptr @GLeeErrorString, i64 0, i64 %indvars.iv
  store i8 %19, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %21 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = getelementptr inbounds [256 x i8], ptr @GLeeErrorString, i64 0, i64 %indvars.iv.next
  store i8 %22, ptr %23, align 1, !tbaa !5
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %24 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.1
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = getelementptr inbounds [256 x i8], ptr @GLeeErrorString, i64 0, i64 %indvars.iv.next.1
  store i8 %25, ptr %26, align 2, !tbaa !5
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %27 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv.next.2
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = getelementptr inbounds [256 x i8], ptr @GLeeErrorString, i64 0, i64 %indvars.iv.next.2
  store i8 %28, ptr %29, align 1, !tbaa !5
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 256
  br i1 %exitcond.not.3, label %middle.block, label %scalar.ph, !llvm.loop !8

middle.block:                                     ; preds = %scalar.ph, %vector.body
  store i8 0, ptr getelementptr inbounds (i8, ptr @GLeeErrorString, i64 255), align 1, !tbaa !5
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(write, argmem: read, 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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9, !10}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass