; LLVM IR from libtcod/libtcod :: src/libtcod (mersenne_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_dice_t = type { i32, i32, float, float }

@__const.TCOD_random_dice_new.dice = external hidden unnamed_addr constant %struct.TCOD_dice_t, align 4
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nounwind uwtable
define dso_local { i64, <2 x float> } @TCOD_random_dice_new(ptr noundef %0) #2 {
  %2 = alloca %struct.TCOD_dice_t, align 4
  %3 = alloca ptr, align 8
  %4 = alloca [128 x i8], align 16
  %5 = alloca i64, align 8
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %2, ptr align 4 @__const.TCOD_random_dice_new.dice, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 128, ptr %4) #7
  call void @llvm.memset.p0.i64(ptr align 16 %4, i8 0, i64 128, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = call i64 @strcspn(ptr noundef %7, ptr noundef @.str.2) #8
  store i64 %8, ptr %5, align 8, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i64 @strlen(ptr noundef %9) #8
  %11 = icmp ult i64 %8, %10
  br i1 %11, label %12, label %26

12:                                               ; preds = %1
  %13 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call ptr @strncpy(ptr noundef %13, ptr noundef %14, i64 noundef 127) #7
  %16 = load i64, ptr %5, align 8, !tbaa !9
  %17 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 %16
  store i8 0, ptr %17, align 1, !tbaa !11
  %18 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %19 = call double @atof(ptr noundef %18) #8
  %20 = fptrunc double %19 to float
  %21 = getelementptr inbounds %struct.TCOD_dice_t, ptr %2, i32 0, i32 2
  store float %20, ptr %21, align 4, !tbaa !12
  %22 = load i64, ptr %5, align 8, !tbaa !9
  %23 = add i64 %22, 1
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i64 %23
  store ptr %25, ptr %3, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %12, %1
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i64 @strcspn(ptr noundef %27, ptr noundef @.str.3) #8
  store i64 %28, ptr %5, align 8, !tbaa !9
  %29 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = call ptr @strncpy(ptr noundef %29, ptr noundef %30, i64 noundef 127) #7
  %32 = load i64, ptr %5, align 8, !tbaa !9
  %33 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 %32
  store i8 0, ptr %33, align 1, !tbaa !11
  %34 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %35 = call i32 @atoi(ptr noundef %34) #8
  %36 = getelementptr inbounds %struct.TCOD_dice_t, ptr %2, i32 0, i32 0
  store i32 %35, ptr %36, align 4, !tbaa !16
  %37 = load i64, ptr %5, align 8, !tbaa !9
  %38 = add i64 %37, 1
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i64 %38
  store ptr %40, ptr %3, align 8, !tbaa !5
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = call i64 @strcspn(ptr noundef %41, ptr noundef @.str.4) #8
  store i64 %42, ptr %5, align 8, !tbaa !9
  %43 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call ptr @strncpy(ptr noundef %43, ptr noundef %44, i64 noundef 127) #7
  %46 = load i64, ptr %5, align 8, !tbaa !9
  %47 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 %46
  store i8 0, ptr %47, align 1, !tbaa !11
  %48 = getelementptr inbounds [128 x i8], ptr %4, i64 0, i64 0
  %49 = call i32 @atoi(ptr noundef %48) #8
  %50 = getelementptr inbounds %struct.TCOD_dice_t, ptr %2, i32 0, i32 1
  store i32 %49, ptr %50, align 4, !tbaa !17
  %51 = load i64, ptr %5, align 8, !tbaa !9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 %51
  store ptr %53, ptr %3, align 8, !tbaa !5
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call i64 @strlen(ptr noundef %54) #8
  %56 = icmp ugt i64 %55, 0
  br i1 %56, label %57, label %73

57:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load i8, ptr %58, align 1, !tbaa !11
  %60 = sext i8 %59 to i32
  %61 = icmp eq i32 %60, 43
  %62 = zext i1 %61 to i64
  %63 = select i1 %61, i32 1, i32 -1
  store i32 %63, ptr %6, align 4, !tbaa !18
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i32 1
  store ptr %65, ptr %3, align 8, !tbaa !5
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = call double @atof(ptr noundef %66) #8
  %68 = load i32, ptr %6, align 4, !tbaa !18
  %69 = sitofp i32 %68 to double
  %70 = fmul double %67, %69
  %71 = fptrunc double %70 to float
  %72 = getelementptr inbounds %struct.TCOD_dice_t, ptr %2, i32 0, i32 3
  store float %71, ptr %72, align 4, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %73

73:                                               ; preds = %57, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 128, ptr %4) #7
  %74 = load { i64, <2 x float> }, ptr %2, align 4
  ret { i64, <2 x float> } %74
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strcspn(ptr noundef, ptr noundef) #4

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #5

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare double @atof(ptr noundef nonnull) #6

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr noundef nonnull) #6

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 #5 = { 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 #6 = { inlinehint nounwind willreturn memory(read) 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 #7 = { nounwind }
attributes #8 = { 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 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !15, i64 8}
!13 = !{!"", !14, i64 0, !14, i64 4, !15, i64 8, !15, i64 12}
!14 = !{!"int", !7, i64 0}
!15 = !{!"float", !7, i64 0}
!16 = !{!13, !14, i64 0}
!17 = !{!13, !14, i64 4}
!18 = !{!14, !14, i64 0}
!19 = !{!13, !15, i64 12}


