; LLVM IR from marcobambini/gravity :: src/compiler (gravity_parser)

; 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.gravity_parser_t = type { ptr, ptr, ptr, ptr, %struct.uint16_r, double, i32, i32, i32, i32, i32, i32, ptr }
%struct.uint16_r = type { i64, i64, ptr }
%struct.lexer_r = type { i64, i64, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_parser_create(ptr noundef %0, i64 noundef %1, i32 noundef %2, i1 noundef zeroext %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i8, align 1
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !11
  %13 = zext i1 %3 to i8
  store i8 %13, ptr %9, align 1, !tbaa !13
  call void @init_grammer_rules()
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %14 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 96)
  store ptr %14, ptr %10, align 8, !tbaa !5
  %15 = load ptr, ptr %10, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %18, label %17

17:                                               ; preds = %4
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %139

18:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i64, ptr %7, align 8, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = load i8, ptr %9, align 1, !tbaa !13, !range !15, !noundef !16
  %23 = trunc i8 %22 to i1
  %24 = call ptr @gravity_lexer_create(ptr noundef %19, i64 noundef %20, i32 noundef %21, i1 noundef zeroext %23)
  store ptr %24, ptr %12, align 8, !tbaa !5
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %28, label %27

27:                                               ; preds = %18
  br label %136

28:                                               ; preds = %18
  %29 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 24)
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gravity_parser_t, ptr %30, i32 0, i32 0
  store ptr %29, ptr %31, align 8, !tbaa !17
  %32 = load ptr, ptr %10, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.gravity_parser_t, ptr %32, i32 0, i32 0
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = getelementptr inbounds %struct.lexer_r, ptr %34, i32 0, i32 1
  store i64 0, ptr %35, align 8, !tbaa !21
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gravity_parser_t, ptr %36, i32 0, i32 0
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = getelementptr inbounds %struct.lexer_r, ptr %38, i32 0, i32 0
  store i64 0, ptr %39, align 8, !tbaa !22
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gravity_parser_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = getelementptr inbounds %struct.lexer_r, ptr %42, i32 0, i32 2
  store ptr null, ptr %43, align 8, !tbaa !23
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.gravity_parser_t, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = getelementptr inbounds %struct.lexer_r, ptr %46, i32 0, i32 0
  %48 = load i64, ptr %47, align 8, !tbaa !22
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.gravity_parser_t, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %50, align 8, !tbaa !17
  %52 = getelementptr inbounds %struct.lexer_r, ptr %51, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !21
  %54 = icmp eq i64 %48, %53
  br i1 %54, label %55, label %92

55:                                               ; preds = %28
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.gravity_parser_t, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !17
  %59 = getelementptr inbounds %struct.lexer_r, ptr %58, i32 0, i32 1
  %60 = load i64, ptr %59, align 8, !tbaa !21
  %61 = icmp ne i64 %60, 0
  br i1 %61, label %62, label %69

62:                                               ; preds = %55
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.gravity_parser_t, ptr %63, i32 0, i32 0
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  %66 = getelementptr inbounds %struct.lexer_r, ptr %65, i32 0, i32 1
  %67 = load i64, ptr %66, align 8, !tbaa !21
  %68 = shl i64 %67, 1
  br label %70

69:                                               ; preds = %55
  br label %70

70:                                               ; preds = %69, %62
  %71 = phi i64 [ %68, %62 ], [ 8, %69 ]
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gravity_parser_t, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = getelementptr inbounds %struct.lexer_r, ptr %74, i32 0, i32 1
  store i64 %71, ptr %75, align 8, !tbaa !21
  %76 = load ptr, ptr %10, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.gravity_parser_t, ptr %76, i32 0, i32 0
  %78 = load ptr, ptr %77, align 8, !tbaa !17
  %79 = getelementptr inbounds %struct.lexer_r, ptr %78, i32 0, i32 2
  %80 = load ptr, ptr %79, align 8, !tbaa !23
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.gravity_parser_t, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !17
  %84 = getelementptr inbounds %struct.lexer_r, ptr %83, i32 0, i32 1
  %85 = load i64, ptr %84, align 8, !tbaa !21
  %86 = mul i64 8, %85
  %87 = call ptr @realloc(ptr noundef %80, i64 noundef %86) #5
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.gravity_parser_t, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !17
  %91 = getelementptr inbounds %struct.lexer_r, ptr %90, i32 0, i32 2
  store ptr %87, ptr %91, align 8, !tbaa !23
  br label %92

92:                                               ; preds = %70, %28
  %93 = load ptr, ptr %12, align 8, !tbaa !5
  %94 = load ptr, ptr %10, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.gravity_parser_t, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !17
  %97 = getelementptr inbounds %struct.lexer_r, ptr %96, i32 0, i32 2
  %98 = load ptr, ptr %97, align 8, !tbaa !23
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.gravity_parser_t, ptr %99, i32 0, i32 0
  %101 = load ptr, ptr %100, align 8, !tbaa !17
  %102 = getelementptr inbounds %struct.lexer_r, ptr %101, i32 0, i32 0
  %103 = load i64, ptr %102, align 8, !tbaa !22
  %104 = add i64 %103, 1
  store i64 %104, ptr %102, align 8, !tbaa !22
  %105 = getelementptr inbounds ptr, ptr %98, i64 %103
  store ptr %93, ptr %105, align 8, !tbaa !5
  %106 = call ptr @gnode_array_create()
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.gravity_parser_t, ptr %107, i32 0, i32 2
  store ptr %106, ptr %108, align 8, !tbaa !24
  %109 = load ptr, ptr %10, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.gravity_parser_t, ptr %109, i32 0, i32 2
  %111 = load ptr, ptr %110, align 8, !tbaa !24
  %112 = icmp ne ptr %111, null
  br i1 %112, label %114, label %113

113:                                              ; preds = %92
  br label %136

114:                                              ; preds = %92
  %115 = call ptr @gnode_array_create()
  %116 = load ptr, ptr %10, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.gravity_parser_t, ptr %116, i32 0, i32 1
  store ptr %115, ptr %117, align 8, !tbaa !25
  %118 = load ptr, ptr %10, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.gravity_parser_t, ptr %118, i32 0, i32 1
  %120 = load ptr, ptr %119, align 8, !tbaa !25
  %121 = icmp ne ptr %120, null
  br i1 %121, label %123, label %122

122:                                              ; preds = %114
  br label %136

123:                                              ; preds = %114
  %124 = load ptr, ptr %10, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.gravity_parser_t, ptr %124, i32 0, i32 4
  %126 = getelementptr inbounds %struct.uint16_r, ptr %125, i32 0, i32 1
  store i64 0, ptr %126, align 8, !tbaa !26
  %127 = load ptr, ptr %10, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.gravity_parser_t, ptr %127, i32 0, i32 4
  %129 = getelementptr inbounds %struct.uint16_r, ptr %128, i32 0, i32 0
  store i64 0, ptr %129, align 8, !tbaa !27
  %130 = load ptr, ptr %10, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.gravity_parser_t, ptr %130, i32 0, i32 4
  %132 = getelementptr inbounds %struct.uint16_r, ptr %131, i32 0, i32 2
  store ptr null, ptr %132, align 8, !tbaa !28
  %133 = load ptr, ptr %10, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.gravity_parser_t, ptr %133, i32 0, i32 8
  store i32 -1, ptr %134, align 8, !tbaa !29
  %135 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %135, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %138

136:                                              ; preds = %122, %113, %27
  %137 = load ptr, ptr %10, align 8, !tbaa !5
  call void @gravity_parser_free(ptr noundef %137)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %138

138:                                              ; preds = %136, %123
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %139

139:                                              ; preds = %138, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %140 = load ptr, ptr %5, align 8
  ret ptr %140
}

; Function Attrs: nounwind uwtable
declare hidden void @init_grammer_rules() #0

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

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) #2

declare ptr @gravity_lexer_create(ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext) #2

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

declare ptr @gnode_array_create() #2

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_parser_free(ptr noundef) #0

; 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 allocsize(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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(1) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!18, !6, i64 0}
!18 = !{!"gravity_parser_t", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !19, i64 32, !20, i64 56, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !6, i64 88}
!19 = !{!"", !10, i64 0, !10, i64 8, !6, i64 16}
!20 = !{!"double", !7, i64 0}
!21 = !{!19, !10, i64 8}
!22 = !{!19, !10, i64 0}
!23 = !{!19, !6, i64 16}
!24 = !{!18, !6, i64 16}
!25 = !{!18, !6, i64 8}
!26 = !{!18, !10, i64 40}
!27 = !{!18, !10, i64 32}
!28 = !{!18, !6, i64 48}
!29 = !{!18, !12, i64 72}


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

; Function Attrs: nounwind uwtable
define dso_local ptr @gravity_parser_create(ptr noundef %0, i64 noundef %1, i32 noundef %2, i1 noundef zeroext %3) local_unnamed_addr #0 {
  tail call void @init_grammer_rules()
  %5 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 96) #4
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %21, label %6

6:                                                ; preds = %4
  %7 = tail call ptr @gravity_lexer_create(ptr noundef %0, i64 noundef %1, i32 noundef %2, i1 noundef zeroext %3) #4
  %.not34 = icmp eq ptr %7, null
  br i1 %.not34, label %20, label %8

8:                                                ; preds = %6
  %9 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 24) #4
  store ptr %9, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = getelementptr inbounds i8, ptr %9, i64 16
  store i64 8, ptr %10, align 8, !tbaa !14
  %malloc = tail call dereferenceable_or_null(64) ptr @malloc(i64 64)
  store ptr %malloc, ptr %11, align 8, !tbaa !15
  store i64 1, ptr %9, align 8, !tbaa !16
  store ptr %7, ptr %malloc, align 8, !tbaa !17
  %12 = tail call ptr @gnode_array_create() #4
  %13 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %12, ptr %13, align 8, !tbaa !18
  %.not35 = icmp eq ptr %12, null
  br i1 %.not35, label %20, label %14

14:                                               ; preds = %8
  %15 = tail call ptr @gnode_array_create() #4
  %16 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !19
  %.not36 = icmp eq ptr %15, null
  br i1 %.not36, label %20, label %17

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %5, i64 32
  %19 = getelementptr inbounds i8, ptr %5, i64 72
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %18, i8 0, i64 24, i1 false)
  store i32 -1, ptr %19, align 8, !tbaa !20
  br label %21

20:                                               ; preds = %14, %8, %6
  tail call void @gravity_parser_free(ptr noundef nonnull %5)
  br label %21

21:                                               ; preds = %17, %20, %4
  %.1 = phi ptr [ null, %4 ], [ %5, %17 ], [ null, %20 ]
  ret ptr %.1
}

; Function Attrs: nounwind uwtable
declare hidden void @init_grammer_rules() local_unnamed_addr #0

declare ptr @gravity_calloc(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

declare ptr @gravity_lexer_create(ptr noundef, i64 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #1

declare ptr @gnode_array_create() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @gravity_parser_free(ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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 = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 0}
!6 = !{!"gravity_parser_t", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !12, i64 56, !13, i64 64, !13, i64 68, !13, i64 72, !13, i64 76, !13, i64 80, !13, i64 84, !7, i64 88}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !7, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!"int", !8, i64 0}
!14 = !{!10, !11, i64 8}
!15 = !{!10, !7, i64 16}
!16 = !{!10, !11, i64 0}
!17 = !{!7, !7, i64 0}
!18 = !{!6, !7, i64 16}
!19 = !{!6, !7, i64 8}
!20 = !{!6, !13, i64 72}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass