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

; 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
@stdout = external global ptr, align 8

; 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

declare i32 @fclose(ptr noundef) #2

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN11alglib_impl15ae_trace_stdoutEPKc(ptr noundef %0) #5 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load i8, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !9, !range !11, !noundef !12
  %5 = trunc i8 %4 to i1
  br i1 %5, label %6, label %13

6:                                                ; preds = %1
  %7 = load ptr, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %12

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

12:                                               ; preds = %9, %6
  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 %13

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

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

25:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %40

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

37:                                               ; preds = %26
  %38 = load i32, ptr %3, align 4, !tbaa !13
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !13
  br label %18, !llvm.loop !16

40:                                               ; preds = %25
  store i64 1, ptr @_ZN11alglib_implL17alglib_trace_typeE, align 8, !tbaa !18
  %41 = load ptr, ptr @stdout, align 8, !tbaa !5
  store ptr %41, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !5
  store i8 0, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !9
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 "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 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 = { 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 #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
@stdout = external local_unnamed_addr global ptr, align 8

; 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: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #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 uwtable
define dso_local void @_ZN11alglib_impl15ae_trace_stdoutEPKc(ptr nocapture noundef readonly %0) local_unnamed_addr #4 {
  %2 = load i8, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !5, !range !9, !noundef !10
  %3 = trunc nuw i8 %2 to i1
  br i1 %3, label %4, label %9

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

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

8:                                                ; preds = %6, %4
  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 %9

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

._crit_edge:                                      ; preds = %.lr.ph, %9
  store i64 1, ptr @_ZN11alglib_implL17alglib_trace_typeE, align 8, !tbaa !14
  %14 = load ptr, ptr @stdout, align 8, !tbaa !11
  store ptr %14, ptr @_ZN11alglib_impl17alglib_trace_fileE, align 8, !tbaa !11
  store i8 0, ptr @_ZN11alglib_implL19alglib_fclose_traceE, align 1, !tbaa !5
  ret void

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

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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" }
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 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 = !{!"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