; LLVM IR from libtcod/libtcod :: src/libtcod (lex_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_lex_t = type { i32, i32, i32, i32, float, ptr, i32, i8, ptr, ptr, ptr, ptr, i32, i32, i32, [100 x [5 x i8]], [100 x [20 x i8]], ptr, ptr, ptr, ptr, ptr, i8, i8, i8 }

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 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

declare i32 @TCOD_set_errorf(ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
declare hidden void @allocate_tok(ptr noundef, i32 noundef) #2

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

7:                                                ; preds = %73, %1
  call void @llvm.lifetime.start.p0(i64 1, ptr %5) #3
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TCOD_lex_t, ptr %8, i32 0, i32 8
  %10 = load ptr, ptr %9, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %10, i32 1
  store ptr %11, ptr %9, align 8, !tbaa !11
  %12 = load i8, ptr %11, align 1, !tbaa !15
  store i8 %12, ptr %5, align 1, !tbaa !15
  %13 = load i8, ptr %5, align 1, !tbaa !15
  %14 = sext i8 %13 to i32
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %18

16:                                               ; preds = %7
  %17 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 362, ptr noundef @.str.10)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %70

18:                                               ; preds = %7
  %19 = load i8, ptr %5, align 1, !tbaa !15
  %20 = sext i8 %19 to i32
  %21 = icmp eq i32 %20, 10
  br i1 %21, label %22, label %24

22:                                               ; preds = %18
  %23 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 366, ptr noundef @.str.11)
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %70

24:                                               ; preds = %18
  %25 = load i8, ptr %5, align 1, !tbaa !15
  %26 = sext i8 %25 to i32
  %27 = icmp eq i32 %26, 92
  br i1 %27, label %28, label %33

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = call zeroext i1 @TCOD_lex_get_special_char(ptr noundef %29, ptr noundef %5)
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %70

32:                                               ; preds = %28
  br label %59

33:                                               ; preds = %24
  %34 = load i8, ptr %5, align 1, !tbaa !15
  %35 = sext i8 %34 to i32
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.TCOD_lex_t, ptr %36, i32 0, i32 7
  %38 = load i8, ptr %37, align 4, !tbaa !16
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 %35, %39
  br i1 %40, label %41, label %58

41:                                               ; preds = %33
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = load i32, ptr %4, align 4, !tbaa !9
  call void @allocate_tok(ptr noundef %42, i32 noundef %43)
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TCOD_lex_t, ptr %44, i32 0, i32 5
  %46 = load ptr, ptr %45, align 8, !tbaa !17
  %47 = load i32, ptr %4, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %46, i64 %48
  store i8 0, ptr %49, align 1, !tbaa !15
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TCOD_lex_t, ptr %50, i32 0, i32 1
  store i32 4, ptr %51, align 4, !tbaa !18
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.TCOD_lex_t, ptr %52, i32 0, i32 3
  store i32 -1, ptr %53, align 4, !tbaa !19
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.TCOD_lex_t, ptr %54, i32 0, i32 8
  %56 = load ptr, ptr %55, align 8, !tbaa !11
  %57 = getelementptr inbounds i8, ptr %56, i32 1
  store ptr %57, ptr %55, align 8, !tbaa !11
  store i32 4, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %70

58:                                               ; preds = %33
  br label %59

59:                                               ; preds = %58, %32
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = load i32, ptr %4, align 4, !tbaa !9
  call void @allocate_tok(ptr noundef %60, i32 noundef %61)
  %62 = load i8, ptr %5, align 1, !tbaa !15
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.TCOD_lex_t, ptr %63, i32 0, i32 5
  %65 = load ptr, ptr %64, align 8, !tbaa !17
  %66 = load i32, ptr %4, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %4, align 4, !tbaa !9
  %68 = sext i32 %66 to i64
  %69 = getelementptr inbounds i8, ptr %65, i64 %68
  store i8 %62, ptr %69, align 1, !tbaa !15
  store i32 0, ptr %6, align 4
  br label %70

70:                                               ; preds = %59, %41, %31, %22, %16
  call void @llvm.lifetime.end.p0(i64 1, ptr %5) #3
  %71 = load i32, ptr %6, align 4
  switch i32 %71, label %75 [
    i32 0, label %72
  ]

72:                                               ; preds = %70
  br label %73

73:                                               ; preds = %72
  br i1 true, label %7, label %74

74:                                               ; preds = %73
  store i32 0, ptr %6, align 4
  br label %75

