; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (OffsetWidthValidate)

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

@.str.25 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.27 = external hidden unnamed_addr constant [8 x i32], align 4

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

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) #1

declare i64 @StrLen(ptr noundef) #1

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

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

8:                                                ; preds = %65, %1
  br label %9

9:                                                ; preds = %8
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %10, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call i64 @StrLen(ptr noundef @.str.25)
  %13 = call i64 @StrnCmp(ptr noundef %11, ptr noundef @.str.25, i64 noundef %12)
  %14 = icmp ne i64 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %9
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %16, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %66

17:                                               ; preds = %9
  br label %18

18:                                               ; preds = %30, %17
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i16, ptr %19, align 2, !tbaa !9
  %21 = zext i16 %20 to i32
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = call i64 @StrLen(ptr noundef @.str.27)
  %26 = call i64 @StrnCmp(ptr noundef %24, ptr noundef @.str.27, i64 noundef %25)
  %27 = icmp ne i64 %26, 0
  br label %28

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

30:                                               ; preds = %28
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds i16, ptr %31, i32 1
  store ptr %32, ptr %4, align 8, !tbaa !5
  br label %18, !llvm.loop !11

33:                                               ; preds = %28
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = load i16, ptr %34, align 2, !tbaa !9
  %36 = zext i16 %35 to i32
  %37 = icmp eq i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %33
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %39, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %66

40:                                               ; preds = %33
  %41 = call i64 @StrLen(ptr noundef @.str.27)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds i16, ptr %42, i64 %41
  store ptr %43, ptr %4, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %56, %40
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = load i16, ptr %45, align 2, !tbaa !9
  %47 = zext i16 %46 to i32
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %44
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = call i64 @StrLen(ptr noundef @.str.25)
  %52 = call i64 @StrnCmp(ptr noundef %50, ptr noundef @.str.25, i64 noundef %51)
  %53 = icmp ne i64 %52, 0
  br label %54

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

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

59:                                               ; preds = %54
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = load i16, ptr %60, align 2, !tbaa !9
  %62 = zext i16 %61 to i32
  %63 = icmp eq i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  store ptr null, ptr %2, align 8
  store i32 1, ptr %6, align 4
  br label %66

65:                                               ; preds = %59
  br label %8

66:                                               ; preds = %64, %38, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %67 = load ptr, ptr %2, align 8
  ret ptr %67
}

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

!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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@.str.25 = external hidden unnamed_addr constant [9 x i32], align 4
@.str.27 = external hidden unnamed_addr constant [8 x i32], align 4

declare i64 @StrnCmp(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

declare i64 @StrLen(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @OffsetWidthValidate(ptr noundef %0) local_unnamed_addr #1 {
  br label %2

2:                                                ; preds = %.critedge2, %1
  %.017 = phi ptr [ %0, %1 ], [ %.233, %.critedge2 ]
  %3 = tail call i64 @StrLen(ptr noundef nonnull @.str.25) #2
  %4 = tail call i64 @StrnCmp(ptr noundef %.017, ptr noundef nonnull @.str.25, i64 noundef %3) #2
  %.not = icmp eq i64 %4, 0
  br i1 %.not, label %.preheader, label %.critedge.thread

.preheader:                                       ; preds = %2
  %5 = load i16, ptr %.017, align 2, !tbaa !5
  %.not1829 = icmp eq i16 %5, 0
  br i1 %.not1829, label %.critedge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %8
  %.130 = phi ptr [ %9, %8 ], [ %.017, %.preheader ]
  %6 = tail call i64 @StrLen(ptr noundef nonnull @.str.27) #2
  %7 = tail call i64 @StrnCmp(ptr noundef nonnull %.130, ptr noundef nonnull @.str.27, i64 noundef %6) #2
  %.not19 = icmp eq i64 %7, 0
  br i1 %.not19, label %.critedge, label %8

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.130, i64 2
  %10 = load i16, ptr %9, align 2, !tbaa !5
  %.not18 = icmp eq i16 %10, 0
  br i1 %.not18, label %.critedge.thread, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph
  %.pr = load i16, ptr %.130, align 2, !tbaa !5
  %11 = icmp eq i16 %.pr, 0
  br i1 %11, label %.critedge.thread, label %12

12:                                               ; preds = %.critedge
  %13 = tail call i64 @StrLen(ptr noundef nonnull @.str.27) #2
  %14 = getelementptr inbounds i16, ptr %.130, i64 %13
  %15 = load i16, ptr %14, align 2, !tbaa !5
  %.not2032 = icmp eq i16 %15, 0
  br i1 %.not2032, label %.critedge.thread, label %.lr.ph34

.lr.ph34:                                         ; preds = %12, %18
  %.233 = phi ptr [ %19, %18 ], [ %14, %12 ]
  %16 = tail call i64 @StrLen(ptr noundef nonnull @.str.25) #2
  %17 = tail call i64 @StrnCmp(ptr noundef nonnull %.233, ptr noundef nonnull @.str.25, i64 noundef %16) #2
  %.not21 = icmp eq i64 %17, 0
  br i1 %.not21, label %.critedge2, label %18

18:                                               ; preds = %.lr.ph34
  %19 = getelementptr inbounds i8, ptr %.233, i64 2
  %20 = load i16, ptr %19, align 2, !tbaa !5
  %.not20 = icmp eq i16 %20, 0
  br i1 %.not20, label %.critedge.thread, label %.lr.ph34, !llvm.loop !11

.critedge2:                                       ; preds = %.lr.ph34
  %.pr22 = load i16, ptr %.233, align 2, !tbaa !5
  %21 = icmp eq i16 %.pr22, 0
  br i1 %21, label %.critedge.thread, label %2

.critedge.thread:                                 ; preds = %.critedge2, %.critedge, %2, %.preheader, %12, %8, %18
  %.0 = phi ptr [ null, %18 ], [ %.017, %8 ], [ null, %12 ], [ %.017, %.preheader ], [ null, %.critedge2 ], [ %.017, %.critedge ], [ %.017, %2 ]
  ret ptr %.0
}

attributes #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 = { 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 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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