; LLVM IR from rolinh/dfc :: src (util)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @strtrim(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

9:                                                ; preds = %1
  br label %10

10:                                               ; preds = %22, %9
  %11 = call ptr @__ctype_b_loc() #5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = sext i8 %14 to i32
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds i16, ptr %12, i64 %16
  %18 = load i16, ptr %17, align 2, !tbaa !10
  %19 = zext i16 %18 to i32
  %20 = and i32 %19, 8192
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %10
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i32 1
  store ptr %24, ptr %3, align 8, !tbaa !5
  br label %10, !llvm.loop !12

25:                                               ; preds = %10
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %25
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %31, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

32:                                               ; preds = %25
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = call i64 @strlen(ptr noundef %34) #6
  %36 = getelementptr inbounds i8, ptr %33, i64 %35
  %37 = getelementptr inbounds i8, ptr %36, i64 -1
  store ptr %37, ptr %4, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %56, %32
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = icmp ugt ptr %39, %40
  br i1 %41, label %42, label %54

42:                                               ; preds = %38
  %43 = call ptr @__ctype_b_loc() #5
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i8, ptr %45, align 1, !tbaa !9
  %47 = sext i8 %46 to i32
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i16, ptr %44, i64 %48
  %50 = load i16, ptr %49, align 2, !tbaa !10
  %51 = zext i16 %50 to i32
  %52 = and i32 %51, 8192
  %53 = icmp ne i32 %52, 0
  br label %54

54:                                               ; preds = %42, %38
  %55 = phi i1 [ false, %38 ], [ %53, %42 ]
  br i1 %55, label %56, label %59

56:                                               ; preds = %54
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = getelementptr inbounds i8, ptr %57, i32 -1
  store ptr %58, ptr %4, align 8, !tbaa !5
  br label %38, !llvm.loop !14

59:                                               ; preds = %54
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 1
  store i8 0, ptr %61, align 1, !tbaa !9
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %62, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %63

63:                                               ; preds = %59, %30, %8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %64 = load ptr, ptr %2, align 8
  ret ptr %64
}

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #2

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

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind willreturn memory(none) "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 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }
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/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


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

; Function Attrs: nofree nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local noundef ptr @strtrim(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %24, label %.preheader

.preheader:                                       ; preds = %1
  %2 = tail call ptr @__ctype_b_loc() #3
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %4, %.preheader
  %.014 = phi ptr [ %10, %4 ], [ %0, %.preheader ]
  %5 = load i8, ptr %.014, align 1, !tbaa !9
  %6 = sext i8 %5 to i64
  %7 = getelementptr inbounds i16, ptr %3, i64 %6
  %8 = load i16, ptr %7, align 2, !tbaa !10
  %9 = and i16 %8, 8192
  %.not17 = icmp eq i16 %9, 0
  %10 = getelementptr inbounds i8, ptr %.014, i64 1
  br i1 %.not17, label %11, label %4, !llvm.loop !12

11:                                               ; preds = %4
  %12 = icmp eq i8 %5, 0
  br i1 %12, label %24, label %13

13:                                               ; preds = %11
  %14 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.014) #4
  %15 = getelementptr inbounds i8, ptr %.014, i64 %14
  br label %16

16:                                               ; preds = %18, %13
  %.pn = phi ptr [ %15, %13 ], [ %.0, %18 ]
  %.0 = getelementptr inbounds i8, ptr %.pn, i64 -1
  %17 = icmp ugt ptr %.0, %.014
  br i1 %17, label %18, label %.critedge

18:                                               ; preds = %16
  %19 = load i8, ptr %.0, align 1, !tbaa !9
  %20 = sext i8 %19 to i64
  %21 = getelementptr inbounds i16, ptr %3, i64 %20
  %22 = load i16, ptr %21, align 2, !tbaa !10
  %23 = and i16 %22, 8192
  %.not18 = icmp eq i16 %23, 0
  br i1 %.not18, label %.critedge, label %16, !llvm.loop !14

.critedge:                                        ; preds = %16, %18
  store i8 0, ptr %.pn, align 1, !tbaa !9
  br label %24

24:                                               ; preds = %11, %1, %.critedge
  %.015 = phi ptr [ %.014, %.critedge ], [ null, %1 ], [ %.014, %11 ]
  ret ptr %.015
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() 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 = { nofree nounwind 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 nosync nounwind willreturn memory(none) "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 willreturn memory(none) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass