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

; 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._gqlType = type { ptr, ptr, ptr, i32, i32, i8, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr, ptr }
%struct._gqlValue = type { ptr, %union.anon.1 }
%union.anon.1 = type { %union.anon.2 }
%union.anon.2 = type { %struct.anon.4 }
%struct.anon.4 = type { i8, [7 x i8], ptr }
%struct.anon.3 = type { i8, [15 x i8] }

@gql_string_type = external dso_local global %struct._gqlType, align 8
@gql_token_type = external dso_local global %struct._gqlType, align 8
@gql_id_type = external dso_local global %struct._gqlType, align 8
@gql_var_type = external dso_local global %struct._gqlType, align 8

; 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 uwtable
define dso_local ptr @gql_string_get(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store ptr null, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp ne ptr null, %4
  br i1 %5, label %6, label %51

6:                                                ; preds = %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct._gqlValue, ptr %7, i32 0, i32 0
  %9 = load ptr, ptr %8, align 8, !tbaa !9
  %10 = icmp eq ptr @gql_string_type, %9
  br i1 %10, label %33, label %11

11:                                               ; preds = %6
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct._gqlValue, ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = icmp eq ptr @gql_token_type, %14
  br i1 %15, label %33, label %16

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct._gqlValue, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = icmp eq ptr @gql_var_type, %19
  br i1 %20, label %33, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._gqlValue, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = icmp eq ptr @gql_id_type, %24
  br i1 %25, label %33, label %26

26:                                               ; preds = %21
  %27 = load ptr, ptr %2, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct._gqlValue, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %28, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct._gqlType, ptr %29, i32 0, i32 3
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = icmp eq i32 7, %31
  br i1 %32, label %33, label %50

33:                                               ; preds = %26, %21, %16, %11, %6
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._gqlValue, ptr %34, i32 0, i32 1
  %36 = getelementptr inbounds %struct.anon.3, ptr %35, i32 0, i32 0
  %37 = load i8, ptr %36, align 8, !tbaa !15
  %38 = icmp ne i8 %37, 0
  br i1 %38, label %39, label %44

39:                                               ; preds = %33
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct._gqlValue, ptr %40, i32 0, i32 1
  %42 = getelementptr inbounds %struct.anon.4, ptr %41, i32 0, i32 2
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  store ptr %43, ptr %3, align 8, !tbaa !5
  br label %49

44:                                               ; preds = %33
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct._gqlValue, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.anon.3, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds [15 x i8], ptr %47, i64 0, i64 0
  store ptr %48, ptr %3, align 8, !tbaa !5
  br label %49

49:                                               ; preds = %44, %39
  br label %50

50:                                               ; preds = %49, %26
  br label %51

51:                                               ; preds = %50, %1
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret ptr %52
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_gqlValue", !6, i64 0, !7, i64 8}
!11 = !{!12, !13, i64 24}
!12 = !{!"_gqlType", !6, i64 0, !6, i64 8, !6, i64 16, !13, i64 24, !13, i64 28, !14, i64 32, !7, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!7, !7, i64 0}


; 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._gqlType = type { ptr, ptr, ptr, i32, i32, i8, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { ptr, ptr, ptr }

@gql_string_type = external dso_local global %struct._gqlType, align 8
@gql_token_type = external dso_local global %struct._gqlType, align 8
@gql_id_type = external dso_local global %struct._gqlType, align 8
@gql_var_type = external dso_local global %struct._gqlType, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local ptr @gql_string_get(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %20, label %2

2:                                                ; preds = %1
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %3, @gql_string_type
  %5 = icmp eq ptr %3, @gql_token_type
  %or.cond = or i1 %4, %5
  %6 = icmp eq ptr %3, @gql_var_type
  %or.cond13 = or i1 %6, %or.cond
  %7 = icmp eq ptr %3, @gql_id_type
  %or.cond14 = or i1 %7, %or.cond13
  br i1 %or.cond14, label %12, label %8

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %3, i64 24
  %10 = load i32, ptr %9, align 8, !tbaa !10
  %11 = icmp eq i32 %10, 7
  br i1 %11, label %12, label %20

12:                                               ; preds = %8, %2
  %13 = getelementptr inbounds i8, ptr %0, i64 8
  %14 = load i8, ptr %13, align 8, !tbaa !14
  %.not12 = icmp eq i8 %14, 0
  br i1 %.not12, label %18, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  %17 = load ptr, ptr %16, align 8, !tbaa !14
  br label %20

18:                                               ; preds = %12
  %19 = getelementptr inbounds i8, ptr %0, i64 9
  br label %20

20:                                               ; preds = %8, %18, %15, %1
  %.0 = phi ptr [ %17, %15 ], [ %19, %18 ], [ null, %8 ], [ null, %1 ]
  ret ptr %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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" }

!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 = !{!"_gqlValue", !7, i64 0, !8, i64 8}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 24}
!11 = !{!"_gqlType", !7, i64 0, !7, i64 8, !7, i64 16, !12, i64 24, !12, i64 28, !13, i64 32, !8, i64 40}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_Bool", !8, i64 0}
!14 = !{!8, !8, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass