; LLVM IR from sylefeb/Silixel :: src/fstapi (fstapi)

; 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.fstWriterContext = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, ptr, ptr, i32, ptr, i32, i32, i32, i8, i64, i64, i32, i32, i64, i64, i32, i32, i32, i64, i32, double, ptr, ptr, i32, i64, i8, i8, i8, i8, i8, i64, i64, i64, i64, i64, i32, ptr, i32, i8, ptr, ptr, ptr, ptr, i32 }

@.str.11 = external hidden unnamed_addr constant [1 x i8], align 1
@.str.12 = external hidden unnamed_addr constant [9 x i8], align 1

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

declare i32 @fputc(i32 noundef, ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @fstWriterSetScope(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #3 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %71

11:                                               ; preds = %4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.fstWriterContext, ptr %12, i32 0, i32 1
  %14 = load ptr, ptr %13, align 8, !tbaa !11
  %15 = call i32 @fputc(i32 noundef 254, ptr noundef %14)
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = icmp ugt i32 %16, 21
  br i1 %17, label %18, label %19

18:                                               ; preds = %11
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %18, %11
  %20 = load i32, ptr %6, align 4, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.fstWriterContext, ptr %21, i32 0, i32 1
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = call i32 @fputc(i32 noundef %20, ptr noundef %23)
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.fstWriterContext, ptr %25, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %32

30:                                               ; preds = %19
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  br label %33

32:                                               ; preds = %19
  br label %33

33:                                               ; preds = %32, %30
  %34 = phi ptr [ %31, %30 ], [ @.str.11, %32 ]
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %39

37:                                               ; preds = %33
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  br label %40

39:                                               ; preds = %33
  br label %40

40:                                               ; preds = %39, %37
  %41 = phi ptr [ %38, %37 ], [ @.str.11, %39 ]
  %42 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.12, ptr noundef %34, i32 noundef 0, ptr noundef %41, i32 noundef 0) #4
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %45, label %52

45:                                               ; preds = %40
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = call i64 @strlen(ptr noundef %46) #5
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.fstWriterContext, ptr %48, i32 0, i32 7
  %50 = load i64, ptr %49, align 8, !tbaa !15
  %51 = add i64 %50, %47
  store i64 %51, ptr %49, align 8, !tbaa !15
  br label %52

52:                                               ; preds = %45, %40
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %62

55:                                               ; preds = %52
  %56 = load ptr, ptr %8, align 8, !tbaa !5
  %57 = call i64 @strlen(ptr noundef %56) #5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.fstWriterContext, ptr %58, i32 0, i32 7
  %60 = load i64, ptr %59, align 8, !tbaa !15
  %61 = add i64 %60, %57
  store i64 %61, ptr %59, align 8, !tbaa !15
  br label %62

62:                                               ; preds = %55, %52
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.fstWriterContext, ptr %63, i32 0, i32 7
  %65 = load i64, ptr %64, align 8, !tbaa !15
  %66 = add nsw i64 %65, 4
  store i64 %66, ptr %64, align 8, !tbaa !15
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.fstWriterContext, ptr %67, i32 0, i32 27
  %69 = load i32, ptr %68, align 8, !tbaa !16
  %70 = add i32 %69, 1
  store i32 %70, ptr %68, align 8, !tbaa !16
  br label %71

71:                                               ; preds = %62, %4
  ret void
}

attributes #0 = { 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 #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 "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"fstWriterContext", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !6, i64 96, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 116, !10, i64 116, !10, i64 116, !13, i64 120, !13, i64 128, !10, i64 136, !10, i64 140, !13, i64 144, !13, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !13, i64 176, !10, i64 184, !14, i64 192, !6, i64 200, !6, i64 208, !10, i64 216, !13, i64 224, !7, i64 232, !10, i64 233, !10, i64 233, !10, i64 233, !10, i64 233, !10, i64 233, !10, i64 233, !10, i64 233, !10, i64 233, !7, i64 234, !7, i64 235, !10, i64 236, !13, i64 240, !13, i64 248, !13, i64 256, !13, i64 264, !13, i64 272, !10, i64 280, !6, i64 288, !10, i64 296, !10, i64 300, !6, i64 304, !6, i64 312, !6, i64 320, !6, i64 328, !10, i64 336}
!13 = !{!"long", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!12, !13, i64 56}
!16 = !{!12, !10, i64 184}


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

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

