; LLVM IR from ohler55/agoo :: ext/agoo (sdl)

; 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._agooDoc = type { ptr, ptr, ptr }
%struct._gqlDoc = type { ptr, ptr, ptr, ptr, %struct._gqlFuncs, ptr, ptr, ptr }
%struct._gqlFuncs = type { ptr, ptr }

@.str.4 = external hidden unnamed_addr constant [21 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

declare void @agoo_doc_init(ptr noundef, ptr noundef, i32 noundef) #1

declare void @agoo_doc_next_token(ptr noundef) #1

declare i32 @agoo_doc_err(ptr noundef, ptr noundef, 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 @sdl_parse_doc(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct._agooDoc, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store ptr null, ptr %13, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load i32, ptr %9, align 4, !tbaa !9
  call void @agoo_doc_init(ptr noundef %12, ptr noundef %15, i32 noundef %16)
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = call ptr @gql_doc_create(ptr noundef %17)
  store ptr %18, ptr %13, align 8, !tbaa !5
  %19 = icmp eq ptr null, %18
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

21:                                               ; preds = %5
  %22 = load ptr, ptr %10, align 8, !tbaa !5
  %23 = load ptr, ptr %13, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct._gqlDoc, ptr %23, i32 0, i32 1
  store ptr %22, ptr %24, align 8, !tbaa !11
  br label %25

25:                                               ; preds = %65, %21
  %26 = getelementptr inbounds %struct._agooDoc, ptr %12, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = getelementptr inbounds %struct._agooDoc, ptr %12, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !16
  %30 = icmp ult ptr %27, %29
  br i1 %30, label %31, label %66

31:                                               ; preds = %25
  call void @agoo_doc_next_token(ptr noundef %12)
  %32 = getelementptr inbounds %struct._agooDoc, ptr %12, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !16
  %34 = getelementptr inbounds %struct._agooDoc, ptr %12, i32 0, i32 1
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = icmp ule ptr %33, %35
  br i1 %36, label %37, label %38

37:                                               ; preds = %31
  br label %66

38:                                               ; preds = %31
  %39 = getelementptr inbounds %struct._agooDoc, ptr %12, i32 0, i32 1
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  %41 = load i8, ptr %40, align 1, !tbaa !17
  %42 = sext i8 %41 to i32
  switch i32 %42, label %61 [
    i32 123, label %43
    i32 113, label %43
    i32 109, label %43
    i32 115, label %43
    i32 102, label %52
    i32 0, label %60
  ]

43:                                               ; preds = %38, %38, %38, %38
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = load i32, ptr %11, align 4, !tbaa !9
  %47 = call i32 @make_op(ptr noundef %44, ptr noundef %12, ptr noundef %45, i32 noundef %46)
  %48 = icmp ne i32 0, %47
  br i1 %48, label %49, label %51

49:                                               ; preds = %43
  %50 = load ptr, ptr %13, align 8, !tbaa !5
  call void @gql_doc_destroy(ptr noundef %50)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

51:                                               ; preds = %43
  br label %65

52:                                               ; preds = %38
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = call i32 @make_fragment(ptr noundef %53, ptr noundef %12, ptr noundef %54)
  %56 = icmp ne i32 0, %55
  br i1 %56, label %57, label %59

57:                                               ; preds = %52
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  call void @gql_doc_destroy(ptr noundef %58)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

59:                                               ; preds = %52
  br label %65

60:                                               ; preds = %38
  br label %67

61:                                               ; preds = %38
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = call i32 (ptr, ptr, ptr, ...) @agoo_doc_err(ptr noundef %12, ptr noundef %62, ptr noundef @.str.4)
  %64 = load ptr, ptr %13, align 8, !tbaa !5
  call void @gql_doc_destroy(ptr noundef %64)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

65:                                               ; preds = %59, %51
  br label %25, !llvm.loop !18

66:                                               ; preds = %37, %25
  br label %67

67:                                               ; preds = %66, %60
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = call i32 @validate_doc(ptr noundef %68, ptr noundef %69)
  %71 = icmp ne i32 0, %70
  br i1 %71, label %72, label %74

72:                                               ; preds = %67
  %73 = load ptr, ptr %13, align 8, !tbaa !5
  call void @gql_doc_destroy(ptr noundef %73)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

74:                                               ; preds = %67
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %75, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %76

76:                                               ; preds = %74, %72, %61, %57, %49, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #3
  %77 = load ptr, ptr %6, align 8
  ret ptr %77
}

declare ptr @gql_doc_create(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @make_op(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

declare void @gql_doc_destroy(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare hidden i32 @make_fragment(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @validate_doc(ptr noundef, ptr noundef) #2

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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_gqlDoc", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!"_gqlFuncs", !6, i64 0, !6, i64 8}
!14 = !{!15, !6, i64 8}
!15 = !{!"_agooDoc", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!15, !6, i64 16}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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"

%struct._agooDoc = type { ptr, ptr, ptr }

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

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

declare void @agoo_doc_init(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @agoo_doc_next_token(ptr noundef) local_unnamed_addr #1

declare i32 @agoo_doc_err(ptr noundef, ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress 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 @sdl_parse_doc(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct._agooDoc, align 8
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #3
  call void @agoo_doc_init(ptr noundef nonnull %6, ptr noundef %1, i32 noundef %2) #3
  %7 = call ptr @gql_doc_create(ptr noundef %0) #3
  %8 = icmp eq ptr %7, null
  br i1 %8, label %31, label %9

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %7, i64 8
  store ptr %3, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %6, i64 8
  %12 = getelementptr inbounds i8, ptr %6, i64 16
  %13 = load ptr, ptr %11, align 8, !tbaa !11
  %14 = load ptr, ptr %12, align 8, !tbaa !13
  %15 = icmp ult ptr %13, %14
  br i1 %15, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %9, %26
  call void @agoo_doc_next_token(ptr noundef nonnull %6) #3
  %16 = load ptr, ptr %12, align 8, !tbaa !13
  %17 = load ptr, ptr %11, align 8, !tbaa !11
  %.not = icmp ugt ptr %16, %17
  br i1 %.not, label %18, label %._crit_edge

18:                                               ; preds = %.lr.ph
  %19 = load i8, ptr %17, align 1, !tbaa !14
  switch i8 %19, label %24 [
    i8 123, label %20
    i8 113, label %20
    i8 109, label %20
    i8 115, label %20
    i8 102, label %22
    i8 0, label %._crit_edge
  ]

20:                                               ; preds = %18, %18, %18, %18
  %21 = call i32 @make_op(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %7, i32 noundef %4)
  %.not21 = icmp eq i32 %21, 0
  br i1 %.not21, label %26, label %.sink.split

22:                                               ; preds = %18
  %23 = call i32 @make_fragment(ptr noundef %0, ptr noundef nonnull %6, ptr noundef nonnull %7)
  %.not20 = icmp eq i32 %23, 0
  br i1 %.not20, label %26, label %.sink.split

24:                                               ; preds = %18
  %25 = call i32 (ptr, ptr, ptr, ...) @agoo_doc_err(ptr noundef nonnull %6, ptr noundef %0, ptr noundef nonnull @.str.4) #3
  br label %.sink.split

26:                                               ; preds = %22, %20
  %27 = load ptr, ptr %11, align 8, !tbaa !11
  %28 = load ptr, ptr %12, align 8, !tbaa !13
  %29 = icmp ult ptr %27, %28
  br i1 %29, label %.lr.ph, label %._crit_edge, !llvm.loop !15

._crit_edge:                                      ; preds = %18, %.lr.ph, %26, %9
  %30 = call i32 @validate_doc(ptr noundef %0, ptr noundef nonnull %7)
  %.not22 = icmp eq i32 %30, 0
  br i1 %.not22, label %31, label %.sink.split

.sink.split:                                      ; preds = %22, %20, %._crit_edge, %24
  call void @gql_doc_destroy(ptr noundef nonnull %7) #3
  br label %31

31:                                               ; preds = %.sink.split, %._crit_edge, %5
  %.0 = phi ptr [ null, %5 ], [ %7, %._crit_edge ], [ null, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #3
  ret ptr %.0
}

declare ptr @gql_doc_create(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @make_op(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @gql_doc_destroy(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @make_fragment(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @validate_doc(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !7, i64 8}
!6 = !{!"_gqlDoc", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 48, !7, i64 56, !7, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"_gqlFuncs", !7, i64 0, !7, i64 8}
!11 = !{!12, !7, i64 8}
!12 = !{!"_agooDoc", !7, i64 0, !7, i64 8, !7, i64 16}
!13 = !{!12, !7, i64 16}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass