; LLVM IR from kajott/GIPS :: src/string_util.ll (ZN10StringUtil14extractExtCodeEPKc)

; 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: 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: mustprogress uwtable
define dso_local noundef i32 @_ZN10StringUtil14extractExtCodeEPKc(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %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 i32 0, ptr %2, align 4
  br label %46

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call noundef ptr @_ZN10StringUtil7pathExtEPKc(ptr noundef %10)
  store ptr %11, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = load i8, ptr %12, align 1, !tbaa !9
  %14 = sext i8 %13 to i32
  %15 = icmp eq i32 %14, 46
  br i1 %15, label %16, label %19

16:                                               ; preds = %9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i32 1
  store ptr %18, ptr %3, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %16, %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %20

20:                                               ; preds = %39, %19
  %21 = load i32, ptr %5, align 4, !tbaa !10
  %22 = icmp slt i32 %21, 32
  br i1 %22, label %23, label %27

23:                                               ; preds = %20
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = load i8, ptr %24, align 1, !tbaa !9
  %26 = icmp ne i8 %25, 0
  br label %27

27:                                               ; preds = %23, %20
  %28 = phi i1 [ false, %20 ], [ %26, %23 ]
  br i1 %28, label %30, label %29

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

30:                                               ; preds = %27
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = call i32 @tolower(i32 noundef %33) #5
  %35 = load i32, ptr %5, align 4, !tbaa !10
  %36 = shl i32 %34, %35
  %37 = load i32, ptr %4, align 4, !tbaa !10
  %38 = or i32 %37, %36
  store i32 %38, ptr %4, align 4, !tbaa !10
  br label %39

39:                                               ; preds = %30
  %40 = load ptr, ptr %3, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i32 1
  store ptr %41, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %5, align 4, !tbaa !10
  %43 = add nsw i32 %42, 8
  store i32 %43, ptr %5, align 4, !tbaa !10
  br label %20, !llvm.loop !12

44:                                               ; preds = %29
  %45 = load i32, ptr %4, align 4, !tbaa !10
  store i32 %45, ptr %2, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %46

46:                                               ; preds = %44, %8
  %47 = load i32, ptr %2, align 4
  ret i32 %47
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN10StringUtil7pathExtEPKc(ptr noundef) #2

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN10StringUtil14extractExtCodeEPKc(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.critedge, label %2

2:                                                ; preds = %1
  %3 = tail call noundef ptr @_ZN10StringUtil7pathExtEPKc(ptr noundef nonnull %0)
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = icmp eq i8 %4, 46
  %spec.select.idx = zext i1 %5 to i64
  %spec.select = getelementptr inbounds i8, ptr %3, i64 %spec.select.idx
  %6 = load i8, ptr %spec.select, align 1, !tbaa !5
  %.not17 = icmp eq i8 %6, 0
  br i1 %.not17, label %.critedge, label %7

7:                                                ; preds = %2
  %8 = sext i8 %6 to i32
  %9 = tail call i32 @tolower(i32 noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %spec.select, i64 1
  %11 = load i8, ptr %10, align 1, !tbaa !5
  %.not17.1 = icmp eq i8 %11, 0
  br i1 %.not17.1, label %.critedge, label %12

12:                                               ; preds = %7
  %13 = sext i8 %11 to i32
  %14 = tail call i32 @tolower(i32 noundef %13) #3
  %15 = shl i32 %14, 8
  %16 = or i32 %15, %9
  %17 = getelementptr inbounds i8, ptr %spec.select, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !5
  %.not17.2 = icmp eq i8 %18, 0
  br i1 %.not17.2, label %.critedge, label %19

19:                                               ; preds = %12
  %20 = sext i8 %18 to i32
  %21 = tail call i32 @tolower(i32 noundef %20) #3
  %22 = shl i32 %21, 16
  %23 = or i32 %22, %16
  %24 = getelementptr inbounds i8, ptr %spec.select, i64 3
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %.not17.3 = icmp eq i8 %25, 0
  br i1 %.not17.3, label %.critedge, label %26

26:                                               ; preds = %19
  %27 = sext i8 %25 to i32
  %28 = tail call i32 @tolower(i32 noundef %27) #3
  %29 = shl i32 %28, 24
  %30 = or i32 %29, %23
  br label %.critedge

.critedge:                                        ; preds = %2, %7, %12, %19, %26, %1
  %.014 = phi i32 [ 0, %1 ], [ 0, %2 ], [ %9, %7 ], [ %16, %12 ], [ %23, %19 ], [ %30, %26 ]
  ret i32 %.014
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZN10StringUtil7pathExtEPKc(ptr noundef) local_unnamed_addr #1

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

attributes #0 = { 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 #1 = { inlinehint 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 #2 = { 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 #3 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass