; LLVM IR from EarlGray/language-incubator :: llvm/kldscp (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.parser = type { i32, i32, ptr }
%struct.lexstate = type { i32, double, [256 x i8], i8, i32, ptr }
%struct.ast_node = type { i32, %union.anon }
%union.anon = type { %struct.anon.2 }
%struct.anon.2 = type { i8, ptr, ptr, i32 }

@stderr = external global ptr, align 8
@.str.26 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [34 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
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @binop_precedence(i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @next_token(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_binop(i8 noundef signext, ptr noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @parse_error(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @parse_expr(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_binop(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.parser, ptr %12, i32 0, i32 2
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.lexstate, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 8, !tbaa !12
  %17 = sext i8 %16 to i32
  store i32 %17, ptr %6, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %18 = load i32, ptr %6, align 4, !tbaa !15
  %19 = call i32 @binop_precedence(i32 noundef %18)
  store i32 %19, ptr %7, align 4, !tbaa !15
  %20 = load i32, ptr %7, align 4, !tbaa !15
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %26

22:                                               ; preds = %2
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = load i32, ptr %6, align 4, !tbaa !15
  %25 = call ptr (ptr, ptr, ...) @parse_error(ptr noundef %23, ptr noundef @.str.26, i32 noundef %24)
  store ptr %25, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %90

26:                                               ; preds = %2
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  call void @next_token(ptr noundef %27)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call ptr @parse_expr(ptr noundef %28)
  store ptr %29, ptr %9, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %26
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %36, label %33

33:                                               ; preds = %30
  %34 = load ptr, ptr @stderr, align 8, !tbaa !5
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef @.str.27) #3
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %89

36:                                               ; preds = %30
  br label %37

37:                                               ; preds = %36
  br label %38

38:                                               ; preds = %37
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.ast_node, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !16
  %42 = icmp ne i32 %41, 2
  br i1 %42, label %43, label %50

43:                                               ; preds = %38
  %44 = load i32, ptr %6, align 4, !tbaa !15
  %45 = trunc i32 %44 to i8
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !15
  %49 = call ptr @new_binop(i8 noundef signext %45, ptr noundef %46, ptr noundef %47, i32 noundef %48)
  store ptr %49, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %89

50:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %51 = load ptr, ptr %9, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.ast_node, ptr %51, i32 0, i32 1
  %53 = getelementptr inbounds %struct.anon.2, ptr %52, i32 0, i32 0
  %54 = load i8, ptr %53, align 8, !tbaa !18
  %55 = sext i8 %54 to i32
  store i32 %55, ptr %10, align 4, !tbaa !15
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.ast_node, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct.anon.2, ptr %57, i32 0, i32 3
  %59 = load i32, ptr %58, align 8, !tbaa !18
  store i32 %59, ptr %11, align 4, !tbaa !15
  %60 = load i32, ptr %7, align 4, !tbaa !15
  %61 = load i32, ptr %11, align 4, !tbaa !15
  %62 = icmp slt i32 %60, %61
  br i1 %62, label %63, label %70

63:                                               ; preds = %50
  %64 = load i32, ptr %6, align 4, !tbaa !15
  %65 = trunc i32 %64 to i8
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load i32, ptr %7, align 4, !tbaa !15
  %69 = call ptr @new_binop(i8 noundef signext %65, ptr noundef %66, ptr noundef %67, i32 noundef %68)
  store ptr %69, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %88

70:                                               ; preds = %50
  %71 = load i32, ptr %10, align 4, !tbaa !15
  %72 = trunc i32 %71 to i8
  %73 = load i32, ptr %6, align 4, !tbaa !15
  %74 = trunc i32 %73 to i8
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.ast_node, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds %struct.anon.2, ptr %77, i32 0, i32 2
  %79 = load ptr, ptr %78, align 8, !tbaa !18
  %80 = load i32, ptr %7, align 4, !tbaa !15
  %81 = call ptr @new_binop(i8 noundef signext %74, ptr noundef %75, ptr noundef %79, i32 noundef %80)
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.ast_node, ptr %82, i32 0, i32 1
  %84 = getelementptr inbounds %struct.anon.2, ptr %83, i32 0, i32 1
  %85 = load ptr, ptr %84, align 8, !tbaa !18
  %86 = load i32, ptr %11, align 4, !tbaa !15
  %87 = call ptr @new_binop(i8 noundef signext %72, ptr noundef %81, ptr noundef %85, i32 noundef %86)
  store ptr %87, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %88

88:                                               ; preds = %70, %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %89

89:                                               ; preds = %88, %43, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %90

90:                                               ; preds = %89, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %91 = load ptr, ptr %3, align 8
  ret ptr %91
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"parser", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 272}
!13 = !{!"lexstate", !11, i64 0, !14, i64 8, !7, i64 16, !7, i64 272, !11, i64 276, !6, i64 280}
!14 = !{!"double", !7, i64 0}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"ast_node", !11, i64 0, !7, i64 8}
!18 = !{!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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.26 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [34 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @binop_precedence(i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_binop(i8 noundef signext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @parse_error(ptr noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @parse_expr(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_binop(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 272
  %6 = load i8, ptr %5, align 8, !tbaa !11
  %7 = sext i8 %6 to i32
  %8 = tail call i32 @binop_precedence(i32 noundef %7)
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %12

10:                                               ; preds = %2
  %11 = tail call ptr (ptr, ptr, ...) @parse_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.26, i32 noundef %7)
  br label %36

12:                                               ; preds = %2
  tail call void @next_token(ptr noundef nonnull %0)
  %13 = tail call ptr @parse_expr(ptr noundef nonnull %0)
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %14, label %17

14:                                               ; preds = %12
  %15 = load ptr, ptr @stderr, align 8, !tbaa !14
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.27) #2
  br label %36

17:                                               ; preds = %12
  %18 = load i32, ptr %13, align 8, !tbaa !15
  %.not31 = icmp eq i32 %18, 2
  br i1 %.not31, label %21, label %19

19:                                               ; preds = %17
  %20 = tail call ptr @new_binop(i8 noundef signext %6, ptr noundef %1, ptr noundef nonnull %13, i32 noundef %8)
  br label %36

21:                                               ; preds = %17
  %22 = getelementptr inbounds i8, ptr %13, i64 32
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = icmp slt i32 %8, %23
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = tail call ptr @new_binop(i8 noundef signext %6, ptr noundef %1, ptr noundef nonnull %13, i32 noundef %8)
  br label %36

27:                                               ; preds = %21
  %28 = getelementptr inbounds i8, ptr %13, i64 8
  %29 = load i8, ptr %28, align 8, !tbaa !17
  %30 = getelementptr inbounds i8, ptr %13, i64 24
  %31 = load ptr, ptr %30, align 8, !tbaa !17
  %32 = tail call ptr @new_binop(i8 noundef signext %6, ptr noundef %1, ptr noundef %31, i32 noundef %8)
  %33 = getelementptr inbounds i8, ptr %13, i64 16
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = tail call ptr @new_binop(i8 noundef signext %29, ptr noundef %32, ptr noundef %34, i32 noundef %23)
  br label %36

36:                                               ; preds = %14, %19, %27, %25, %10
  %.2 = phi ptr [ %11, %10 ], [ %20, %19 ], [ null, %14 ], [ %26, %25 ], [ %35, %27 ]
  ret ptr %.2
}

attributes #0 = { nofree 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 #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 = { cold 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 8}
!6 = !{!"parser", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !8, i64 272}
!12 = !{!"lexstate", !7, i64 0, !13, i64 8, !8, i64 16, !8, i64 272, !7, i64 276, !10, i64 280}
!13 = !{!"double", !8, i64 0}
!14 = !{!10, !10, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"ast_node", !7, i64 0, !8, i64 8}
!17 = !{!8, !8, i64 0}


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