; LLVM IR from jspd-group/pegit :: src (main)

; 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.command_type = type { i32, ptr, ptr }
%struct.core_commands = type { i32, i32, %struct.command, ptr }
%struct.command = type { %struct.strbuf, i32, i32, i32, ptr }
%struct.strbuf = type { i64, i64, ptr }

@cmds = external hidden global [17 x %struct.command_type], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @init_command(ptr noundef) #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 void @read_user_cmds(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @gen_core_commands(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %54, %1
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = icmp slt i32 %8, 16
  br i1 %9, label %11, label %10

10:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %57

11:                                               ; preds = %7
  %12 = call noalias ptr @malloc(i64 noundef 64) #5
  store ptr %12, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.core_commands, ptr %13, i32 0, i32 2
  call void @init_command(ptr noundef %14)
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.core_commands, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds %struct.command, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [17 x %struct.command_type], ptr @cmds, i64 0, i64 %19
  %21 = getelementptr inbounds %struct.command_type, ptr %20, i32 0, i32 1
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  call void @strbuf_addstr(ptr noundef %17, ptr noundef %22)
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [17 x %struct.command_type], ptr @cmds, i64 0, i64 %24
  %26 = getelementptr inbounds %struct.command_type, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !13
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.core_commands, ptr %28, i32 0, i32 2
  %30 = getelementptr inbounds %struct.command, ptr %29, i32 0, i32 1
  store i32 %27, ptr %30, align 8, !tbaa !14
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.core_commands, ptr %31, i32 0, i32 1
  store i32 0, ptr %32, align 4, !tbaa !19
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.core_commands, ptr %33, i32 0, i32 0
  store i32 0, ptr %34, align 8, !tbaa !20
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.core_commands, ptr %35, i32 0, i32 3
  store ptr null, ptr %36, align 8, !tbaa !21
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %43, label %40

40:                                               ; preds = %11
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %41, ptr %42, align 8, !tbaa !5
  br label %47

43:                                               ; preds = %11
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.core_commands, ptr %45, i32 0, i32 3
  store ptr %44, ptr %46, align 8, !tbaa !21
  br label %47

47:                                               ; preds = %43, %40
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %48, ptr %3, align 8, !tbaa !5
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.core_commands, ptr %50, i32 0, i32 0
  %52 = load i32, ptr %51, align 8, !tbaa !20
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %51, align 8, !tbaa !20
  br label %54

54:                                               ; preds = %47
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !22

57:                                               ; preds = %10
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  call void @read_user_cmds(ptr noundef %58, ptr noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @strbuf_addstr(ptr noundef, ptr noundef) #3

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 allocsize(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 = { inlinehint 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 }
attributes #5 = { nounwind allocsize(0) }

!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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"command_type", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !10, i64 0}
!14 = !{!15, !10, i64 32}
!15 = !{!"core_commands", !10, i64 0, !10, i64 4, !16, i64 8, !6, i64 56}
!16 = !{!"command", !17, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40}
!17 = !{!"strbuf", !18, i64 0, !18, i64 8, !6, i64 16}
!18 = !{!"long", !7, i64 0}
!19 = !{!15, !10, i64 4}
!20 = !{!15, !10, i64 0}
!21 = !{!15, !6, i64 56}
!22 = distinct !{!22, !23}
!23 = !{!"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"

%struct.command_type = type { i32, ptr, ptr }

@cmds = external hidden local_unnamed_addr global [17 x %struct.command_type], align 16

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

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

; Function Attrs: nounwind uwtable
define dso_local void @gen_core_commands(ptr noundef %0) local_unnamed_addr #0 {
  store ptr null, ptr %0, align 8, !tbaa !5
  br label %3

2:                                                ; preds = %3
  tail call void @read_user_cmds(ptr noundef nonnull %0, ptr noundef nonnull %4)
  ret void

3:                                                ; preds = %1, %3
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next, %3 ]
  %.01920 = phi ptr [ undef, %1 ], [ %4, %3 ]
  %4 = tail call noalias dereferenceable_or_null(64) ptr @malloc(i64 noundef 64) #3
  %5 = getelementptr inbounds i8, ptr %4, i64 8
  tail call void @init_command(ptr noundef nonnull %5)
  %6 = getelementptr inbounds [17 x %struct.command_type], ptr @cmds, i64 0, i64 %indvars.iv
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  tail call void @strbuf_addstr(ptr noundef nonnull %5, ptr noundef %8)
  %9 = load i32, ptr %6, align 8, !tbaa !12
  %10 = getelementptr inbounds i8, ptr %4, i64 32
  store i32 %9, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 0, ptr %11, align 4, !tbaa !18
  store i32 0, ptr %4, align 8, !tbaa !19
  %12 = getelementptr inbounds i8, ptr %4, i64 56
  store ptr null, ptr %12, align 8, !tbaa !20
  %13 = load ptr, ptr %0, align 8, !tbaa !5
  %.not = icmp eq ptr %13, null
  %14 = getelementptr inbounds i8, ptr %.01920, i64 56
  %.sink = select i1 %.not, ptr %0, ptr %14
  %15 = select i1 %.not, ptr %4, ptr %13
  store ptr %4, ptr %.sink, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 8, !tbaa !19
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %15, align 8, !tbaa !19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 16
  br i1 %exitcond.not, label %2, label %3, !llvm.loop !21
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @strbuf_addstr(ptr noundef, ptr noundef) 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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { inlinehint 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 allocsize(0) }

!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 = !{!"command_type", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!14, !11, i64 32}
!14 = !{!"core_commands", !11, i64 0, !11, i64 4, !15, i64 8, !6, i64 56}
!15 = !{!"command", !16, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !6, i64 40}
!16 = !{!"strbuf", !17, i64 0, !17, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!14, !11, i64 4}
!19 = !{!14, !11, i64 0}
!20 = !{!14, !6, i64 56}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass