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

; 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_value_t = type { ptr, %union.anon }
%union.anon = type { i64 }
%struct.symboltable_t = type { ptr, i16, i16, i16, i16, i32 }
%struct.ghash_r = type { i64, i64, ptr }

; 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 zeroext i1 @symboltable_insert(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.gravity_value_t, align 8
  %11 = alloca i32, align 4
  %12 = alloca %struct.gravity_value_t, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %16, label %15

15:                                               ; preds = %3
  store i1 false, ptr %4, align 1
  br label %68

16:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.symboltable_t, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.ghash_r, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %20, align 8, !tbaa !13
  store i64 %21, ptr %8, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.symboltable_t, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = getelementptr inbounds %struct.ghash_r, ptr %24, i32 0, i32 2
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = load i64, ptr %8, align 8, !tbaa !16
  %28 = sub i64 %27, 1
  %29 = getelementptr inbounds ptr, ptr %26, i64 %28
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  store ptr %30, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #3
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call { ptr, i64 } @gravity_string_to_value(ptr noundef null, ptr noundef %31, i32 noundef -1)
  %33 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 0
  %34 = extractvalue { ptr, i64 } %32, 0
  store ptr %34, ptr %33, align 8
  %35 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 1
  %36 = extractvalue { ptr, i64 } %32, 1
  store i64 %36, ptr %35, align 8
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8
  %40 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 1
  %41 = load i64, ptr %40, align 8
  %42 = call ptr @gravity_hash_lookup(ptr noundef %37, ptr %39, i64 %41)
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %49

44:                                               ; preds = %16
  %45 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8
  %47 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 1
  %48 = load i64, ptr %47, align 8
  call void @gravity_value_free(ptr noundef null, ptr %46, i64 %48)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %67

49:                                               ; preds = %16
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.gravity_value_t, ptr %12, i32 0, i32 0
  store ptr null, ptr %51, align 8, !tbaa !18
  %52 = getelementptr inbounds %struct.gravity_value_t, ptr %12, i32 0, i32 1
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %53, ptr %52, align 8, !tbaa !20
  %54 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8
  %56 = getelementptr inbounds { ptr, i64 }, ptr %10, i32 0, i32 1
  %57 = load i64, ptr %56, align 8
  %58 = getelementptr inbounds { ptr, i64 }, ptr %12, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8
  %60 = getelementptr inbounds { ptr, i64 }, ptr %12, i32 0, i32 1
  %61 = load i64, ptr %60, align 8
  %62 = call zeroext i1 @gravity_hash_insert(ptr noundef %50, ptr %55, i64 %57, ptr %59, i64 %61)
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.symboltable_t, ptr %63, i32 0, i32 1
  %65 = load i16, ptr %64, align 8, !tbaa !21
  %66 = add i16 %65, 1
  store i16 %66, ptr %64, align 8, !tbaa !21
  store i1 true, ptr %4, align 1
  store i32 1, ptr %11, align 4
  br label %67

67:                                               ; preds = %49, %44
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %68

68:                                               ; preds = %67, %15
  %69 = load i1, ptr %4, align 1
  ret i1 %69
}

declare { ptr, i64 } @gravity_string_to_value(ptr noundef, ptr noundef, i32 noundef) #2

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

declare void @gravity_value_free(ptr noundef, ptr, i64) #2

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

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 = { "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, !6, i64 0}
!10 = !{!"symboltable_t", !6, i64 0, !11, i64 8, !11, i64 10, !11, i64 12, !11, i64 14, !12, i64 16}
!11 = !{!"short", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 8, !6, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!15, !15, i64 0}
!17 = !{!14, !6, i64 16}
!18 = !{!19, !6, i64 0}
!19 = !{!"", !6, i64 0, !7, i64 8}
!20 = !{!7, !7, i64 0}
!21 = !{!10, !11, i64 8}


; 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 noundef zeroext i1 @symboltable_insert(ptr nocapture noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %23, label %4

4:                                                ; preds = %3
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = load i64, ptr %5, align 8, !tbaa !12
  %7 = getelementptr inbounds i8, ptr %5, i64 16
  %8 = load ptr, ptr %7, align 8, !tbaa !15
  %9 = getelementptr ptr, ptr %8, i64 %6
  %10 = getelementptr i8, ptr %9, i64 -8
  %11 = load ptr, ptr %10, align 8, !tbaa !16
  %12 = tail call { ptr, i64 } @gravity_string_to_value(ptr noundef null, ptr noundef nonnull %1, i32 noundef -1) #2
  %13 = extractvalue { ptr, i64 } %12, 0
  %14 = extractvalue { ptr, i64 } %12, 1
  %15 = tail call ptr @gravity_hash_lookup(ptr noundef %11, ptr %13, i64 %14) #2
  %.not15 = icmp eq ptr %15, null
  br i1 %.not15, label %17, label %16

16:                                               ; preds = %4
  tail call void @gravity_value_free(ptr noundef null, ptr %13, i64 %14) #2
  br label %23

17:                                               ; preds = %4
  %18 = ptrtoint ptr %2 to i64
  %19 = tail call zeroext i1 @gravity_hash_insert(ptr noundef %11, ptr %13, i64 %14, ptr null, i64 %18) #2
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i16, ptr %20, align 8, !tbaa !17
  %22 = add i16 %21, 1
  store i16 %22, ptr %20, align 8, !tbaa !17
  br label %23

23:                                               ; preds = %16, %17, %3
  %.1 = phi i1 [ false, %3 ], [ true, %17 ], [ false, %16 ]
  ret i1 %.1
}

declare { ptr, i64 } @gravity_string_to_value(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

declare void @gravity_value_free(ptr noundef, ptr, i64) local_unnamed_addr #1

declare zeroext i1 @gravity_hash_insert(ptr noundef, ptr, i64, ptr, i64) local_unnamed_addr #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 = { "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, !7, i64 0}
!6 = !{!"symboltable_t", !7, i64 0, !10, i64 8, !10, i64 10, !10, i64 12, !10, i64 14, !11, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 8, !7, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!13, !7, i64 16}
!16 = !{!7, !7, i64 0}
!17 = !{!6, !10, i64 8}


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