; 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_dice_t = type { i32, i32, float, float }

@__const.TCOD_random_dice_new.dice = external hidden unnamed_addr constant %struct.TCOD_dice_t, align 4
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: read) uwtable
define dso_local { i64, <2 x float> } @TCOD_random_dice_new(ptr nocapture noundef readonly %0) local_unnamed_addr #1 {
  %2 = alloca [128 x i8], align 16
  %.sroa.4.0.copyload = load <2 x float>, ptr getelementptr inbounds (i8, ptr @__const.TCOD_random_dice_new.dice, i64 8), align 4
  call void @llvm.lifetime.start.p0(i64 128, ptr nonnull %2) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(128) %2, i8 0, i64 128, i1 false)
  %3 = tail call i64 @strcspn(ptr noundef %0, ptr noundef nonnull @.str.2) #7
  %4 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #7
  %5 = icmp ult i64 %3, %4
  br i1 %5, label %6, label %13

6:                                                ; preds = %1
  %7 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 127) #6
  %8 = getelementptr inbounds [128 x i8], ptr %2, i64 0, i64 %3
  store i8 0, ptr %8, align 1, !tbaa !5
  %9 = call double @atof(ptr noundef %2) #7
  %10 = fptrunc double %9 to float
  %.sroa.4.8.vec.insert = insertelement <2 x float> %.sroa.4.0.copyload, float %10, i64 0
  %11 = getelementptr i8, ptr %0, i64 %3
  %12 = getelementptr i8, ptr %11, i64 1
  br label %13

13:                                               ; preds = %6, %1
  %.sroa.4.0 = phi <2 x float> [ %.sroa.4.8.vec.insert, %6 ], [ %.sroa.4.0.copyload, %1 ]
  %.0 = phi ptr [ %12, %6 ], [ %0, %1 ]
  %14 = call i64 @strcspn(ptr noundef %.0, ptr noundef nonnull @.str.3) #7
  %15 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %.0, i64 noundef 127) #6
  %16 = getelementptr inbounds [128 x i8], ptr %2, i64 0, i64 %14
  store i8 0, ptr %16, align 1, !tbaa !5
  %17 = call i32 @atoi(ptr nocapture noundef %2) #7
  %18 = add i64 %14, 1
  %19 = getelementptr inbounds i8, ptr %.0, i64 %18
  %20 = call i64 @strcspn(ptr noundef %19, ptr noundef nonnull @.str.4) #7
  %21 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) %19, i64 noundef 127) #6
  %22 = getelementptr inbounds [128 x i8], ptr %2, i64 0, i64 %20
  store i8 0, ptr %22, align 1, !tbaa !5
  %23 = call i32 @atoi(ptr nocapture noundef %2) #7
  %24 = getelementptr inbounds i8, ptr %19, i64 %20
  %char0 = load i8, ptr %24, align 1
  %.not = icmp eq i8 %char0, 0
  br i1 %.not, label %32, label %25

25:                                               ; preds = %13
  %26 = icmp eq i8 %char0, 43
  %27 = getelementptr inbounds i8, ptr %24, i64 1
  %28 = call double @atof(ptr noundef %27) #7
  %29 = fneg double %28
  %30 = select i1 %26, double %28, double %29
  %31 = fptrunc double %30 to float
  %.sroa.4.12.vec.insert = insertelement <2 x float> %.sroa.4.0, float %31, i64 1
  br label %32

32:                                               ; preds = %25, %13
  %.sroa.4.1 = phi <2 x float> [ %.sroa.4.12.vec.insert, %25 ], [ %.sroa.4.0, %13 ]
  call void @llvm.lifetime.end.p0(i64 128, ptr nonnull %2) #6
  %.sroa.0.sroa.3.0.insert.ext = zext i32 %23 to i64
  %.sroa.0.sroa.3.0.insert.shift = shl nuw i64 %.sroa.0.sroa.3.0.insert.ext, 32
  %.sroa.0.sroa.0.0.insert.ext = zext i32 %17 to i64
  %.sroa.0.sroa.0.0.insert.insert = or disjoint i64 %.sroa.0.sroa.3.0.insert.shift, %.sroa.0.sroa.0.0.insert.ext
  %.fca.0.insert = insertvalue { i64, <2 x float> } poison, i64 %.sroa.0.sroa.0.0.insert.insert, 0
  %.fca.1.insert = insertvalue { i64, <2 x float> } %.fca.0.insert, <2 x float> %.sroa.4.1, 1
  ret { i64, <2 x float> } %.fca.1.insert
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strcspn(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #4

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare double @atof(ptr nocapture noundef nonnull) local_unnamed_addr #5

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare i32 @atoi(ptr nocapture noundef nonnull) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(readwrite, inaccessiblemem: read) 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #6 = { nounwind }
attributes #7 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass