; LLVM IR from clibs/clib :: deps/gumbo-get-element-by-id (get-element-by-id)

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

%struct.GumboInternalNode = type { i32, ptr, i64, i32, %union.anon }
%union.anon = type { %struct.GumboElement }
%struct.GumboElement = type { %struct.GumboVector, i32, i32, %struct.GumboStringPiece, %struct.GumboStringPiece, %struct.GumboSourcePosition, %struct.GumboSourcePosition, %struct.GumboVector }
%struct.GumboStringPiece = type { ptr, i64 }
%struct.GumboSourcePosition = type { i32, i32, i32 }
%struct.GumboVector = type { ptr, i32, i32 }
%struct.GumboAttribute = type { i32, ptr, %struct.GumboStringPiece, ptr, %struct.GumboStringPiece, %struct.GumboSourcePosition, %struct.GumboSourcePosition, %struct.GumboSourcePosition, %struct.GumboSourcePosition }

@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @gumbo_get_element_by_id(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.GumboInternalNode, ptr %11, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp ne i32 0, %13
  br i1 %14, label %15, label %21

15:                                               ; preds = %2
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.GumboInternalNode, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !9
  %19 = icmp ne i32 1, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store ptr null, ptr %3, align 8
  br label %74

21:                                               ; preds = %15, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.GumboInternalNode, ptr %22, i32 0, i32 4
  %24 = getelementptr inbounds %struct.GumboElement, ptr %23, i32 0, i32 7
  %25 = call ptr @gumbo_get_attribute(ptr noundef %24, ptr noundef @.str)
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %37

28:                                               ; preds = %21
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.GumboAttribute, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !13
  %33 = call i32 @strcmp(ptr noundef %29, ptr noundef %32) #5
  %34 = icmp eq i32 0, %33
  br i1 %34, label %35, label %37

35:                                               ; preds = %28
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %36, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %73

37:                                               ; preds = %28, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.GumboInternalNode, ptr %38, i32 0, i32 4
  %40 = getelementptr inbounds %struct.GumboElement, ptr %39, i32 0, i32 0
  store ptr %40, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %66, %37
  %42 = load i32, ptr %9, align 4, !tbaa !17
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.GumboVector, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !18
  %46 = icmp ult i32 %42, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %41
  store i32 2, ptr %7, align 4
  br label %69

48:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.GumboVector, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !20
  %53 = load i32, ptr %9, align 4, !tbaa !17
  %54 = zext i32 %53 to i64
  %55 = getelementptr inbounds ptr, ptr %52, i64 %54
  %56 = load ptr, ptr %55, align 8, !tbaa !5
  %57 = call ptr @gumbo_get_element_by_id(ptr noundef %49, ptr noundef %56)
  store ptr %57, ptr %10, align 8, !tbaa !5
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = icmp ne ptr %58, null
  br i1 %59, label %60, label %62

60:                                               ; preds = %48
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %61, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %63

62:                                               ; preds = %48
  store i32 0, ptr %7, align 4
  br label %63

63:                                               ; preds = %62, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %64 = load i32, ptr %7, align 4
  switch i32 %64, label %69 [
    i32 0, label %65
  ]

65:                                               ; preds = %63
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %9, align 4, !tbaa !17
  %68 = add i32 %67, 1
  store i32 %68, ptr %9, align 4, !tbaa !17
  br label %41, !llvm.loop !21

69:                                               ; preds = %63, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  %70 = load i32, ptr %7, align 4
  switch i32 %70, label %72 [
    i32 2, label %71
  ]

71:                                               ; preds = %69
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %72

72:                                               ; preds = %71, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %73

73:                                               ; preds = %72, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %74

74:                                               ; preds = %73, %20
  %75 = load ptr, ptr %3, align 8
  ret ptr %75
}

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

declare ptr @gumbo_get_attribute(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, 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 = { "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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"GumboInternalNode", !11, i64 0, !6, i64 8, !12, i64 16, !11, i64 24, !7, i64 32}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 32}
!14 = !{!"", !11, i64 0, !6, i64 8, !15, i64 16, !6, i64 32, !15, i64 40, !16, i64 56, !16, i64 68, !16, i64 80, !16, i64 92}
!15 = !{!"", !6, i64 0, !12, i64 8}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8}
!17 = !{!11, !11, i64 0}
!18 = !{!19, !11, i64 8}
!19 = !{!"", !6, i64 0, !11, i64 8, !11, i64 12}
!20 = !{!19, !6, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @gumbo_get_element_by_id(ptr nocapture noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = load i32, ptr %1, align 8, !tbaa !5
  %switch = icmp ult i32 %3, 2
  br i1 %switch, label %4, label %.loopexit

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %1, i64 32
  %6 = getelementptr inbounds i8, ptr %1, i64 112
  %7 = tail call ptr @gumbo_get_attribute(ptr noundef nonnull %6, ptr noundef nonnull @.str) #3
  %.not26 = icmp eq ptr %7, null
  br i1 %.not26, label %13, label %8

8:                                                ; preds = %4
  %9 = getelementptr inbounds i8, ptr %7, i64 32
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %10) #4
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %.loopexit, label %13

13:                                               ; preds = %8, %4
  %14 = getelementptr inbounds i8, ptr %1, i64 40
  %15 = load i32, ptr %14, align 8, !tbaa !16
  %.not2829.not = icmp eq i32 %15, 0
  br i1 %.not2829.not, label %.loopexit, label %.lr.ph

16:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr %14, align 8, !tbaa !16
  %18 = zext i32 %17 to i64
  %.not28 = icmp ult i64 %indvars.iv.next, %18
  br i1 %.not28, label %.lr.ph, label %.loopexit, !llvm.loop !18

.lr.ph:                                           ; preds = %13, %16
  %indvars.iv = phi i64 [ %indvars.iv.next, %16 ], [ 0, %13 ]
  %19 = load ptr, ptr %5, align 8, !tbaa !20
  %20 = getelementptr inbounds ptr, ptr %19, i64 %indvars.iv
  %21 = load ptr, ptr %20, align 8, !tbaa !21
  %22 = tail call ptr @gumbo_get_element_by_id(ptr noundef %0, ptr noundef %21)
  %.not27 = icmp eq ptr %22, null
  br i1 %.not27, label %16, label %.loopexit

.loopexit:                                        ; preds = %16, %.lr.ph, %13, %2, %8
  %.5 = phi ptr [ null, %2 ], [ %1, %8 ], [ null, %13 ], [ null, %16 ], [ %22, %.lr.ph ]
  ret ptr %.5
}

declare ptr @gumbo_get_attribute(ptr noundef, ptr noundef) local_unnamed_addr #1

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

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 = { "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 }
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, !7, i64 0}
!6 = !{!"GumboInternalNode", !7, i64 0, !10, i64 8, !11, i64 16, !7, i64 24, !8, i64 32}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!13, !10, i64 32}
!13 = !{!"", !7, i64 0, !10, i64 8, !14, i64 16, !10, i64 32, !14, i64 40, !15, i64 56, !15, i64 68, !15, i64 80, !15, i64 92}
!14 = !{!"", !10, i64 0, !11, i64 8}
!15 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!16 = !{!17, !7, i64 8}
!17 = !{!"", !10, i64 0, !7, i64 8, !7, i64 12}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!17, !10, i64 0}
!21 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass