; LLVM IR from masyagin1998/GCI :: src/parser (parser)

; 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_ERROR = type { [16 x i32], i32, i64, i64 }

@stderr = external global ptr, align 8
@.str.42 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [2 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: nounwind
declare i32 @fprintf(ptr noundef, ptr 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: nounwind uwtable
declare dso_local void @token_type_to_str(i32 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @print_parser_error(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca [128 x i8], align 16
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 128, ptr %4) #3
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.PARSER_ERROR, ptr %5, i32 0, i32 1
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  call void @token_type_to_str(i32 noundef %7, ptr noundef %8, i64 noundef 128)
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.PARSER_ERROR, ptr %10, i32 0, i32 2
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.PARSER_ERROR, ptr %13, i32 0, i32 3
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %17 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef @.str.42, i64 noundef %12, i64 noundef %15, ptr noundef %16) #3
  store i64 0, ptr %3, align 8, !tbaa !15
  br label %18

18:                                               ; preds = %25, %1
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.PARSER_ERROR, ptr %19, i32 0, i32 0
  %21 = load i64, ptr %3, align 8, !tbaa !15
  %22 = getelementptr inbounds [16 x i32], ptr %20, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !16
  %24 = icmp ne i32 %23, 38
  br i1 %24, label %25, label %37

25:                                               ; preds = %18
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.PARSER_ERROR, ptr %26, i32 0, i32 0
  %28 = load i64, ptr %3, align 8, !tbaa !15
  %29 = getelementptr inbounds [16 x i32], ptr %27, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !16
  %31 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  call void @token_type_to_str(i32 noundef %30, ptr noundef %31, i64 noundef 128)
  %32 = load ptr, ptr @stderr, align 8, !tbaa !5
  %33 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %34 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %32, ptr noundef @.str.43, ptr noundef %33) #3
  %35 = load i64, ptr %3, align 8, !tbaa !15
  %36 = add i64 %35, 1
  store i64 %36, ptr %3, align 8, !tbaa !15
  br label %18, !llvm.loop !17

37:                                               ; preds = %18
  %38 = load ptr, ptr @stderr, align 8, !tbaa !5
  %39 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %38, ptr noundef @.str.44) #3
  call void @llvm.lifetime.end.p0(i64 128, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

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, !11, i64 64}
!10 = !{!"PARSER_ERROR", !7, i64 0, !11, i64 64, !12, i64 72, !12, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 72}
!14 = !{!10, !12, i64 80}
!15 = !{!12, !12, i64 0}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.42 = external hidden unnamed_addr constant [55 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @token_type_to_str(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @print_parser_error(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = alloca [128 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %2) #3
  %3 = getelementptr inbounds i8, ptr %0, i64 64
  %4 = load i32, ptr %3, align 8, !tbaa !5
  call void @token_type_to_str(i32 noundef %4, ptr noundef nonnull %2, i64 noundef 128)
  %5 = load ptr, ptr @stderr, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load i64, ptr %6, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = load i64, ptr %8, align 8, !tbaa !14
  %10 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %5, ptr noundef nonnull @.str.42, i64 noundef %7, i64 noundef %9, ptr noundef nonnull %2) #4
  %11 = load i32, ptr %0, align 4, !tbaa !15
  %.not8 = icmp eq i32 %11, 38
  br i1 %.not8, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1, %.lr.ph
  %12 = phi i32 [ %17, %.lr.ph ], [ %11, %1 ]
  %.09 = phi i64 [ %15, %.lr.ph ], [ 0, %1 ]
  call void @token_type_to_str(i32 noundef %12, ptr noundef nonnull %2, i64 noundef 128)
  %13 = load ptr, ptr @stderr, align 8, !tbaa !11
  %14 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %13, ptr noundef nonnull @.str.43, ptr noundef nonnull %2) #4
  %15 = add i64 %.09, 1
  %16 = getelementptr inbounds [16 x i32], ptr %0, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %.not = icmp eq i32 %17, 38
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !16

._crit_edge:                                      ; preds = %.lr.ph, %1
  %18 = load ptr, ptr @stderr, align 8, !tbaa !11
  %19 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.44) #4
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %2) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 }
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, !9, i64 64}
!6 = !{!"PARSER_ERROR", !7, i64 0, !9, i64 64, !10, i64 72, !10, i64 80}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!6, !10, i64 72}
!14 = !{!6, !10, i64 80}
!15 = !{!9, !9, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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