; LLVM IR from Syrocco/Graphical-EDMD :: parser (write_frame)

; 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.Dump = type { ptr, ptr, i8, i32, ptr, i32, i32, i64, ptr, i32, [10 x [256 x i8]], [11 x ptr] }

@.str.45 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [64 x i8], align 1

declare i32 @printf(ptr noundef, ...) #0

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #2

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #0

declare i64 @ftell(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @write_frame(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.Dump, ptr %3, i32 0, i32 2
  %5 = load i8, ptr %4, align 8, !tbaa !9
  %6 = sext i8 %5 to i32
  %7 = icmp ne i32 %6, 119
  br i1 %7, label %8, label %10

8:                                                ; preds = %1
  %9 = call i32 (ptr, ...) @printf(ptr noundef @.str.45)
  call void @exit(i32 noundef 1) #4
  unreachable

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

15:                                               ; preds = %10
  br label %114

16:                                               ; preds = %10
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.Dump, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.Dump, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !15
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.Dump, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 4, !tbaa !16
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds i64, ptr %22, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !17
  %29 = call i32 @fseek(ptr noundef %19, i64 noundef %28, i32 noundef 0)
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Dump, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !18
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Dump, ptr %33, i32 0, i32 7
  %35 = load i64, ptr %34, align 8, !tbaa !13
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.Dump, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = call i64 @fwrite(ptr noundef %32, i64 noundef 1, i64 noundef %35, ptr noundef %38)
  %40 = trunc i64 %39 to i32
  %41 = sext i32 %40 to i64
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.Dump, ptr %42, i32 0, i32 7
  %44 = load i64, ptr %43, align 8, !tbaa !13
  %45 = icmp ne i64 %41, %44
  br i1 %45, label %46, label %48

46:                                               ; preds = %16
  %47 = call i32 (ptr, ...) @printf(ptr noundef @.str.46)
  br label %48

48:                                               ; preds = %46, %16
  %49 = load ptr, ptr %2, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.Dump, ptr %49, i32 0, i32 3
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %50, align 4, !tbaa !16
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.Dump, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !16
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.Dump, ptr %56, i32 0, i32 6
  store i32 %55, ptr %57, align 4, !tbaa !19
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.Dump, ptr %58, i32 0, i32 3
  %60 = load i32, ptr %59, align 4, !tbaa !16
  %61 = add nsw i32 %60, 1
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Dump, ptr %62, i32 0, i32 5
  %64 = load i32, ptr %63, align 8, !tbaa !20
  %65 = icmp sgt i32 %61, %64
  br i1 %65, label %66, label %93

66:                                               ; preds = %48
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.Dump, ptr %67, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !15
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.Dump, ptr %70, i32 0, i32 5
  %72 = load i32, ptr %71, align 8, !tbaa !20
  %73 = mul nsw i32 2, %72
  %74 = sext i32 %73 to i64
  %75 = mul i64 %74, 8
  %76 = call ptr @realloc(ptr noundef %69, i64 noundef %75) #5
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.Dump, ptr %77, i32 0, i32 4
  store ptr %76, ptr %78, align 8, !tbaa !15
  %79 = load ptr, ptr %2, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.Dump, ptr %79, i32 0, i32 5
  %81 = load i32, ptr %80, align 8, !tbaa !20
  %82 = mul nsw i32 %81, 2
  store i32 %82, ptr %80, align 8, !tbaa !20
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.Dump, ptr %83, i32 0, i32 4
  %85 = load ptr, ptr %84, align 8, !tbaa !15
  %86 = icmp eq ptr %85, null
  br i1 %86, label %87, label %92

87:                                               ; preds = %66
  %88 = load ptr, ptr %2, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.Dump, ptr %88, i32 0, i32 5
  %90 = load i32, ptr %89, align 8, !tbaa !20
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.47, i32 noundef %90)
  call void @exit(i32 noundef 1) #4
  unreachable

92:                                               ; preds = %66
  br label %93

93:                                               ; preds = %92, %48
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.Dump, ptr %94, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !14
  %97 = call i64 @ftell(ptr noundef %96)
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.Dump, ptr %98, i32 0, i32 4
  %100 = load ptr, ptr %99, align 8, !tbaa !15
  %101 = load ptr, ptr %2, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.Dump, ptr %101, i32 0, i32 3
  %103 = load i32, ptr %102, align 4, !tbaa !16
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds i64, ptr %100, i64 %104
  store i64 %97, ptr %105, align 8, !tbaa !17
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.Dump, ptr %106, i32 0, i32 8
  %108 = load ptr, ptr %107, align 8, !tbaa !18
  %109 = getelementptr inbounds i8, ptr %108, i64 0
  store i8 0, ptr %109, align 1, !tbaa !21
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.Dump, ptr %110, i32 0, i32 7
  store i64 0, ptr %111, align 8, !tbaa !13
  %112 = load ptr, ptr %2, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.Dump, ptr %112, i32 0, i32 9
  store i32 0, ptr %113, align 8, !tbaa !22
  br label %114

114:                                              ; preds = %93, %15
  ret void
}

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #0

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 = { noreturn 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 = { nounwind allocsize(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 #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 = { noreturn nounwind }
attributes #5 = { nounwind allocsize(1) }

!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, !7, i64 16}
!10 = !{!"Dump", !6, i64 0, !6, i64 8, !7, i64 16, !11, i64 20, !6, i64 24, !11, i64 32, !11, i64 36, !12, i64 40, !6, i64 48, !11, i64 56, !7, i64 60, !7, i64 2624}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !12, i64 40}
!14 = !{!10, !6, i64 8}
!15 = !{!10, !6, i64 24}
!16 = !{!10, !11, i64 20}
!17 = !{!12, !12, i64 0}
!18 = !{!10, !6, i64 48}
!19 = !{!10, !11, i64 36}
!20 = !{!10, !11, i64 32}
!21 = !{!7, !7, i64 0}
!22 = !{!10, !11, i64 56}


; 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.45 = external hidden unnamed_addr constant [50 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [92 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [64 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @write_frame(ptr nocapture noundef %0) local_unnamed_addr #3 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i8, ptr %2, align 8, !tbaa !5
  %.not = icmp eq i8 %3, 119
  br i1 %.not, label %6, label %4

4:                                                ; preds = %1
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.45)
  tail call void @exit(i32 noundef 1) #4
  unreachable

6:                                                ; preds = %1
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %58, label %10

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !13
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 20
  %16 = load i32, ptr %15, align 4, !tbaa !15
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i64, ptr %14, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !16
  %20 = tail call i32 @fseek(ptr noundef %12, i64 noundef %19, i32 noundef 0)
  %21 = getelementptr inbounds i8, ptr %0, i64 48
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  %23 = load i64, ptr %7, align 8, !tbaa !12
  %24 = load ptr, ptr %11, align 8, !tbaa !13
  %25 = tail call i64 @fwrite(ptr noundef %22, i64 noundef 1, i64 noundef %23, ptr noundef %24)
  %sext = shl i64 %25, 32
  %26 = ashr exact i64 %sext, 32
  %27 = load i64, ptr %7, align 8, !tbaa !12
  %.not26 = icmp eq i64 %26, %27
  br i1 %.not26, label %30, label %28

28:                                               ; preds = %10
  %29 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.46)
  br label %30

30:                                               ; preds = %28, %10
  %31 = load i32, ptr %15, align 4, !tbaa !15
  %32 = add nsw i32 %31, 1
  store i32 %32, ptr %15, align 4, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %32, ptr %33, align 4, !tbaa !18
  %34 = add nsw i32 %31, 2
  %35 = getelementptr inbounds i8, ptr %0, i64 32
  %36 = load i32, ptr %35, align 8, !tbaa !19
  %37 = icmp sgt i32 %34, %36
  br i1 %37, label %38, label %49

38:                                               ; preds = %30
  %39 = load ptr, ptr %13, align 8, !tbaa !14
  %40 = shl nsw i32 %36, 1
  %41 = sext i32 %40 to i64
  %42 = shl nsw i64 %41, 3
  %43 = tail call ptr @realloc(ptr noundef %39, i64 noundef %42) #5
  store ptr %43, ptr %13, align 8, !tbaa !14
  %44 = load i32, ptr %35, align 8, !tbaa !19
  %45 = shl nsw i32 %44, 1
  store i32 %45, ptr %35, align 8, !tbaa !19
  %46 = icmp eq ptr %43, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %38
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.47, i32 noundef %45)
  tail call void @exit(i32 noundef 1) #4
  unreachable

49:                                               ; preds = %38, %30
  %50 = load ptr, ptr %11, align 8, !tbaa !13
  %51 = tail call i64 @ftell(ptr noundef %50)
  %52 = load ptr, ptr %13, align 8, !tbaa !14
  %53 = load i32, ptr %15, align 4, !tbaa !15
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds i64, ptr %52, i64 %54
  store i64 %51, ptr %55, align 8, !tbaa !16
  %56 = load ptr, ptr %21, align 8, !tbaa !17
  store i8 0, ptr %56, align 1, !tbaa !20
  store i64 0, ptr %7, align 8, !tbaa !12
  %57 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 0, ptr %57, align 8, !tbaa !21
  br label %58

58:                                               ; preds = %6, %49
  ret void
}

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

attributes #0 = { 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 #1 = { noreturn 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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { noreturn nounwind }
attributes #5 = { nounwind allocsize(1) }

!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, !8, i64 16}
!6 = !{!"Dump", !7, i64 0, !7, i64 8, !8, i64 16, !10, i64 20, !7, i64 24, !10, i64 32, !10, i64 36, !11, i64 40, !7, i64 48, !10, i64 56, !8, i64 60, !8, i64 2624}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !11, i64 40}
!13 = !{!6, !7, i64 8}
!14 = !{!6, !7, i64 24}
!15 = !{!6, !10, i64 20}
!16 = !{!11, !11, i64 0}
!17 = !{!6, !7, i64 48}
!18 = !{!6, !10, i64 36}
!19 = !{!6, !10, i64 32}
!20 = !{!8, !8, i64 0}
!21 = !{!6, !10, i64 56}


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