; LLVM IR from 4LT/galines :: svg-writer (seqToSVG)

; 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.LineDef = type { i32, i32, i32, i32, i32 }
%struct.Sequence = type { i64, ptr }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@SVG_HEAD = external hidden global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@SVG_LINE = external hidden global ptr, align 8
@SVG_TAIL = external hidden global ptr, align 8

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @seqToSVG(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, float noundef %4) #0 {
  %6 = alloca i1, align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca float, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca i64, align 8
  %17 = alloca %struct.LineDef, align 4
  %18 = alloca float, align 4
  %19 = alloca float, align 4
  %20 = alloca float, align 4
  %21 = alloca float, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store float %4, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call noalias ptr @fopen(ptr noundef %22, ptr noundef @.str)
  store ptr %23, ptr %12, align 8, !tbaa !5
  %24 = load ptr, ptr %12, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %30

26:                                               ; preds = %5
  %27 = load ptr, ptr @stderr, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %27, ptr noundef @.str.1, ptr noundef %28) #5
  store i1 false, ptr %6, align 1
  store i32 1, ptr %13, align 4
  br label %113

30:                                               ; preds = %5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = load ptr, ptr @SVG_HEAD, align 8, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %31, ptr noundef %32, i32 noundef %33, i32 noundef %34) #5
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = load i32, ptr %9, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 1
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, i32 0, i32 1
  %43 = sub i32 %38, %42
  %44 = uitofp i32 %43 to float
  store float %44, ptr %14, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #5
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = icmp eq i32 %46, 1
  %48 = zext i1 %47 to i64
  %49 = select i1 %47, i32 0, i32 1
  %50 = sub i32 %45, %49
  %51 = uitofp i32 %50 to float
  store float %51, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  store i64 0, ptr %16, align 8, !tbaa !13
  br label %52

52:                                               ; preds = %102, %30
  %53 = load i64, ptr %16, align 8, !tbaa !13
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Sequence, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !15
  %57 = icmp ult i64 %53, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %52
  store i32 2, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  br label %105

59:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 20, ptr %17) #5
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.Sequence, ptr %60, i32 0, i32 1
  %62 = load ptr, ptr %61, align 8, !tbaa !17
  %63 = load i64, ptr %16, align 8, !tbaa !13
  %64 = getelementptr inbounds %struct.LineDef, ptr %62, i64 %63
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %17, ptr align 4 %64, i64 20, i1 false), !tbaa.struct !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %65 = getelementptr inbounds %struct.LineDef, ptr %17, i32 0, i32 0
  %66 = load i32, ptr %65, align 4, !tbaa !19
  %67 = mul nsw i32 100, %66
  %68 = sitofp i32 %67 to float
  %69 = load float, ptr %14, align 4, !tbaa !11
  %70 = fdiv float %68, %69
  store float %70, ptr %18, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  %71 = getelementptr inbounds %struct.LineDef, ptr %17, i32 0, i32 1
  %72 = load i32, ptr %71, align 4, !tbaa !21
  %73 = mul nsw i32 100, %72
  %74 = sitofp i32 %73 to float
  %75 = load float, ptr %15, align 4, !tbaa !11
  %76 = fdiv float %74, %75
  store float %76, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #5
  %77 = getelementptr inbounds %struct.LineDef, ptr %17, i32 0, i32 2
  %78 = load i32, ptr %77, align 4, !tbaa !22
  %79 = mul nsw i32 100, %78
  %80 = sitofp i32 %79 to float
  %81 = load float, ptr %14, align 4, !tbaa !11
  %82 = fdiv float %80, %81
  store float %82, ptr %20, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  %83 = getelementptr inbounds %struct.LineDef, ptr %17, i32 0, i32 3
  %84 = load i32, ptr %83, align 4, !tbaa !23
  %85 = mul nsw i32 100, %84
  %86 = sitofp i32 %85 to float
  %87 = load float, ptr %15, align 4, !tbaa !11
  %88 = fdiv float %86, %87
  store float %88, ptr %21, align 4, !tbaa !11
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = load ptr, ptr @SVG_LINE, align 8, !tbaa !5
  %91 = load float, ptr %18, align 4, !tbaa !11
  %92 = fpext float %91 to double
  %93 = load float, ptr %19, align 4, !tbaa !11
  %94 = fpext float %93 to double
  %95 = load float, ptr %20, align 4, !tbaa !11
  %96 = fpext float %95 to double
  %97 = load float, ptr %21, align 4, !tbaa !11
  %98 = fpext float %97 to double
  %99 = getelementptr inbounds %struct.LineDef, ptr %17, i32 0, i32 4
  %100 = load i32, ptr %99, align 4, !tbaa !24
  %101 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %89, ptr noundef %90, double noundef %92, double noundef %94, double noundef %96, double noundef %98, i32 noundef %100) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 20, ptr %17) #5
  br label %102

102:                                              ; preds = %59
  %103 = load i64, ptr %16, align 8, !tbaa !13
  %104 = add i64 %103, 1
  store i64 %104, ptr %16, align 8, !tbaa !13
  br label %52, !llvm.loop !25