75:                                               ; preds = %74, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  %76 = load i32, ptr %6, align 4
  switch i32 %76, label %79 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  %78 = load i32, ptr %2, align 4
  ret i32 %78

79:                                               ; preds = %75
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @TCOD_lex_get_special_char(ptr noundef, ptr noundef) #2

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 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"TCOD_lex_t", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !13, i64 16, !6, i64 24, !10, i64 32, !7, i64 36, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !10, i64 76, !10, i64 80, !7, i64 84, !7, i64 584, !6, i64 2584, !6, i64 2592, !6, i64 2600, !6, i64 2608, !6, i64 2616, !14, i64 2624, !14, i64 2625, !14, i64 2626}
!13 = !{!"float", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !7, i64 36}
!17 = !{!12, !6, i64 24}
!18 = !{!12, !10, i64 4}
!19 = !{!12, !10, 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"

@.str = external hidden unnamed_addr constant [9 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [83 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [17 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [21 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

declare i32 @TCOD_set_errorf(ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @allocate_tok(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @TCOD_lex_get_string(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca i8, align 1
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = getelementptr inbounds i8, ptr %0, i64 36
  %5 = getelementptr inbounds i8, ptr %0, i64 24
  br label %6

6:                                                ; preds = %28, %1
  %indvars.iv = phi i64 [ %indvars.iv.next, %28 ], [ 0, %1 ]
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %2) #3
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 1
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = load i8, ptr %8, align 1, !tbaa !13
  store i8 %9, ptr %2, align 1, !tbaa !13
  switch i8 %9, label %16 [
    i8 0, label %10
    i8 10, label %12
    i8 92, label %14
  ]

10:                                               ; preds = %6
  %11 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 362, ptr noundef nonnull @.str.10) #3
  br label %.loopexit

12:                                               ; preds = %6
  %13 = call i32 (ptr, ...) @TCOD_set_errorf(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 366, ptr noundef nonnull @.str.11) #3
  br label %.loopexit

14:                                               ; preds = %6
  %15 = call zeroext i1 @TCOD_lex_get_special_char(ptr noundef nonnull %0, ptr noundef nonnull %2)
  br i1 %15, label %28, label %.loopexit

16:                                               ; preds = %6
  %17 = load i8, ptr %4, align 4, !tbaa !14
  %18 = icmp eq i8 %9, %17
  br i1 %18, label %19, label %28

19:                                               ; preds = %16
  %20 = trunc nuw nsw i64 %indvars.iv to i32
  call void @allocate_tok(ptr noundef nonnull %0, i32 noundef %20)
  %21 = load ptr, ptr %5, align 8, !tbaa !15
  %22 = and i64 %indvars.iv, 4294967295
  %23 = getelementptr inbounds i8, ptr %21, i64 %22
  store i8 0, ptr %23, align 1, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 4, ptr %24, align 4, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 -1, ptr %25, align 4, !tbaa !17
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %26, i64 1
  store ptr %27, ptr %3, align 8, !tbaa !5
  br label %.loopexit

28:                                               ; preds = %14, %16
  %29 = trunc nuw nsw i64 %indvars.iv to i32
  call void @allocate_tok(ptr noundef nonnull %0, i32 noundef %29)
  %30 = load i8, ptr %2, align 1, !tbaa !13
  %31 = load ptr, ptr %5, align 8, !tbaa !15
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = getelementptr inbounds i8, ptr %31, i64 %indvars.iv
  store i8 %30, ptr %32, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  br label %6

.loopexit:                                        ; preds = %14, %10, %12, %19
  %.117.ph = phi i32 [ 4, %19 ], [ -1, %12 ], [ -1, %10 ], [ -1, %14 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %2) #3
  ret i32 %.117.ph
}

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @TCOD_lex_get_special_char(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 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, !11, i64 40}
!6 = !{!"TCOD_lex_t", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !10, i64 16, !11, i64 24, !7, i64 32, !8, i64 36, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !7, i64 72, !7, i64 76, !7, i64 80, !8, i64 84, !8, i64 584, !11, i64 2584, !11, i64 2592, !11, i64 2600, !11, i64 2608, !11, i64 2616, !12, i64 2624, !12, i64 2625, !12, i64 2626}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"float", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!6, !8, i64 36}
!15 = !{!6, !11, i64 24}
!16 = !{!6, !7, i64 4}
!17 = !{!6, !7, i64 12}


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