; LLVM IR from libtcod/libtcod :: src/libtcod (namegen_c)

; 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.TCOD_parser_listener_t = type { ptr, ptr, ptr, ptr, ptr }

@parsed_files = external dso_local global ptr, align 8
@namegen_parser = external dso_local global ptr, align 8
@namegen_listener = external dso_local global %struct.TCOD_parser_listener_t, align 8

; 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

declare ptr @TCOD_list_new() #1

declare ptr @TCOD_list_begin(ptr noundef) #1

declare ptr @TCOD_list_end(ptr noundef) #1

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

declare void @TCOD_list_push(ptr noundef, ptr noundef) #1

declare ptr @TCOD_strdup(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @namegen_parser_prepare() #3

; Function Attrs: nounwind uwtable
define dso_local void @namegen_parser_run(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = 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 @namegen_parser_prepare()
  %5 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %6 = icmp eq ptr %5, null
  br i1 %6, label %7, label %9

7:                                                ; preds = %1
  %8 = call ptr @TCOD_list_new()
  store ptr %8, ptr @parsed_files, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %7, %1
  %10 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %11 = call i32 @TCOD_list_size(ptr noundef %10)
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %13, label %33

13:                                               ; preds = %9
  %14 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %15 = call ptr @TCOD_list_begin(ptr noundef %14)
  store ptr %15, ptr %3, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %29, %13
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %19 = call ptr @TCOD_list_end(ptr noundef %18)
  %20 = icmp ne ptr %17, %19
  br i1 %20, label %21, label %32

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = call i32 @strcmp(ptr noundef %23, ptr noundef %24) #5
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21
  store i32 1, ptr %4, align 4
  br label %39

28:                                               ; preds = %21
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds ptr, ptr %30, i32 1
  store ptr %31, ptr %3, align 8, !tbaa !5
  br label %16, !llvm.loop !9

32:                                               ; preds = %16
  br label %33

33:                                               ; preds = %32, %9
  %34 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = call ptr @TCOD_strdup(ptr noundef %35)
  call void @TCOD_list_push(ptr noundef %34, ptr noundef %36)
  %37 = load ptr, ptr @namegen_parser, align 8, !tbaa !5
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  call void @TCOD_parser_run(ptr noundef %37, ptr noundef %38, ptr noundef @namegen_listener)
  store i32 0, ptr %4, align 4
  br label %39

39:                                               ; preds = %33, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  %40 = load i32, ptr %4, align 4
  switch i32 %40, label %42 [
    i32 0, label %41
    i32 1, label %41
  ]

41:                                               ; preds = %39, %39
  ret void

42:                                               ; preds = %39
  unreachable
}

declare i32 @TCOD_list_size(ptr noundef) #1

declare void @TCOD_parser_run(ptr noundef, ptr noundef, ptr noundef) #1

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 = { nounwind willreturn memory(read) "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 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 willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"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.TCOD_parser_listener_t = type { ptr, ptr, ptr, ptr, ptr }

@parsed_files = external dso_local local_unnamed_addr global ptr, align 8
@namegen_parser = external dso_local local_unnamed_addr global ptr, align 8
@namegen_listener = external dso_local global %struct.TCOD_parser_listener_t, align 8

declare ptr @TCOD_list_new() local_unnamed_addr #0

declare ptr @TCOD_list_begin(ptr noundef) local_unnamed_addr #0

declare ptr @TCOD_list_end(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @TCOD_list_push(ptr noundef, ptr noundef) local_unnamed_addr #0

declare ptr @TCOD_strdup(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @namegen_parser_prepare() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @namegen_parser_run(ptr noundef %0) local_unnamed_addr #2 {
  tail call void @namegen_parser_prepare()
  %2 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %3 = icmp eq ptr %2, null
  br i1 %3, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call ptr @TCOD_list_new() #3
  store ptr %5, ptr @parsed_files, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %4, %1
  %7 = phi ptr [ %5, %4 ], [ %2, %1 ]
  %8 = tail call i32 @TCOD_list_size(ptr noundef %7) #3
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %10, label %.loopexit

10:                                               ; preds = %6
  %11 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %12 = tail call ptr @TCOD_list_begin(ptr noundef %11) #3
  %13 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %14 = tail call ptr @TCOD_list_end(ptr noundef %13) #3
  %.not7 = icmp eq ptr %12, %14
  br i1 %.not7, label %.loopexit, label %.lr.ph

15:                                               ; preds = %.lr.ph
  %16 = getelementptr inbounds i8, ptr %.08, i64 8
  %17 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %18 = tail call ptr @TCOD_list_end(ptr noundef %17) #3
  %.not = icmp eq ptr %16, %18
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !9

.lr.ph:                                           ; preds = %10, %15
  %.08 = phi ptr [ %16, %15 ], [ %12, %10 ]
  %19 = load ptr, ptr %.08, align 8, !tbaa !5
  %20 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %19, ptr noundef nonnull dereferenceable(1) %0) #4
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.loopexit6, label %15

.loopexit:                                        ; preds = %15, %10, %6
  %22 = load ptr, ptr @parsed_files, align 8, !tbaa !5
  %23 = tail call ptr @TCOD_strdup(ptr noundef %0) #3
  tail call void @TCOD_list_push(ptr noundef %22, ptr noundef %23) #3
  %24 = load ptr, ptr @namegen_parser, align 8, !tbaa !5
  tail call void @TCOD_parser_run(ptr noundef %24, ptr noundef %0, ptr noundef nonnull @namegen_listener) #3
  br label %.loopexit6

.loopexit6:                                       ; preds = %.lr.ph, %.loopexit
  ret void
}

declare i32 @TCOD_list_size(ptr noundef) local_unnamed_addr #0

declare void @TCOD_parser_run(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 nofree nounwind willreturn memory(argmem: read) "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 = { nounwind willreturn memory(read) }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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