; LLVM IR from jovanlanik/wip :: src (wip_mdl)

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

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 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: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #1

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

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

9:                                                ; preds = %50, %48, %1
  %10 = getelementptr inbounds [1024 x i8], ptr %5, i64 0, i64 0
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.msh_ply_file, ptr %11, i32 0, i32 5
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = call ptr @fgets(ptr noundef %10, i32 noundef 1024, ptr noundef %13)
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %51

16:                                               ; preds = %9
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1024, ptr %7) #5
  %19 = getelementptr inbounds [1024 x i8], ptr %5, i64 0, i64 0
  %20 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %21 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef %19, ptr noundef @.str, ptr noundef %20) #5
  %22 = icmp ne i32 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %16
  store i32 5, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %48

24:                                               ; preds = %16
  %25 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %26 = call i32 @strcmp(ptr noundef %25, ptr noundef @.str.1) #6
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 3, ptr %8, align 4
  br label %48

29:                                               ; preds = %24
  %30 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %31 = call i32 @strcmp(ptr noundef %30, ptr noundef @.str.2) #6
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 2, ptr %8, align 4
  br label %48, !llvm.loop !13

34:                                               ; preds = %29
  %35 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %36 = call i32 @strcmp(ptr noundef %35, ptr noundef @.str.3) #6
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 2, ptr %8, align 4
  br label %48, !llvm.loop !13

39:                                               ; preds = %34
  %40 = getelementptr inbounds [1024 x i8], ptr %7, i64 0, i64 0
  %41 = getelementptr inbounds [1024 x i8], ptr %5, i64 0, i64 0
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  %43 = call i32 @msh_ply__parse_command(ptr noundef %40, ptr noundef %41, ptr noundef %42)
  store i32 %43, ptr %6, align 4, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %47

46:                                               ; preds = %39
  store i32 3, ptr %8, align 4
  br label %48

47:                                               ; preds = %39
  store i32 0, ptr %8, align 4
  br label %48

48:                                               ; preds = %47, %46, %38, %33, %28, %23
  call void @llvm.lifetime.end.p0(i64 1024, ptr %7) #5
  %49 = load i32, ptr %8, align 4
  switch i32 %49, label %66 [
    i32 0, label %50
    i32 3, label %51
    i32 2, label %9
  ]

50:                                               ; preds = %48
  br label %9, !llvm.loop !13

51:                                               ; preds = %48, %9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.msh_ply_file, ptr %52, i32 0, i32 5
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  %55 = call i64 @ftell(ptr noundef %54)
  %56 = trunc i64 %55 to i32
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.msh_ply_file, ptr %57, i32 0, i32 6
  store i32 %56, ptr %58, align 8, !tbaa !15
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %64

61:                                               ; preds = %51
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.msh_ply_file, ptr %62, i32 0, i32 8
  store i32 1, ptr %63, align 8, !tbaa !16
  br label %64

64:                                               ; preds = %61, %51
  %65 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %65, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %66

66:                                               ; preds = %64, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 1024, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %67 = load i32, ptr %2, align 4
  ret i32 %67
}

declare ptr @fgets(ptr noundef, i32 noundef, ptr noundef) #3

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #4

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

declare i64 @ftell(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 "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 }
attributes #6 = { 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 32}
!12 = !{!"msh_ply_file", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!12, !10, i64 40}
!16 = !{!12, !10, i64 48}


; 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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [8 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [9 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 nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @msh_ply_parse_header(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca [1024 x i8], align 16
  %3 = alloca [1024 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %2) #4
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = call ptr @fgets(ptr noundef nonnull %2, i32 noundef 1024, ptr noundef %5)
  %.not30 = icmp eq ptr %6, null
  br i1 %.not30, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %1, %select.unfold
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %3) #4
  %7 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull %2, ptr noundef nonnull @.str, ptr noundef nonnull %3) #4
  %.not17 = icmp eq i32 %7, 1
  br i1 %.not17, label %8, label %.thread25

.thread25:                                        ; preds = %.lr.ph
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  br label %25

8:                                                ; preds = %.lr.ph
  %9 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.1) #5
  %.not18 = icmp eq i32 %9, 0
  br i1 %.not18, label %.thread, label %10

10:                                               ; preds = %8
  %11 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.2) #5
  %.not19 = icmp eq i32 %11, 0
  br i1 %.not19, label %select.unfold, label %12, !llvm.loop !11

12:                                               ; preds = %10
  %13 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.3) #5
  %.not20 = icmp eq i32 %13, 0
  br i1 %.not20, label %select.unfold, label %14, !llvm.loop !11

14:                                               ; preds = %12
  %15 = call i32 @msh_ply__parse_command(ptr noundef nonnull %3, ptr noundef nonnull %2, ptr noundef nonnull %0)
  %.not21 = icmp eq i32 %15, 0
  br i1 %.not21, label %select.unfold, label %.thread

.thread:                                          ; preds = %8, %14
  %.1.ph = phi i32 [ %15, %14 ], [ 0, %8 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  br label %.loopexit

select.unfold:                                    ; preds = %14, %12, %10
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %3) #4
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @fgets(ptr noundef nonnull %2, i32 noundef 1024, ptr noundef %16)
  %.not = icmp eq ptr %17, null
  br i1 %.not, label %.loopexit, label %.lr.ph

.loopexit:                                        ; preds = %select.unfold, %1, %.thread
  %.2 = phi i32 [ %.1.ph, %.thread ], [ 0, %1 ], [ 0, %select.unfold ]
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call i64 @ftell(ptr noundef %18)
  %20 = trunc i64 %19 to i32
  %21 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %20, ptr %21, align 8, !tbaa !13
  %22 = icmp eq i32 %.2, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %.loopexit
  %24 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 1, ptr %24, align 8, !tbaa !14
  br label %25

25:                                               ; preds = %.thread25, %.loopexit, %23
  %.214 = phi i32 [ 0, %23 ], [ %.2, %.loopexit ], [ 5, %.thread25 ]
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %2) #4
  ret i32 %.214
}

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

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

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

; Function Attrs: nofree nounwind
declare noundef i64 @ftell(ptr nocapture noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #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, !10, i64 32}
!6 = !{!"msh_ply_file", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !7, i64 40, !7, i64 44, !7, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!6, !7, i64 40}
!14 = !{!6, !7, i64 48}


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