105:                                              ; preds = %58
  %106 = load ptr, ptr %12, align 8, !tbaa !5
  %107 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %106, ptr noundef @.str.2) #5
  %108 = load ptr, ptr %12, align 8, !tbaa !5
  %109 = load ptr, ptr @SVG_TAIL, align 8, !tbaa !5
  %110 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %108, ptr noundef %109) #5
  %111 = load ptr, ptr %12, align 8, !tbaa !5
  %112 = call i32 @fclose(ptr noundef %111)
  store i1 true, ptr %6, align 1
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  br label %113

113:                                              ; preds = %105, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %114 = load i1, ptr %6, align 1
  ret i1 %114
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

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

; 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) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare i32 @fclose(ptr noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!16, !14, i64 0}
!16 = !{!"Sequence", !14, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 4, !9}
!19 = !{!20, !10, i64 0}
!20 = !{!"LineDef", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16}
!21 = !{!20, !10, i64 4}
!22 = !{!20, !10, i64 8}
!23 = !{!20, !10, i64 12}
!24 = !{!20, !10, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; 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.LineDef = type { i32, i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@SVG_HEAD = external hidden local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@SVG_LINE = external hidden local_unnamed_addr global ptr, align 8
@SVG_TAIL = external hidden local_unnamed_addr global ptr, align 8

; Function Attrs: nofree nounwind uwtable
define dso_local noundef zeroext i1 @seqToSVG(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, float noundef %4) local_unnamed_addr #0 {
  %6 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str)
  %7 = icmp ne ptr %6, null
  br i1 %7, label %11, label %8

8:                                                ; preds = %5
  %9 = load ptr, ptr @stderr, align 8, !tbaa !5
  %10 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %9, ptr noundef nonnull @.str.1, ptr noundef %1) #2
  br label %51

11:                                               ; preds = %5
  %12 = load ptr, ptr @SVG_HEAD, align 8, !tbaa !5
  %13 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %6, ptr noundef %12, i32 noundef %2, i32 noundef %3) #3
  %14 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %6, ptr noundef nonnull @.str.2) #3
  %15 = icmp ne i32 %2, 1
  %.neg = sext i1 %15 to i32
  %16 = add i32 %.neg, %2
  %17 = uitofp i32 %16 to float
  %18 = icmp ne i32 %3, 1
  %.neg30 = sext i1 %18 to i32
  %19 = add i32 %.neg30, %3
  %20 = uitofp i32 %19 to float
  %21 = load i64, ptr %0, align 8, !tbaa !9
  %.not = icmp eq i64 %21, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11
  %22 = getelementptr inbounds i8, ptr %0, i64 8
  br label %27

._crit_edge:                                      ; preds = %27, %11
  %23 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %6, ptr noundef nonnull @.str.2) #3
  %24 = load ptr, ptr @SVG_TAIL, align 8, !tbaa !5
  %25 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %6, ptr noundef %24) #3
  %26 = tail call i32 @fclose(ptr noundef nonnull %6)
  br label %51

27:                                               ; preds = %.lr.ph, %27
  %.02831 = phi i64 [ 0, %.lr.ph ], [ %48, %27 ]
  %28 = load ptr, ptr %22, align 8, !tbaa !12
  %29 = getelementptr inbounds %struct.LineDef, ptr %28, i64 %.02831
  %.sroa.0.0.copyload = load i32, ptr %29, align 4, !tbaa !13
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %29, i64 4
  %.sroa.4.0.copyload = load i32, ptr %.sroa.4.0..sroa_idx, align 4, !tbaa !13
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %29, i64 8
  %.sroa.5.0.copyload = load i32, ptr %.sroa.5.0..sroa_idx, align 4, !tbaa !13
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %29, i64 12
  %.sroa.6.0.copyload = load i32, ptr %.sroa.6.0..sroa_idx, align 4, !tbaa !13
  %.sroa.7.0..sroa_idx = getelementptr inbounds i8, ptr %29, i64 16
  %.sroa.7.0.copyload = load i32, ptr %.sroa.7.0..sroa_idx, align 4, !tbaa !13
  %30 = mul nsw i32 %.sroa.0.0.copyload, 100
  %31 = sitofp i32 %30 to float
  %32 = fdiv float %31, %17
  %33 = mul nsw i32 %.sroa.4.0.copyload, 100
  %34 = sitofp i32 %33 to float
  %35 = fdiv float %34, %20
  %36 = mul nsw i32 %.sroa.5.0.copyload, 100
  %37 = sitofp i32 %36 to float
  %38 = fdiv float %37, %17
  %39 = mul nsw i32 %.sroa.6.0.copyload, 100
  %40 = sitofp i32 %39 to float
  %41 = fdiv float %40, %20
  %42 = load ptr, ptr @SVG_LINE, align 8, !tbaa !5
  %43 = fpext float %32 to double
  %44 = fpext float %35 to double
  %45 = fpext float %38 to double
  %46 = fpext float %41 to double
  %47 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %6, ptr noundef %42, double noundef %43, double noundef %44, double noundef %45, double noundef %46, i32 noundef %.sroa.7.0.copyload) #3
  %48 = add nuw i64 %.02831, 1
  %49 = load i64, ptr %0, align 8, !tbaa !9
  %50 = icmp ult i64 %48, %49
  br i1 %50, label %27, label %._crit_edge, !llvm.loop !15

51:                                               ; preds = %._crit_edge, %8
  ret i1 %7
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) 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
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #1

attributes #0 = { 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 #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 = { cold nounwind }
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, !11, i64 0}
!10 = !{!"Sequence", !11, i64 0, !6, i64 8}
!11 = !{!"long", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass