; LLVM IR from zeux/meshoptimizer :: gltf/gltfpack.ll (Z11textureMaskPKc)

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

@stderr = external global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [42 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: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #2

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

6:                                                ; preds = %64, %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %66

9:                                                ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call noundef ptr @strchr(ptr noundef %10, i32 noundef 44) #5
  store ptr %11, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %21

14:                                               ; preds = %9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = ptrtoint ptr %15 to i64
  %18 = ptrtoint ptr %16 to i64
  %19 = sub i64 %17, %18
  %20 = sub nsw i64 %19, 1
  br label %24

21:                                               ; preds = %9
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = call i64 @strlen(ptr noundef %22) #5
  br label %24

24:                                               ; preds = %21, %14
  %25 = phi i64 [ %20, %14 ], [ %23, %21 ]
  store i64 %25, ptr %5, align 8, !tbaa !11
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load i64, ptr %5, align 8, !tbaa !11
  %28 = call i32 @strncmp(ptr noundef %26, ptr noundef @.str.16, i64 noundef %27) #5
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %33

30:                                               ; preds = %24
  %31 = load i32, ptr %3, align 4, !tbaa !9
  %32 = or i32 %31, 2
  store i32 %32, ptr %3, align 4, !tbaa !9
  br label %57

33:                                               ; preds = %24
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = load i64, ptr %5, align 8, !tbaa !11
  %36 = call i32 @strncmp(ptr noundef %34, ptr noundef @.str.17, i64 noundef %35) #5
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %41

38:                                               ; preds = %33
  %39 = load i32, ptr %3, align 4, !tbaa !9
  %40 = or i32 %39, 4
  store i32 %40, ptr %3, align 4, !tbaa !9
  br label %56

41:                                               ; preds = %33
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = load i64, ptr %5, align 8, !tbaa !11
  %44 = call i32 @strncmp(ptr noundef %42, ptr noundef @.str.18, i64 noundef %43) #5
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %46, label %49

46:                                               ; preds = %41
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = or i32 %47, 8
  store i32 %48, ptr %3, align 4, !tbaa !9
  br label %55

49:                                               ; preds = %41
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  %51 = load i64, ptr %5, align 8, !tbaa !11
  %52 = trunc i64 %51 to i32
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.19, i32 noundef %52, ptr noundef %53) #4
  br label %55

55:                                               ; preds = %49, %46
  br label %56

56:                                               ; preds = %55, %38
  br label %57

57:                                               ; preds = %56, %30
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %63

60:                                               ; preds = %57
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 1
  br label %64

63:                                               ; preds = %57
  br label %64

64:                                               ; preds = %63, %60
  %65 = phi ptr [ %62, %60 ], [ null, %63 ]
  store ptr %65, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %6, !llvm.loop !13

66:                                               ; preds = %6
  %67 = load i32, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 %67
}

; Function Attrs: nounwind willreturn memory(read)
declare noundef ptr @strchr(ptr noundef, i32 noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #3 = { 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 #4 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.16 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [42 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strncmp(ptr nocapture noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local noundef i32 @_Z11textureMaskPKc(ptr noundef %0) local_unnamed_addr #2 {
  %.not22 = icmp eq ptr %0, null
  br i1 %.not22, label %select.unfold._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %select.unfold
  %.024 = phi ptr [ %30, %select.unfold ], [ %0, %1 ]
  %.01923 = phi i32 [ %.1, %select.unfold ], [ 0, %1 ]
  %2 = tail call noundef ptr @strchr(ptr noundef nonnull dereferenceable(1) %.024, i32 noundef 44) #3
  %.not21 = icmp eq ptr %2, null
  br i1 %.not21, label %8, label %3

3:                                                ; preds = %.lr.ph
  %4 = ptrtoint ptr %2 to i64
  %5 = ptrtoint ptr %.024 to i64
  %6 = xor i64 %5, -1
  %7 = add i64 %4, %6
  br label %10

8:                                                ; preds = %.lr.ph
  %9 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %.024) #3
  br label %10

10:                                               ; preds = %8, %3
  %11 = phi i64 [ %7, %3 ], [ %9, %8 ]
  %12 = tail call i32 @strncmp(ptr noundef nonnull %.024, ptr noundef nonnull @.str.16, i64 noundef %11) #3
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %16

14:                                               ; preds = %10
  %15 = or i32 %.01923, 2
  br label %select.unfold

16:                                               ; preds = %10
  %17 = tail call i32 @strncmp(ptr noundef nonnull %.024, ptr noundef nonnull @.str.17, i64 noundef %11) #3
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = or i32 %.01923, 4
  br label %select.unfold

21:                                               ; preds = %16
  %22 = tail call i32 @strncmp(ptr noundef nonnull %.024, ptr noundef nonnull @.str.18, i64 noundef %11) #3
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %21
  %25 = or i32 %.01923, 8
  br label %select.unfold

26:                                               ; preds = %21
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = trunc i64 %11 to i32
  %29 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef nonnull @.str.19, i32 noundef %28, ptr noundef nonnull %.024) #4
  br label %select.unfold

select.unfold:                                    ; preds = %19, %26, %24, %14
  %.1 = phi i32 [ %15, %14 ], [ %20, %19 ], [ %25, %24 ], [ %.01923, %26 ]
  %30 = getelementptr inbounds i8, ptr %2, i64 1
  br i1 %.not21, label %select.unfold._crit_edge, label %.lr.ph

select.unfold._crit_edge:                         ; preds = %select.unfold, %1
  %.019.lcssa = phi i32 [ 0, %1 ], [ %.1, %select.unfold ]
  ret i32 %.019.lcssa
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare noundef ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { nounwind willreturn memory(read) }
attributes #4 = { cold 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++ TBAA"}


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