; LLVM IR from freakout42/macrocalc :: mc/src (wksrecd)

; 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.Lotrec = type { i16, i16, %union.anon }
%union.anon = type <{ %struct.anon.4, [2039 x i8] }>
%struct.anon.4 = type { [16 x i8], %struct.CELLADR123, %struct.CELLADR123 }
%struct.CELLADR123 = type { i16, i16 }

@stdin = external global ptr, align 8
@.str = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @getwksrecord(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = load ptr, ptr @stdin, align 8, !tbaa !5
  %6 = call i64 @fread(ptr noundef %4, i64 noundef 2, i64 noundef 2, ptr noundef %5)
  %7 = trunc i64 %6 to i32
  store i32 %7, ptr %3, align 4, !tbaa !9
  %8 = load i32, ptr %3, align 4, !tbaa !9
  %9 = icmp ne i32 %8, 2
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  call void @fatal(i32 noundef 11, ptr noundef @.str)
  br label %11

11:                                               ; preds = %10, %1
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.Lotrec, ptr %12, i32 0, i32 1
  %14 = load i16, ptr %13, align 2, !tbaa !11
  %15 = icmp ne i16 %14, 0
  br i1 %15, label %16, label %30

16:                                               ; preds = %11
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Lotrec, ptr %17, i32 0, i32 2
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.Lotrec, ptr %19, i32 0, i32 1
  %21 = load i16, ptr %20, align 2, !tbaa !11
  %22 = sext i16 %21 to i64
  %23 = load ptr, ptr @stdin, align 8, !tbaa !5
  %24 = call i64 @fread(ptr noundef %18, i64 noundef %22, i64 noundef 1, ptr noundef %23)
  %25 = trunc i64 %24 to i32
  store i32 %25, ptr %3, align 4, !tbaa !9
  %26 = load i32, ptr %3, align 4, !tbaa !9
  %27 = icmp ne i32 %26, 1
  br i1 %27, label %28, label %29

28:                                               ; preds = %16
  call void @fatal(i32 noundef 11, ptr noundef @.str)
  br label %29

29:                                               ; preds = %28, %16
  br label %30

30:                                               ; preds = %29, %11
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.Lotrec, ptr %31, i32 0, i32 0
  %33 = load i16, ptr %32, align 2, !tbaa !14
  %34 = sext i16 %33 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 %34
}

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

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

declare void @fatal(i32 noundef, ptr noundef) #2

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

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 }

!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, !13, i64 2}
!12 = !{!"", !13, i64 0, !13, i64 2, !7, i64 4}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !13, i64 0}


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

@stdin = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [39 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 -32768, 32768) i32 @getwksrecord(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = load ptr, ptr @stdin, align 8, !tbaa !5
  %3 = tail call i64 @fread(ptr noundef %0, i64 noundef 2, i64 noundef 2, ptr noundef %2)
  %4 = and i64 %3, 4294967295
  %.not = icmp eq i64 %4, 2
  br i1 %.not, label %6, label %5

5:                                                ; preds = %1
  tail call void @fatal(i32 noundef 11, ptr noundef nonnull @.str) #3
  br label %6

6:                                                ; preds = %5, %1
  %7 = getelementptr inbounds i8, ptr %0, i64 2
  %8 = load i16, ptr %7, align 2, !tbaa !9
  %.not6 = icmp eq i16 %8, 0
  br i1 %.not6, label %16, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 4
  %11 = sext i16 %8 to i64
  %12 = load ptr, ptr @stdin, align 8, !tbaa !5
  %13 = tail call i64 @fread(ptr noundef nonnull %10, i64 noundef %11, i64 noundef 1, ptr noundef %12)
  %14 = and i64 %13, 4294967295
  %.not7 = icmp eq i64 %14, 1
  br i1 %.not7, label %16, label %15

15:                                               ; preds = %9
  tail call void @fatal(i32 noundef 11, ptr noundef nonnull @.str) #3
  br label %16

16:                                               ; preds = %9, %15, %6
  %17 = load i16, ptr %0, align 2, !tbaa !12
  %18 = sext i16 %17 to i32
  ret i32 %18
}

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

declare void @fatal(i32 noundef, ptr noundef) local_unnamed_addr #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 = { 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 = { "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, !11, i64 2}
!10 = !{!"", !11, i64 0, !11, i64 2, !7, i64 4}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 0}


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