; Function Attrs: nofree nounwind
declare noundef i32 @fputc(i32 noundef, ptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind uwtable
define dso_local void @fstWriterSetScope(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %34, label %5

5:                                                ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = tail call i32 @fputc(i32 noundef 254, ptr noundef %7)
  %9 = icmp ugt i32 %1, 21
  %spec.store.select = select i1 %9, i32 0, i32 %1
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = tail call i32 @fputc(i32 noundef %spec.store.select, ptr noundef %10)
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %.not19 = icmp eq ptr %2, null
  %13 = select i1 %.not19, ptr @.str.11, ptr %2
  %.not20 = icmp eq ptr %3, null
  %14 = select i1 %.not20, ptr @.str.11, ptr %3
  %15 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %12, ptr noundef nonnull @.str.12, ptr noundef nonnull %13, i32 noundef 0, ptr noundef nonnull %14, i32 noundef 0) #3
  br i1 %.not19, label %21, label %16

16:                                               ; preds = %5
  %17 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %2) #4
  %18 = getelementptr inbounds i8, ptr %0, i64 56
  %19 = load i64, ptr %18, align 8, !tbaa !13
  %20 = add i64 %19, %17
  store i64 %20, ptr %18, align 8, !tbaa !13
  br label %21

21:                                               ; preds = %16, %5
  br i1 %.not20, label %._crit_edge, label %22

._crit_edge:                                      ; preds = %21
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 56
  %.pre = load i64, ptr %.phi.trans.insert, align 8, !tbaa !13
  br label %27

22:                                               ; preds = %21
  %23 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #4
  %24 = getelementptr inbounds i8, ptr %0, i64 56
  %25 = load i64, ptr %24, align 8, !tbaa !13
  %26 = add i64 %25, %23
  br label %27

27:                                               ; preds = %._crit_edge, %22
  %28 = phi i64 [ %.pre, %._crit_edge ], [ %26, %22 ]
  %29 = getelementptr inbounds i8, ptr %0, i64 56
  %30 = add nsw i64 %28, 4
  store i64 %30, ptr %29, align 8, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %0, i64 184
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = add i32 %32, 1
  store i32 %33, ptr %31, align 8, !tbaa !14
  br label %34

34:                                               ; preds = %27, %4
  ret void
}

attributes #0 = { 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 #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 = { nofree 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 8}
!6 = !{!"fstWriterContext", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !11, i64 88, !7, i64 96, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 116, !11, i64 116, !11, i64 116, !10, i64 120, !10, i64 128, !11, i64 136, !11, i64 140, !10, i64 144, !10, i64 152, !11, i64 160, !11, i64 164, !11, i64 168, !10, i64 176, !11, i64 184, !12, i64 192, !7, i64 200, !7, i64 208, !11, i64 216, !10, i64 224, !8, i64 232, !11, i64 233, !11, i64 233, !11, i64 233, !11, i64 233, !11, i64 233, !11, i64 233, !11, i64 233, !11, i64 233, !8, i64 234, !8, i64 235, !11, i64 236, !10, i64 240, !10, i64 248, !10, i64 256, !10, i64 264, !10, i64 272, !11, i64 280, !7, i64 288, !11, i64 296, !11, i64 300, !7, i64 304, !7, i64 312, !7, i64 320, !7, i64 328, !11, i64 336}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!"double", !8, i64 0}
!13 = !{!6, !10, i64 56}
!14 = !{!6, !11, i64 184}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass