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

; 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_implL19alglib_fclose_traceE = external hidden global i8, align 1
@_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.35 = external hidden unnamed_addr constant [3 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: mustprogress uwtable
define dso_local void @_ZN11alglib_impl13ae_trace_fileEPKcS1_(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load i8, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !9, !range !11, !noundef !12
  %7 = trunc i8 %6 to i1
  br i1 %7, label %8, label %15

8:                                                ; preds = %2
  %9 = load ptr, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %14

11:                                               ; preds = %8
  %12 = load ptr, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  %13 = call i32 @fclose(ptr noundef %12)
  br label %14

14:                                               ; preds = %11, %8
  store ptr null, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  store i8 0, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !9
  br label %15

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

20:                                               ; preds = %39, %15
  %21 = load i32, ptr %5, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [2051 x i8], ptr @_ZN11alglib_implL17alglib_trace_tagsE, i64 0, i64 %22
  %24 = load i8, ptr %23, align 1, !tbaa !15
  %25 = sext i8 %24 to i32
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %42

28:                                               ; preds = %20
  %29 = load i32, ptr %5, align 4, !tbaa !13
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [2051 x i8], ptr @_ZN11alglib_implL17alglib_trace_tagsE, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !15
  %33 = sext i8 %32 to i32
  %34 = call i32 @tolower(i32 noundef %33) #7
  %35 = trunc i32 %34 to i8
  %36 = load i32, ptr %5, align 4, !tbaa !13
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [2051 x i8], ptr @_ZN11alglib_implL17alglib_trace_tagsE, i64 0, i64 %37
  store i8 %35, ptr %38, align 1, !tbaa !15
  br label %39

39:                                               ; preds = %28
  %40 = load i32, ptr %5, align 4, !tbaa !13
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %5, align 4, !tbaa !13
  br label %20, !llvm.loop !16

42:                                               ; preds = %27
  store i64 1, ptr @_ZN11alglib_implL17alglib_trace_typeE, align 8, !tbaa !18
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = call noalias ptr @fopen(ptr noundef %43, ptr noundef @.str.35)
  store ptr %44, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  store i8 1, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !9
  ret void
}

declare i32 @fclose(ptr noundef) #3

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

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

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

declare noalias ptr @fopen(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 = { mustprogress 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 #3 = { "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 = { 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 #5 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !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"

@_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_implL19alglib_fclose_traceE = external hidden local_unnamed_addr global i8, align 1
@_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.35 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_ZN11alglib_impl13ae_trace_fileEPKcS1_(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 {
  %3 = load i8, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !5, !range !9, !noundef !10
  %4 = trunc nuw i8 %3 to i1
  br i1 %4, label %5, label %10

5:                                                ; preds = %2
  %6 = load ptr, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !11
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %9, label %7

7:                                                ; preds = %5
  %8 = tail call i32 @fclose(ptr noundef nonnull %6)
  br label %9

9:                                                ; preds = %7, %5
  store ptr null, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !11
  store i8 0, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !5
  br label %10

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

._crit_edge:                                      ; preds = %.lr.ph, %10
  store i64 1, ptr @_ZN11alglib_implL17alglib_trace_typeE, align 8, !tbaa !14
  %15 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.35)
  store ptr %15, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !11
  store i8 1, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !5
  ret void

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

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

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

; 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 #3

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress 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 #2 = { 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" }
attributes #3 = { 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 #4 = { 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 #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 = !{!"bool", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{i8 0, i8 2}
!10 = !{}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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