; 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_token_type = external dso_local global %struct._gqlType, align 8
@.str.32 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [9 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

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #1

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @value_create(ptr noundef) #3

; Function Attrs: nounwind
declare noalias ptr @strndup(ptr noundef, i64 noundef) #4

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_token_create(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = icmp sge i32 0, %12
  br i1 %13, label %14, label %18

14:                                               ; preds = %4
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = call i64 @strlen(ptr noundef %15) #6
  %17 = trunc i64 %16 to i32
  store i32 %17, ptr %8, align 4, !tbaa !9
  br label %18

18:                                               ; preds = %14, %4
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp eq ptr null, %19
  br i1 %20, label %26, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._gqlType, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 8, !tbaa !11
  %25 = icmp ne i32 7, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %21, %18
  store ptr @gql_token_type, ptr %9, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %26, %21
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = call ptr @value_create(ptr noundef %28)
  store ptr %29, ptr %10, align 8, !tbaa !5
  %30 = icmp ne ptr null, %29
  br i1 %30, label %31, label %69

31:                                               ; preds = %27
  %32 = load i32, ptr %8, align 4, !tbaa !9
  %33 = icmp sle i32 15, %32
  br i1 %33, label %34, label %50

34:                                               ; preds = %31
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._gqlValue, ptr %35, i32 0, i32 1
  %37 = getelementptr inbounds %struct.anon.3, ptr %36, i32 0, i32 0
  store i8 1, ptr %37, align 8, !tbaa !14
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = call noalias ptr @strndup(ptr noundef %38, i64 noundef %40) #5
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._gqlValue, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds %struct.anon.4, ptr %43, i32 0, i32 2
  store ptr %41, ptr %44, align 8, !tbaa !14
  %45 = icmp eq ptr null, %41
  br i1 %45, label %46, label %49

46:                                               ; preds = %34
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i32 @agoo_err_memory(ptr noundef %47, ptr noundef @.str.33, ptr noundef @.str.32, i32 noundef 1076)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %71

49:                                               ; preds = %34
  br label %68

50:                                               ; preds = %31
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct._gqlValue, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.anon.3, ptr %52, i32 0, i32 0
  store i8 0, ptr %53, align 8, !tbaa !14
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct._gqlValue, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds %struct.anon.3, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds [15 x i8], ptr %56, i64 0, i64 0
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = sext i32 %59 to i64
  %61 = call ptr @strncpy(ptr noundef %57, ptr noundef %58, i64 noundef %60) #5
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct._gqlValue, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds %struct.anon.3, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %8, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [15 x i8], ptr %64, i64 0, i64 %66
  store i8 0, ptr %67, align 1, !tbaa !14
  br label %68

68:                                               ; preds = %50, %49
  br label %69

69:                                               ; preds = %68, %27
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %70, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %71

71:                                               ; preds = %69, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %72 = load ptr, ptr %5, align 8
  ret ptr %72
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { nounwind "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 #5 = { nounwind }
attributes #6 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"_gqlType", !6, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !10, i64 28, !13, i64 32, !7, i64 40}
!13 = !{!"_Bool", !7, i64 0}
!14 = !{!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_token_type = external dso_local global %struct._gqlType, align 8
@.str.32 = external hidden unnamed_addr constant [66 x i8], align 1
@.str.33 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #0

declare i32 @agoo_err_memory(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strndup(ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local ptr @gql_token_create(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = icmp slt i32 %2, 1
  br i1 %5, label %6, label %9

6:                                                ; preds = %4
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %8 = trunc i64 %7 to i32
  br label %9

9:                                                ; preds = %6, %4
  %.019 = phi i32 [ %8, %6 ], [ %2, %4 ]
  %10 = icmp eq ptr %3, null
  br i1 %10, label %14, label %11

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %3, i64 24
  %13 = load i32, ptr %12, align 8, !tbaa !5
  %.not = icmp eq i32 %13, 7
  br i1 %.not, label %15, label %14

14:                                               ; preds = %11, %9
  br label %15

15:                                               ; preds = %14, %11
  %.018 = phi ptr [ @gql_token_type, %14 ], [ %3, %11 ]
  %16 = tail call ptr @value_create(ptr noundef nonnull %.018)
  %.not23 = icmp eq ptr %16, null
  br i1 %.not23, label %32, label %17

17:                                               ; preds = %15
  %18 = icmp sgt i32 %.019, 14
  %19 = getelementptr inbounds i8, ptr %16, i64 8
  br i1 %18, label %20, label %27

20:                                               ; preds = %17
  store i8 1, ptr %19, align 8, !tbaa !12
  %21 = zext nneg i32 %.019 to i64
  %22 = tail call noalias ptr @strndup(ptr noundef %1, i64 noundef %21) #6
  %23 = getelementptr inbounds i8, ptr %16, i64 16
  store ptr %22, ptr %23, align 8, !tbaa !12
  %24 = icmp eq ptr %22, null
  br i1 %24, label %25, label %32

25:                                               ; preds = %20
  %26 = tail call i32 @agoo_err_memory(ptr noundef %0, ptr noundef nonnull @.str.33, ptr noundef nonnull @.str.32, i32 noundef 1076) #6
  br label %32

27:                                               ; preds = %17
  store i8 0, ptr %19, align 8, !tbaa !12
  %28 = getelementptr inbounds i8, ptr %16, i64 9
  %29 = sext i32 %.019 to i64
  %30 = tail call ptr @strncpy(ptr noundef nonnull %28, ptr noundef %1, i64 noundef %29) #6
  %31 = getelementptr inbounds [15 x i8], ptr %28, i64 0, i64 %29
  store i8 0, ptr %31, align 1, !tbaa !12
  br label %32

32:                                               ; preds = %15, %20, %27, %25
  %.0 = phi ptr [ null, %25 ], [ %16, %27 ], [ %16, %20 ], [ null, %15 ]
  ret ptr %.0
}

attributes #0 = { 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 #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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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, !10, i64 24}
!6 = !{!"_gqlType", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !11, i64 32, !8, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_Bool", !8, i64 0}
!12 = !{!8, !8, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass