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

@stderr = external global ptr, align 8
@.str.17 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_list() #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @list_append(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_funcall(ptr noundef, ptr noundef) #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_idexpr(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.parser, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = icmp ne i32 %10, -4
  br i1 %11, label %12, label %15

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = call ptr (ptr, ptr, ...) @parse_error(ptr noundef %13, ptr noundef @.str.17)
  store ptr %14, ptr %2, align 8
  br label %82

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.parser, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = getelementptr inbounds %struct.lexstate, ptr %18, i32 0, i32 2
  %20 = getelementptr inbounds [256 x i8], ptr %19, i64 0, i64 0
  %21 = call noalias ptr @strdup(ptr noundef %20) #3
  store ptr %21, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %22)
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.parser, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !9
  %26 = icmp ne i32 %25, 40
  br i1 %26, label %27, label %30

27:                                               ; preds = %15
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = call ptr @new_var(ptr noundef %28)
  store ptr %29, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %81

30:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %31)
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.parser, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !9
  %35 = icmp eq i32 %34, 41
  br i1 %35, label %36, label %38

36:                                               ; preds = %30
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %37)
  br label %76

38:                                               ; preds = %30
  %39 = call ptr @new_list()
  store ptr %39, ptr %6, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %74, %38
  br label %41

41:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call ptr @parse_expr(ptr noundef %42)
  store ptr %43, ptr %7, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %50, label %47

47:                                               ; preds = %44
  %48 = load ptr, ptr @stderr, align 8, !tbaa !5
  %49 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %48, ptr noundef @.str.18) #3
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %72

50:                                               ; preds = %44
  br label %51

51:                                               ; preds = %50
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = call ptr @list_append(ptr noundef %53, ptr noundef %54)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.parser, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !9
  %59 = icmp eq i32 %58, 41
  br i1 %59, label %60, label %62

60:                                               ; preds = %52
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %61)
  store i32 3, ptr %5, align 4
  br label %72

62:                                               ; preds = %52
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.parser, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 8, !tbaa !9
  %66 = icmp ne i32 %65, 44
  br i1 %66, label %67, label %70

67:                                               ; preds = %62
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = call ptr (ptr, ptr, ...) @parse_error(ptr noundef %68, ptr noundef @.str.19)
  store ptr %69, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %72

70:                                               ; preds = %62
  %71 = load ptr, ptr %3, align 8, !tbaa !5
  call void @next_token(ptr noundef %71)
  store i32 0, ptr %5, align 4
  br label %72

72:                                               ; preds = %70, %67, %60, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %73 = load i32, ptr %5, align 4
  switch i32 %73, label %80 [
    i32 0, label %74
    i32 3, label %75
  ]

74:                                               ; preds = %72
  br label %40

75:                                               ; preds = %72
  br label %76

76:                                               ; preds = %75, %36
  %77 = load ptr, ptr %4, align 8, !tbaa !5
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = call ptr @new_funcall(ptr noundef %77, ptr noundef %78)
  store ptr %79, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %80

80:                                               ; preds = %76, %72
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %81

81:                                               ; preds = %80, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %82

82:                                               ; preds = %81, %12
  %83 = load ptr, ptr %2, align 8
  ret ptr %83
}

; Function Attrs: nounwind
declare noalias ptr @strdup(ptr noundef) #2

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 = { 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 #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, !11, i64 0}
!10 = !{!"parser", !11, i64 0, !11, i64 4, !6, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, 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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.17 = external hidden unnamed_addr constant [27 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [38 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @new_list() local_unnamed_addr #0

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

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @parse_idexpr(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %2, -4
  br i1 %.not, label %5, label %3

3:                                                ; preds = %1
  %4 = tail call ptr (ptr, ptr, ...) @parse_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.17)
  br label %.thread

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %7, i64 16
  %9 = tail call noalias ptr @strdup(ptr noundef nonnull %8) #3
  tail call void @next_token(ptr noundef nonnull %0)
  %10 = load i32, ptr %0, align 8, !tbaa !5
  %.not25 = icmp eq i32 %10, 40
  br i1 %.not25, label %13, label %11

11:                                               ; preds = %5
  %12 = tail call ptr @new_var(ptr noundef %9)
  br label %.thread

13:                                               ; preds = %5
  tail call void @next_token(ptr noundef nonnull %0)
  %14 = load i32, ptr %0, align 8, !tbaa !5
  %15 = icmp eq i32 %14, 41
  br i1 %15, label %.thread30, label %16

16:                                               ; preds = %13
  %17 = tail call ptr @new_list()
  %18 = tail call ptr @parse_expr(ptr noundef nonnull %0)
  %.not2633 = icmp eq ptr %18, null
  br i1 %.not2633, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %26, %16
  %19 = load ptr, ptr @stderr, align 8, !tbaa !12
  %20 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %19, ptr noundef nonnull @.str.18) #4
  br label %.thread

.lr.ph:                                           ; preds = %16, %26
  %21 = phi ptr [ %27, %26 ], [ %18, %16 ]
  %22 = tail call ptr @list_append(ptr noundef %17, ptr noundef nonnull %21)
  %23 = load i32, ptr %0, align 8, !tbaa !5
  switch i32 %23, label %24 [
    i32 41, label %.thread30
    i32 44, label %26
  ]

24:                                               ; preds = %.lr.ph
  %25 = tail call ptr (ptr, ptr, ...) @parse_error(ptr noundef nonnull %0, ptr noundef nonnull @.str.19)
  br label %.thread

26:                                               ; preds = %.lr.ph
  tail call void @next_token(ptr noundef nonnull %0)
  %27 = tail call ptr @parse_expr(ptr noundef nonnull %0)
  %.not26 = icmp eq ptr %27, null
  br i1 %.not26, label %._crit_edge, label %.lr.ph

.thread30:                                        ; preds = %.lr.ph, %13
  %.021 = phi ptr [ null, %13 ], [ %17, %.lr.ph ]
  tail call void @next_token(ptr noundef nonnull %0)
  %28 = tail call ptr @new_funcall(ptr noundef %9, ptr noundef %.021)
  br label %.thread

.thread:                                          ; preds = %._crit_edge, %24, %11, %.thread30, %3
  %.4 = phi ptr [ %4, %3 ], [ %12, %11 ], [ %28, %.thread30 ], [ null, %._crit_edge ], [ %25, %24 ]
  ret ptr %.4
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias ptr @strdup(ptr nocapture noundef readonly) local_unnamed_addr #2

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 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 }
attributes #4 = { 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, !7, i64 0}
!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 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass