; 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_binary_expr_t = type { %struct.gnode_t, i32, ptr, ptr }
%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 }

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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @gnode_binary_expr_create(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  store i32 %0, ptr %6, align 4, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !9
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %16

13:                                               ; preds = %4
  %14 = load ptr, ptr %8, align 8, !tbaa !9
  %15 = icmp ne ptr %14, null
  br i1 %15, label %17, label %16

16:                                               ; preds = %13, %4
  store ptr null, ptr %5, align 8
  br label %41

17:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %18 = call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 96)
  store ptr %18, ptr %10, align 8, !tbaa !9
  %19 = load ptr, ptr %10, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.gnode_binary_expr_t, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %struct.gnode_t, ptr %20, i32 0, i32 0
  store i32 13, ptr %21, align 8, !tbaa !11
  %22 = load ptr, ptr %10, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.gnode_binary_expr_t, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds %struct.gnode_t, ptr %23, i32 0, i32 3
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.gnode_t, ptr %25, i32 0, i32 3
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %24, ptr align 8 %26, i64 40, i1 false), !tbaa.struct !16
  %27 = load ptr, ptr %9, align 8, !tbaa !9
  %28 = load ptr, ptr %10, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.gnode_binary_expr_t, ptr %28, i32 0, i32 0
  %30 = getelementptr inbounds %struct.gnode_t, ptr %29, i32 0, i32 5
  store ptr %27, ptr %30, align 8, !tbaa !17
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.gnode_binary_expr_t, ptr %32, i32 0, i32 1
  store i32 %31, ptr %33, align 8, !tbaa !18
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.gnode_binary_expr_t, ptr %35, i32 0, i32 2
  store ptr %34, ptr %36, align 8, !tbaa !19
  %37 = load ptr, ptr %8, align 8, !tbaa !9
  %38 = load ptr, ptr %10, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.gnode_binary_expr_t, ptr %38, i32 0, i32 3
  store ptr %37, ptr %39, align 8, !tbaa !20
  %40 = load ptr, ptr %10, align 8, !tbaa !9
  store ptr %40, ptr %5, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %41

41:                                               ; preds = %17, %16
  %42 = load ptr, ptr %5, align 8
  ret ptr %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !13, i64 0, !6, i64 72, !10, i64 80, !10, i64 88}
!13 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !14, i64 16, !15, i64 56, !10, i64 64}
!14 = !{!"gtoken_s", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !10, i64 32}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5, i64 12, i64 4, !5, i64 16, i64 4, !5, i64 20, i64 4, !5, i64 24, i64 4, !5, i64 28, i64 4, !5, i64 32, i64 8, !9}
!17 = !{!12, !10, i64 64}
!18 = !{!12, !6, i64 72}
!19 = !{!12, !10, i64 80}
!20 = !{!12, !10, i64 88}


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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @gnode_binary_expr_create(i32 noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %5 = icmp ne ptr %1, null
  %6 = icmp ne ptr %2, null
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %15

7:                                                ; preds = %4
  %8 = tail call ptr @gravity_calloc(ptr noundef null, i64 noundef 1, i64 noundef 96) #3
  store i32 13, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %8, i64 16
  %10 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %9, ptr noundef nonnull align 8 dereferenceable(40) %10, i64 40, i1 false), !tbaa.struct !14
  %11 = getelementptr inbounds i8, ptr %8, i64 64
  store ptr %3, ptr %11, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %8, i64 72
  store i32 %0, ptr %12, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %8, i64 80
  store ptr %1, ptr %13, align 8, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %8, i64 88
  store ptr %2, ptr %14, align 8, !tbaa !20
  br label %15

15:                                               ; preds = %4, %7
  %.0 = phi ptr [ %8, %7 ], [ null, %4 ]
  ret ptr %.0
}

attributes #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !8, i64 0}
!6 = !{!"", !7, i64 0, !8, i64 72, !12, i64 80, !12, i64 88}
!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 = !{i64 0, i64 4, !15, i64 4, i64 4, !15, i64 8, i64 4, !15, i64 12, i64 4, !15, i64 16, i64 4, !15, i64 20, i64 4, !15, i64 24, i64 4, !15, i64 28, i64 4, !15, i64 32, i64 8, !16}
!15 = !{!8, !8, i64 0}
!16 = !{!12, !12, i64 0}
!17 = !{!6, !12, i64 64}
!18 = !{!6, !8, i64 72}
!19 = !{!6, !12, i64 80}
!20 = !{!6, !12, i64 88}


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