; LLVM IR from libtcod/libtcod :: src/libtcod (parser_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_ParserStruct = type { ptr, ptr, ptr, ptr, ptr }
%struct.TCOD_struct_prop_t = type { ptr, i32, i8 }

; 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_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

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_struct_get_type(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.TCOD_ParserStruct, ptr %9, i32 0, i32 2
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = call ptr @TCOD_list_begin(ptr noundef %11)
  store ptr %12, ptr %6, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %35, %2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TCOD_ParserStruct, ptr %15, i32 0, i32 2
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = call ptr @TCOD_list_end(ptr noundef %17)
  %19 = icmp ne ptr %14, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %13
  store i32 2, ptr %7, align 4
  br label %38

21:                                               ; preds = %13
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TCOD_struct_prop_t, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @strcmp(ptr noundef %25, ptr noundef %26) #5
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %34

29:                                               ; preds = %21
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TCOD_struct_prop_t, ptr %31, i32 0, i32 1
  %33 = load i32, ptr %32, align 8, !tbaa !15
  store i32 %33, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %38

34:                                               ; preds = %21
  br label %35

35:                                               ; preds = %34
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds ptr, ptr %36, i32 1
  store ptr %37, ptr %6, align 8, !tbaa !5
  br label %13, !llvm.loop !16

38:                                               ; preds = %29, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %39 = load i32, ptr %7, align 4
  switch i32 %39, label %69 [
    i32 2, label %40
    i32 1, label %67
  ]

40:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.TCOD_ParserStruct, ptr %41, i32 0, i32 1
  %43 = load ptr, ptr %42, align 8, !tbaa !18
  %44 = call ptr @TCOD_list_begin(ptr noundef %43)
  store ptr %44, ptr %8, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %61, %40
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.TCOD_ParserStruct, ptr %47, i32 0, i32 1
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  %50 = call ptr @TCOD_list_end(ptr noundef %49)
  %51 = icmp ne ptr %46, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %45
  store i32 5, ptr %7, align 4
  br label %64

53:                                               ; preds = %45
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = call i32 @strcmp(ptr noundef %55, ptr noundef %56) #5
  %58 = icmp eq i32 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %53
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %64

60:                                               ; preds = %53
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds ptr, ptr %62, i32 1
  store ptr %63, ptr %8, align 8, !tbaa !5
  br label %45, !llvm.loop !19

64:                                               ; preds = %59, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %65 = load i32, ptr %7, align 4
  switch i32 %65, label %69 [
    i32 5, label %66
    i32 1, label %67
  ]

66:                                               ; preds = %64
  store i32 0, ptr %3, align 4
  br label %67

67:                                               ; preds = %66, %64, %38
  %68 = load i32, ptr %3, align 4
  ret i32 %68

69:                                               ; preds = %64, %38
  unreachable
}

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 = !{!10, !6, i64 16}
!10 = !{!"TCOD_ParserStruct", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32}
!11 = !{!12, !6, i64 0}
!12 = !{!"TCOD_struct_prop_t", !6, i64 0, !13, i64 8, !14, i64 12}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !13, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!10, !6, i64 8}
!19 = distinct !{!19, !17}


; 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"

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

; Function Attrs: nounwind uwtable
define dso_local i32 @TCOD_struct_get_type(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = tail call ptr @TCOD_list_begin(ptr noundef %4) #3
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = tail call ptr @TCOD_list_end(ptr noundef %6) #3
  %.not27 = icmp eq ptr %5, %7
  br i1 %.not27, label %._crit_edge, label %.lr.ph

8:                                                ; preds = %.lr.ph
  %9 = getelementptr inbounds i8, ptr %.01628, i64 8
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = tail call ptr @TCOD_list_end(ptr noundef %10) #3
  %.not = icmp eq ptr %9, %11
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

.lr.ph:                                           ; preds = %2, %8
  %.01628 = phi ptr [ %9, %8 ], [ %5, %2 ]
  %12 = load ptr, ptr %.01628, align 8, !tbaa !12
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %13, ptr noundef nonnull dereferenceable(1) %1) #4
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %8

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %12, i64 8
  %18 = load i32, ptr %17, align 8, !tbaa !17
  br label %._crit_edge34

._crit_edge:                                      ; preds = %8, %2
  %19 = getelementptr inbounds i8, ptr %0, i64 8
  %20 = load ptr, ptr %19, align 8, !tbaa !18
  %21 = tail call ptr @TCOD_list_begin(ptr noundef %20) #3
  %22 = load ptr, ptr %19, align 8, !tbaa !18
  %23 = tail call ptr @TCOD_list_end(ptr noundef %22) #3
  %.not1929.not = icmp eq ptr %21, %23
  br i1 %.not1929.not, label %._crit_edge34, label %.lr.ph33

24:                                               ; preds = %.lr.ph33
  %25 = getelementptr inbounds i8, ptr %.030, i64 8
  %26 = load ptr, ptr %19, align 8, !tbaa !18
  %27 = tail call ptr @TCOD_list_end(ptr noundef %26) #3
  %.not19.not = icmp eq ptr %25, %27
  br i1 %.not19.not, label %._crit_edge34.loopexit, label %.lr.ph33, !llvm.loop !19

.lr.ph33:                                         ; preds = %._crit_edge, %24
  %.030 = phi ptr [ %25, %24 ], [ %21, %._crit_edge ]
  %28 = load ptr, ptr %.030, align 8, !tbaa !12
  %29 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %28, ptr noundef nonnull dereferenceable(1) %1) #4
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %._crit_edge34.loopexit, label %24

._crit_edge34.loopexit:                           ; preds = %.lr.ph33, %24
  %31 = zext i1 %30 to i32
  br label %._crit_edge34

._crit_edge34:                                    ; preds = %._crit_edge, %._crit_edge34.loopexit, %16
  %.2 = phi i32 [ %18, %16 ], [ 0, %._crit_edge ], [ %31, %._crit_edge34.loopexit ]
  ret i32 %.2
}

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, !7, i64 16}
!6 = !{!"TCOD_ParserStruct", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"TCOD_struct_prop_t", !7, i64 0, !15, i64 8, !16, i64 12}
!15 = !{!"int", !8, i64 0}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{!14, !15, i64 8}
!18 = !{!6, !7, i64 8}
!19 = distinct !{!19, !11}


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