; LLVM IR from Dimandragon/non-parametric-dsp :: alglib-cpp/src/ap.ll (ZN11alglib_impl19ae_is_trace_enabledEPKc)

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

@_ZN11alglib_impl17alglib_trace_fileE = external dso_local global ptr, align 8
@_ZN11alglib_implL17alglib_trace_typeE = external hidden global i64, align 8
@_ZN11alglib_implL17alglib_trace_tagsE = external hidden global [2051 x i8], align 16
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [2 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind
declare ptr @strncat(ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN11alglib_impl19ae_is_trace_enabledEPKc(ptr noundef %0) #4 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca [2051 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2051, ptr %4) #5
  %7 = load i64, ptr @_ZN11alglib_implL17alglib_trace_typeE, align 8, !tbaa !9
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %12, label %9

9:                                                ; preds = %1
  %10 = load ptr, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %9, %1
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %63

13:                                               ; preds = %9
  %14 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %14, i8 0, i64 2051, i1 false)
  %15 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %16 = call ptr @strcat(ptr noundef %15, ptr noundef @.str.34) #5
  %17 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call ptr @strncat(ptr noundef %17, ptr noundef %18, i64 noundef 2048) #5
  %20 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %21 = call ptr @strcat(ptr noundef %20, ptr noundef @.str.36) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %41, %13
  %23 = load i32, ptr %6, align 4, !tbaa !11
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !13
  %27 = sext i8 %26 to i32
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %22
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %44

30:                                               ; preds = %22
  %31 = load i32, ptr %6, align 4, !tbaa !11
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = sext i8 %34 to i32
  %36 = call i32 @tolower(i32 noundef %35) #6
  %37 = trunc i32 %36 to i8
  %38 = load i32, ptr %6, align 4, !tbaa !11
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 %39
  store i8 %37, ptr %40, align 1, !tbaa !13
  br label %41

41:                                               ; preds = %30
  %42 = load i32, ptr %6, align 4, !tbaa !11
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %6, align 4, !tbaa !11
  br label %22, !llvm.loop !14

44:                                               ; preds = %29
  %45 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %46 = call i64 @strlen(ptr noundef %45) #6
  %47 = sub i64 %46, 1
  %48 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 %47
  store i8 44, ptr %48, align 1, !tbaa !13
  %49 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %50 = call noundef ptr @strstr(ptr noundef @_ZN11alglib_implL17alglib_trace_tagsE, ptr noundef %49) #6
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %53

52:                                               ; preds = %44
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %63

53:                                               ; preds = %44
  %54 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %55 = call i64 @strlen(ptr noundef %54) #6
  %56 = sub i64 %55, 1
  %57 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 %56
  store i8 46, ptr %57, align 1, !tbaa !13
  %58 = getelementptr inbounds [2051 x i8], ptr %4, i64 0, i64 0
  %59 = call noundef ptr @strstr(ptr noundef @_ZN11alglib_implL17alglib_trace_tagsE, ptr noundef %58) #6
  %60 = icmp ne ptr %59, null
  br i1 %60, label %61, label %62

61:                                               ; preds = %53
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %63

62:                                               ; preds = %53
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %63

63:                                               ; preds = %62, %61, %52, %12
  call void @llvm.lifetime.end.p0(i64 2051, ptr %4) #5
  %64 = load i1, ptr %2, align 1
  ret i1 %64
}

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

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @strstr(ptr noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

@_ZN11alglib_impl17alglib_trace_fileE = external dso_local local_unnamed_addr global ptr, align 8
@_ZN11alglib_implL17alglib_trace_typeE = external hidden local_unnamed_addr global i64, align 8
@_ZN11alglib_implL17alglib_trace_tagsE = external hidden global [2051 x i8], align 16
@.str.34 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.36 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @tolower(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind memory(read, argmem: readwrite) uwtable
define dso_local noundef zeroext i1 @_ZN11alglib_impl19ae_is_trace_enabledEPKc(ptr nocapture noundef readonly %0) local_unnamed_addr #4 {
  %2 = alloca [2051 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 2051, ptr nonnull %2) #6
  %3 = load i64, ptr @_ZN11alglib_implL17alglib_trace_typeE, align 8, !tbaa !5
  %4 = icmp eq i64 %3, 0
  %5 = load ptr, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8
  %6 = icmp eq ptr %5, null
  %or.cond = select i1 %4, i1 true, i1 %6
  br i1 %or.cond, label %28, label %7

7:                                                ; preds = %1
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(2051) %2, i8 0, i64 2051, i1 false)
  %8 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.34) #6
  %9 = call ptr @strncat(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 2048) #6
  %10 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str.36) #6
  %11 = load i8, ptr %2, align 16, !tbaa !9
  %.not10 = icmp eq i8 %11, 0
  br i1 %.not10, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %7
  %12 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #7
  %13 = add i64 %12, -1
  %14 = getelementptr inbounds [2051 x i8], ptr %2, i64 0, i64 %13
  store i8 44, ptr %14, align 1, !tbaa !9
  %15 = call noundef ptr @strstr(ptr noundef nonnull dereferenceable(1) @_ZN11alglib_implL17alglib_trace_tagsE, ptr noundef nonnull dereferenceable(1) %2) #7
  %.not8 = icmp eq ptr %15, null
  br i1 %.not8, label %23, label %28

.lr.ph:                                           ; preds = %7, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %7 ]
  %16 = phi i8 [ %22, %.lr.ph ], [ %11, %7 ]
  %17 = phi ptr [ %21, %.lr.ph ], [ %2, %7 ]
  %18 = sext i8 %16 to i32
  %19 = call i32 @tolower(i32 noundef %18) #7
  %20 = trunc i32 %19 to i8
  store i8 %20, ptr %17, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %21 = getelementptr inbounds [2051 x i8], ptr %2, i64 0, i64 %indvars.iv.next
  %22 = load i8, ptr %21, align 1, !tbaa !9
  %.not = icmp eq i8 %22, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

23:                                               ; preds = %._crit_edge
  %24 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #7
  %25 = add i64 %24, -1
  %26 = getelementptr inbounds [2051 x i8], ptr %2, i64 0, i64 %25
  store i8 46, ptr %26, align 1, !tbaa !9
  %27 = call noundef ptr @strstr(ptr noundef nonnull dereferenceable(1) @_ZN11alglib_implL17alglib_trace_tagsE, ptr noundef nonnull dereferenceable(1) %2) #7
  %.not9 = icmp ne ptr %27, null
  br label %28

28:                                               ; preds = %23, %._crit_edge, %1
  %.06 = phi i1 [ false, %1 ], [ true, %._crit_edge ], [ %.not9, %23 ]
  call void @llvm.lifetime.end.p0(i64 2051, ptr nonnull %2) #6
  ret i1 %.06
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare noundef ptr @strstr(ptr noundef, ptr nocapture noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { mustprogress nofree 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 #4 = { mustprogress nofree nounwind memory(read, argmem: readwrite) 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 #5 = { 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


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