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

@stderr = external global ptr, align 8
@.str.19 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [26 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 uwtable
declare dso_local zeroext i1 @namegen_generator_check(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @namegen_get_sets_on_error() #1

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #3

declare i32 @TCOD_list_size(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_namegen_generate_custom(ptr noundef, ptr noundef, i1 noundef zeroext) #1

declare i32 @TCOD_random_get_int(ptr noundef, i32 noundef, i32 noundef) #4

declare ptr @TCOD_list_get(ptr noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
define dso_local ptr @TCOD_namegen_generate(ptr noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca ptr, align 8
  %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
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  %13 = zext i1 %1 to i8
  store i8 %13, ptr %5, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call zeroext i1 @namegen_generator_check(ptr noundef %14)
  br i1 %15, label %16, label %19

16:                                               ; preds = %2
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = call ptr @namegen_generator_get(ptr noundef %17)
  store ptr %18, ptr %6, align 8, !tbaa !5
  br label %23

19:                                               ; preds = %2
  %20 = load ptr, ptr @stderr, align 8, !tbaa !5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %20, ptr noundef @.str.19, ptr noundef %21) #5
  call void @namegen_get_sets_on_error()
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %105

23:                                               ; preds = %16
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TCOD_NameGen, ptr %24, i32 0, i32 10
  %26 = load ptr, ptr %25, align 8, !tbaa !11
  %27 = call i32 @TCOD_list_size(ptr noundef %26)
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %32

29:                                               ; preds = %23
  %30 = load ptr, ptr @stderr, align 8, !tbaa !5
  %31 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %30, ptr noundef @.str.22) #5
  call void @exit(i32 noundef 1) #6
  unreachable

32:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  br label %33

33:                                               ; preds = %88, %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.TCOD_NameGen, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TCOD_NameGen, ptr %37, i32 0, i32 10
  %39 = load ptr, ptr %38, align 8, !tbaa !11
  %40 = call i32 @TCOD_list_size(ptr noundef %39)
  %41 = sub nsw i32 %40, 1
  %42 = call i32 @TCOD_random_get_int(ptr noundef %36, i32 noundef 0, i32 noundef %41)
  store i32 %42, ptr %11, align 4, !tbaa !14
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TCOD_NameGen, ptr %43, i32 0, i32 10
  %45 = load ptr, ptr %44, align 8, !tbaa !11
  %46 = load i32, ptr %11, align 4, !tbaa !14
  %47 = call ptr @TCOD_list_get(ptr noundef %45, i32 noundef %46)
  store ptr %47, ptr %9, align 8, !tbaa !5
  store i32 100, ptr %8, align 4, !tbaa !14
  store i32 0, ptr %10, align 4, !tbaa !14
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i64 0
  %50 = load i8, ptr %49, align 1, !tbaa !16
  %51 = sext i8 %50 to i32
  %52 = icmp eq i32 %51, 37
  br i1 %52, label %53, label %87

53:                                               ; preds = %33
  store i32 1, ptr %10, align 4, !tbaa !14
  store i32 0, ptr %8, align 4, !tbaa !14
  br label %54

54:                                               ; preds = %72, %53
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load i32, ptr %10, align 4, !tbaa !14
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds i8, ptr %55, i64 %57
  %59 = load i8, ptr %58, align 1, !tbaa !16
  %60 = sext i8 %59 to i32
  %61 = icmp sge i32 %60, 48
  br i1 %61, label %62, label %70

62:                                               ; preds = %54
  %63 = load ptr, ptr %9, align 8, !tbaa !5
  %64 = load i32, ptr %10, align 4, !tbaa !14
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %63, i64 %65
  %67 = load i8, ptr %66, align 1, !tbaa !16
  %68 = sext i8 %67 to i32
  %69 = icmp sle i32 %68, 57
  br label %70

70:                                               ; preds = %62, %54
  %71 = phi i1 [ false, %54 ], [ %69, %62 ]
  br i1 %71, label %72, label %86

72:                                               ; preds = %70
  %73 = load i32, ptr %8, align 4, !tbaa !14
  %74 = mul nsw i32 %73, 10
  store i32 %74, ptr %8, align 4, !tbaa !14
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = load i32, ptr %10, align 4, !tbaa !14
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds i8, ptr %75, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !16
  %80 = sext i8 %79 to i32
  %81 = sub nsw i32 %80, 48
  %82 = load i32, ptr %8, align 4, !tbaa !14
  %83 = add nsw i32 %82, %81
  store i32 %83, ptr %8, align 4, !tbaa !14
  %84 = load i32, ptr %10, align 4, !tbaa !14
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %10, align 4, !tbaa !14
  br label %54, !llvm.loop !17

86:                                               ; preds = %70
  br label %87

87:                                               ; preds = %86, %33
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %88

88:                                               ; preds = %87
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.TCOD_NameGen, ptr %89, i32 0, i32 1
  %91 = load ptr, ptr %90, align 8, !tbaa !13
  %92 = call i32 @TCOD_random_get_int(ptr noundef %91, i32 noundef 0, i32 noundef 100)
  %93 = load i32, ptr %8, align 4, !tbaa !14
  %94 = icmp sgt i32 %92, %93
  br i1 %94, label %33, label %95, !llvm.loop !19

95:                                               ; preds = %88
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %96 = load ptr, ptr %9, align 8, !tbaa !5
  %97 = load i32, ptr %10, align 4, !tbaa !14
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i8, ptr %96, i64 %98
  store ptr %99, ptr %12, align 8, !tbaa !5
  %100 = load ptr, ptr %4, align 8, !tbaa !5
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = load i8, ptr %5, align 1, !tbaa !9, !range !20, !noundef !21
  %103 = trunc i8 %102 to i1
  %104 = call ptr @TCOD_namegen_generate_custom(ptr noundef %100, ptr noundef %101, i1 noundef zeroext %103)
  store ptr %104, ptr %3, align 8
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %105

105:                                              ; preds = %95, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %106 = load ptr, ptr %3, align 8
  ret ptr %106
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { noreturn 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 #4 = { "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 #5 = { nounwind }
attributes #6 = { noreturn 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, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!12, !6, i64 80}
!12 = !{!"TCOD_NameGen", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"int", !7, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = !{i8 0, i8 2}
!21 = !{}


; 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.19 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [26 x i8], align 1

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

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

declare i32 @TCOD_list_size(ptr noundef) local_unnamed_addr #3

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

declare i32 @TCOD_random_get_int(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare ptr @TCOD_list_get(ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local ptr @TCOD_namegen_generate(ptr noundef %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = tail call zeroext i1 @namegen_generator_check(ptr noundef %0)
  br i1 %3, label %4, label %11

4:                                                ; preds = %2
  %5 = tail call ptr @namegen_generator_get(ptr noundef %0)
  %6 = getelementptr inbounds i8, ptr %5, i64 80
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call i32 @TCOD_list_size(ptr noundef %7) #4
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %14, label %.preheader29

.preheader29:                                     ; preds = %4
  %10 = getelementptr inbounds i8, ptr %5, i64 8
  br label %17

11:                                               ; preds = %2
  %12 = load ptr, ptr @stderr, align 8, !tbaa !10
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.19, ptr noundef %0) #5
  tail call void @namegen_get_sets_on_error()
  br label %44

14:                                               ; preds = %4
  %15 = load ptr, ptr @stderr, align 8, !tbaa !10
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.22) #5
  tail call void @exit(i32 noundef 1) #6
  unreachable

17:                                               ; preds = %.preheader29, %.critedge
  %18 = load ptr, ptr %10, align 8, !tbaa !11
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = tail call i32 @TCOD_list_size(ptr noundef %19) #4
  %21 = add nsw i32 %20, -1
  %22 = tail call i32 @TCOD_random_get_int(ptr noundef %18, i32 noundef 0, i32 noundef %21) #4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = tail call ptr @TCOD_list_get(ptr noundef %23, i32 noundef %22) #4
  %25 = load i8, ptr %24, align 1, !tbaa !12
  %26 = icmp eq i8 %25, 37
  br i1 %26, label %.preheader, label %.critedge

.preheader:                                       ; preds = %17
  %27 = getelementptr inbounds i8, ptr %24, i64 1
  %28 = load i8, ptr %27, align 1, !tbaa !12
  %29 = add i8 %28, -48
  %or.cond30 = icmp ult i8 %29, 10
  br i1 %or.cond30, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %.preheader ]
  %30 = phi i8 [ %35, %.lr.ph ], [ %28, %.preheader ]
  %.02631 = phi i32 [ %33, %.lr.ph ], [ 0, %.preheader ]
  %31 = mul nsw i32 %.02631, 10
  %narrow = add nsw i8 %30, -48
  %32 = zext nneg i8 %narrow to i32
  %33 = add nsw i32 %31, %32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %34 = getelementptr inbounds i8, ptr %24, i64 %indvars.iv.next
  %35 = load i8, ptr %34, align 1, !tbaa !12
  %36 = add i8 %35, -48
  %or.cond = icmp ult i8 %36, 10
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %.preheader, %17
  %.127 = phi i32 [ 100, %17 ], [ 0, %.preheader ], [ %33, %.lr.ph ]
  %.1 = phi i64 [ 0, %17 ], [ 1, %.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %37 = load ptr, ptr %10, align 8, !tbaa !11
  %38 = tail call i32 @TCOD_random_get_int(ptr noundef %37, i32 noundef 0, i32 noundef 100) #4
  %39 = icmp sgt i32 %38, %.127
  br i1 %39, label %17, label %40, !llvm.loop !15

40:                                               ; preds = %.critedge
  %41 = and i64 %.1, 4294967295
  %42 = getelementptr inbounds i8, ptr %24, i64 %41
  %43 = tail call ptr @TCOD_namegen_generate_custom(ptr noundef %0, ptr noundef nonnull %42, i1 noundef zeroext %1)
  br label %44

44:                                               ; preds = %40, %11
  %.0 = phi ptr [ %43, %40 ], [ null, %11 ]
  ret ptr %.0
}

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 = { noreturn 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 = { "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 = { cold nounwind }
attributes #6 = { noreturn 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 80}
!6 = !{!"TCOD_NameGen", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 8}
!12 = !{!8, !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass