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

; 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.gnode_keyword_expr_t = type { %struct.gnode_t }
%struct.gnode_t = type { i32, i32, i32, %struct.gtoken_s, i8, ptr }
%struct.gtoken_s = type { i32, i32, i32, i32, i32, i32, i32, i32, ptr }
%struct.gnode_var_t = type { %struct.gnode_t, ptr, ptr, ptr, ptr, i32, i16, i8, i8, ptr }
%struct.gnode_class_decl_t = type { %struct.gnode_t, i8, i8, ptr, i32, i32, ptr, ptr, i8, ptr, ptr, ptr, ptr, i32, i32 }
%struct.gnode_identifier_expr_t = type { %struct.gnode_t, ptr, ptr, ptr, %struct.gnode_location_t, ptr }
%struct.gnode_location_t = type { i32, i16, i16 }
%struct.gnode_function_decl_t = type { %struct.gnode_t, ptr, i32, i32, ptr, ptr, ptr, ptr, i16, i16, i8, i8, ptr }
%struct.gnode_enum_decl_t = type { %struct.gnode_t, ptr, i32, i32, ptr, ptr }
%struct.gnode_module_decl_t = type { %struct.gnode_t, ptr, i32, i32, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @gnode_identifier(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %16

6:                                                ; preds = %1
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.gnode_keyword_expr_t, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds %struct.gnode_t, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp eq i32 %10, 12
  br i1 %11, label %12, label %16

12:                                               ; preds = %6
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.gnode_var_t, ptr %13, i32 0, i32 2
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  store ptr %15, ptr %2, align 8
  br label %82

16:                                               ; preds = %6, %1
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %29

19:                                               ; preds = %16
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.gnode_keyword_expr_t, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds %struct.gnode_t, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = icmp eq i32 %23, 10
  br i1 %24, label %25, label %29

25:                                               ; preds = %19
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.gnode_class_decl_t, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  store ptr %28, ptr %2, align 8
  br label %82

29:                                               ; preds = %19, %16
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %42

32:                                               ; preds = %29
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gnode_keyword_expr_t, ptr %33, i32 0, i32 0
  %35 = getelementptr inbounds %struct.gnode_t, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = icmp eq i32 %36, 18
  br i1 %37, label %38, label %42

38:                                               ; preds = %32
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.gnode_identifier_expr_t, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !20
  store ptr %41, ptr %2, align 8
  br label %82

42:                                               ; preds = %32, %29
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %55

45:                                               ; preds = %42
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.gnode_keyword_expr_t, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds %struct.gnode_t, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 8, !tbaa !9
  %50 = icmp eq i32 %49, 8
  br i1 %50, label %51, label %55

51:                                               ; preds = %45
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.gnode_function_decl_t, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !23
  store ptr %54, ptr %2, align 8
  br label %82

55:                                               ; preds = %45, %42
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %68

58:                                               ; preds = %55
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.gnode_keyword_expr_t, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds %struct.gnode_t, ptr %60, i32 0, i32 0
  %62 = load i32, ptr %61, align 8, !tbaa !9
  %63 = icmp eq i32 %62, 7
  br i1 %63, label %64, label %68

64:                                               ; preds = %58
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.gnode_enum_decl_t, ptr %65, i32 0, i32 5
  %67 = load ptr, ptr %66, align 8, !tbaa !25
  store ptr %67, ptr %2, align 8
  br label %82

68:                                               ; preds = %58, %55
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %81

71:                                               ; preds = %68
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.gnode_keyword_expr_t, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.gnode_t, ptr %73, i32 0, i32 0
  %75 = load i32, ptr %74, align 8, !tbaa !9
  %76 = icmp eq i32 %75, 11
  br i1 %76, label %77, label %81

77:                                               ; preds = %71
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.gnode_module_decl_t, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !27
  store ptr %80, ptr %2, align 8
  br label %82

81:                                               ; preds = %71, %68
  store ptr null, ptr %2, align 8
  br label %82

82:                                               ; preds = %81, %77, %64, %51, %38, %25, %12
  %83 = load ptr, ptr %2, align 8
  ret ptr %83
}

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

!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, !12, i64 0}
!10 = !{!"", !11, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !13, i64 16, !14, i64 56, !6, i64 64}
!12 = !{!"int", !7, i64 0}
!13 = !{!"gtoken_s", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !6, i64 32}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !6, i64 80}
!16 = !{!"", !11, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !12, i64 104, !17, i64 108, !14, i64 110, !14, i64 111, !6, i64 112}
!17 = !{!"short", !7, i64 0}
!18 = !{!19, !6, i64 96}
!19 = !{!"", !11, i64 0, !14, i64 72, !14, i64 73, !6, i64 80, !12, i64 88, !12, i64 92, !6, i64 96, !6, i64 104, !14, i64 112, !6, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !12, i64 152, !12, i64 156}
!20 = !{!21, !6, i64 72}
!21 = !{!"", !11, i64 0, !6, i64 72, !6, i64 80, !6, i64 88, !22, i64 96, !6, i64 104}
!22 = !{!"", !12, i64 0, !17, i64 4, !17, i64 6}
!23 = !{!24, !6, i64 96}
!24 = !{!"", !11, i64 0, !6, i64 72, !12, i64 80, !12, i64 84, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !17, i64 120, !17, i64 122, !14, i64 124, !14, i64 125, !6, i64 128}
!25 = !{!26, !6, i64 96}
!26 = !{!"", !11, i64 0, !6, i64 72, !12, i64 80, !12, i64 84, !6, i64 88, !6, i64 96}
!27 = !{!28, !6, i64 88}
!28 = !{!"", !11, i64 0, !6, i64 72, !12, i64 80, !12, i64 84, !6, i64 88, !6, i64 96, !6, i64 104}


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

@switch.table.gnode_identifier = private unnamed_addr constant [12 x i64] [i64 96, i64 96, i64 80, i64 96, i64 88, i64 80, i64 80, i64 80, i64 80, i64 80, i64 80, i64 72], align 8

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

2:                                                ; preds = %1
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %switch.tableidx = add i32 %3, -7
  %4 = icmp ult i32 %switch.tableidx, 12
  br i1 %4, label %switch.hole_check, label %.critedge23

switch.hole_check:                                ; preds = %2
  %switch.maskindex = trunc nuw i32 %switch.tableidx to i16
  %switch.shifted = lshr i16 2107, %switch.maskindex
  %switch.lobit = trunc i16 %switch.shifted to i1
  br i1 %switch.lobit, label %switch.lookup, label %.critedge23

switch.lookup:                                    ; preds = %switch.hole_check
  %5 = zext nneg i32 %switch.tableidx to i64
  %switch.gep = getelementptr inbounds [12 x i64], ptr @switch.table.gnode_identifier, i64 0, i64 %5
  %switch.load = load i64, ptr %switch.gep, align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 %switch.load
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  br label %.critedge23

.critedge23:                                      ; preds = %switch.hole_check, %2, %switch.lookup, %1
  %.0 = phi ptr [ null, %1 ], [ null, %2 ], [ %7, %switch.lookup ], [ null, %switch.hole_check ]
  ret ptr %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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, !8, i64 0}
!6 = !{!"", !7, i64 0}
!7 = !{!"", !8, i64 0, !8, i64 4, !8, i64 8, !11, i64 16, !13, i64 56, !12, i64 64}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"gtoken_s", !8, i64 0, !8, i64 4, !8, i64 8, !8, i64 12, !8, i64 16, !8, i64 20, !8, i64 24, !8, i64 28, !12, i64 32}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!"_Bool", !9, i64 0}
!14 = !{!12, !12, i64 0}


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