; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl/tiny_opengl3_app.ll (ZN14TinyOpenGL3App20dump_frames_to_videoEPKc)

; 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.TinyCommonGraphicsApp = type <{ ptr, ptr, ptr, ptr, ptr, i8, i8, i8, i8, float, float, float, float, i8, [3 x i8], [3 x float], [4 x i8] }>
%struct.TinyOpenGL3App = type { %struct.TinyCommonGraphicsApp.base, ptr, ptr, ptr }
%struct.TinyCommonGraphicsApp.base = type <{ ptr, ptr, ptr, ptr, ptr, i8, i8, i8, i8, float, float, float, float, i8, [3 x i8], [3 x float] }>
%struct.TinyOpenGL3AppInternalData = type { i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32 }

@.str.15 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [2 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14TinyOpenGL3App20dump_frames_to_videoEPKc(ptr noundef nonnull align 8 dereferenceable(104) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [8192 x i8], align 16
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %8 = load ptr, ptr %3, align 8
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %74

11:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = getelementptr inbounds %struct.TinyCommonGraphicsApp, ptr %8, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = getelementptr inbounds ptr, ptr %14, i64 24
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef float %16(ptr noundef nonnull align 8 dereferenceable(8) %13)
  %18 = fptosi float %17 to i32
  %19 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 3
  %20 = load ptr, ptr %19, align 8, !tbaa !15
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = getelementptr inbounds ptr, ptr %21, i64 47
  %23 = load ptr, ptr %22, align 8
  %24 = call noundef i32 %23(ptr noundef nonnull align 8 dereferenceable(60) %20)
  %25 = mul nsw i32 %18, %24
  store i32 %25, ptr %5, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %26 = getelementptr inbounds %struct.TinyCommonGraphicsApp, ptr %8, i32 0, i32 1
  %27 = load ptr, ptr %26, align 8, !tbaa !9
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds ptr, ptr %28, i64 24
  %30 = load ptr, ptr %29, align 8
  %31 = call noundef float %30(ptr noundef nonnull align 8 dereferenceable(8) %27)
  %32 = fptosi float %31 to i32
  %33 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = load ptr, ptr %34, align 8, !tbaa !13
  %36 = getelementptr inbounds ptr, ptr %35, i64 48
  %37 = load ptr, ptr %36, align 8
  %38 = call noundef i32 %37(ptr noundef nonnull align 8 dereferenceable(60) %34)
  %39 = mul nsw i32 %32, %38
  store i32 %39, ptr %6, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8192, ptr %7) #4
  %40 = getelementptr inbounds [8192 x i8], ptr %7, i64 0, i64 0
  %41 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !19
  %43 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %42, i32 0, i32 16
  %44 = load i32, ptr %43, align 4, !tbaa !20
  %45 = load i32, ptr %5, align 4, !tbaa !17
  %46 = load i32, ptr %6, align 4, !tbaa !17
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %40, ptr noundef @.str.15, i32 noundef %44, i32 noundef %45, i32 noundef %46, ptr noundef %47) #4
  %49 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !19
  %51 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %50, i32 0, i32 10
  %52 = load ptr, ptr %51, align 8, !tbaa !22
  %53 = icmp ne ptr %52, null
  br i1 %53, label %54, label %60

54:                                               ; preds = %11
  %55 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !19
  %57 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %56, i32 0, i32 10
  %58 = load ptr, ptr %57, align 8, !tbaa !22
  %59 = call i32 @pclose(ptr noundef %58)
  br label %60

60:                                               ; preds = %54, %11
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %73

63:                                               ; preds = %60
  %64 = getelementptr inbounds [8192 x i8], ptr %7, i64 0, i64 0
  %65 = call noalias ptr @popen(ptr noundef %64, ptr noundef @.str.16)
  %66 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !19
  %68 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %67, i32 0, i32 10
  store ptr %65, ptr %68, align 8, !tbaa !22
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !19
  %72 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %71, i32 0, i32 9
  store ptr %69, ptr %72, align 8, !tbaa !23
  br label %73

73:                                               ; preds = %63, %60
  call void @llvm.lifetime.end.p0(i64 8192, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %98

74:                                               ; preds = %2
  %75 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !19
  %77 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %76, i32 0, i32 10
  %78 = load ptr, ptr %77, align 8, !tbaa !22
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %94

80:                                               ; preds = %74
  %81 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %82 = load ptr, ptr %81, align 8, !tbaa !19
  %83 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %82, i32 0, i32 10
  %84 = load ptr, ptr %83, align 8, !tbaa !22
  %85 = call i32 @fflush(ptr noundef %84)
  %86 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %87 = load ptr, ptr %86, align 8, !tbaa !19
  %88 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %87, i32 0, i32 10
  %89 = load ptr, ptr %88, align 8, !tbaa !22
  %90 = call i32 @pclose(ptr noundef %89)
  %91 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %92 = load ptr, ptr %91, align 8, !tbaa !19
  %93 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %92, i32 0, i32 9
  store ptr null, ptr %93, align 8, !tbaa !23
  br label %94

94:                                               ; preds = %80, %74
  %95 = getelementptr inbounds %struct.TinyOpenGL3App, ptr %8, i32 0, i32 1
  %96 = load ptr, ptr %95, align 8, !tbaa !19
  %97 = getelementptr inbounds %struct.TinyOpenGL3AppInternalData, ptr %96, i32 0, i32 10
  store ptr null, ptr %97, align 8, !tbaa !22
  br label %98

98:                                               ; preds = %94, %73
  ret void
}

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

declare i32 @pclose(ptr noundef) #3

declare noalias ptr @popen(ptr noundef, ptr noundef) #3

declare i32 @fflush(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #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 = { "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 }

!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++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"_ZTS21TinyCommonGraphicsApp", !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !11, i64 40, !11, i64 41, !11, i64 42, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !11, i64 60, !7, i64 64}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"vtable pointer", !8, i64 0}
!15 = !{!16, !6, i64 96}
!16 = !{!"_ZTS14TinyOpenGL3App", !10, i64 0, !6, i64 80, !6, i64 88, !6, i64 96}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = !{!16, !6, i64 80}
!20 = !{!21, !18, i64 100}
!21 = !{!"_ZTS26TinyOpenGL3AppInternalData", !18, i64 0, !18, i64 4, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !18, i64 40, !18, i64 44, !18, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !18, i64 88, !18, i64 92, !18, i64 96, !18, i64 100}
!22 = !{!21, !6, i64 64}
!23 = !{!21, !6, 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.15 = external hidden unnamed_addr constant [151 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [2 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN14TinyOpenGL3App20dump_frames_to_videoEPKc(ptr nocapture noundef nonnull readonly align 8 dereferenceable(104) %0, ptr noundef %1) unnamed_addr #1 align 2 {
  %3 = alloca [8192 x i8], align 16
  %.not = icmp eq ptr %1, null
  br i1 %.not, label %46, label %4

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %7, i64 192
  %9 = load ptr, ptr %8, align 8
  %10 = tail call noundef float %9(ptr noundef nonnull align 8 dereferenceable(8) %6)
  %11 = fptosi float %10 to i32
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  %13 = load ptr, ptr %12, align 8, !tbaa !14
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %14, i64 376
  %16 = load ptr, ptr %15, align 8
  %17 = tail call noundef i32 %16(ptr noundef nonnull align 8 dereferenceable(60) %13)
  %18 = mul nsw i32 %17, %11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %20, i64 192
  %22 = load ptr, ptr %21, align 8
  %23 = tail call noundef float %22(ptr noundef nonnull align 8 dereferenceable(8) %19)
  %24 = fptosi float %23 to i32
  %25 = load ptr, ptr %12, align 8, !tbaa !14
  %26 = load ptr, ptr %25, align 8, !tbaa !12
  %27 = getelementptr inbounds i8, ptr %26, i64 384
  %28 = load ptr, ptr %27, align 8
  %29 = tail call noundef i32 %28(ptr noundef nonnull align 8 dereferenceable(60) %25)
  %30 = mul nsw i32 %29, %24
  call void @llvm.lifetime.start.p0(i64 8192, ptr nonnull %3) #3
  %31 = getelementptr inbounds i8, ptr %0, i64 80
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds i8, ptr %32, i64 100
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %3, ptr noundef nonnull dereferenceable(1) @.str.15, i32 noundef %34, i32 noundef %18, i32 noundef %30, ptr noundef nonnull %1) #3
  %36 = load ptr, ptr %31, align 8, !tbaa !16
  %37 = getelementptr inbounds i8, ptr %36, i64 64
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %.not9 = icmp eq ptr %38, null
  br i1 %.not9, label %41, label %39

39:                                               ; preds = %4
  %40 = tail call i32 @pclose(ptr noundef nonnull %38)
  br label %41

41:                                               ; preds = %4, %39
  %42 = call noalias ptr @popen(ptr noundef nonnull %3, ptr noundef nonnull @.str.16)
  %43 = load ptr, ptr %31, align 8, !tbaa !16
  %44 = getelementptr inbounds i8, ptr %43, i64 64
  store ptr %42, ptr %44, align 8, !tbaa !20
  %45 = getelementptr inbounds i8, ptr %43, i64 56
  store ptr %1, ptr %45, align 8, !tbaa !21
  call void @llvm.lifetime.end.p0(i64 8192, ptr nonnull %3) #3
  br label %62

46:                                               ; preds = %2
  %47 = getelementptr inbounds i8, ptr %0, i64 80
  %48 = load ptr, ptr %47, align 8, !tbaa !16
  %49 = getelementptr inbounds i8, ptr %48, i64 64
  %50 = load ptr, ptr %49, align 8, !tbaa !20
  %.not8 = icmp eq ptr %50, null
  br i1 %.not8, label %59, label %51

51:                                               ; preds = %46
  %52 = tail call i32 @fflush(ptr noundef nonnull %50)
  %53 = load ptr, ptr %47, align 8, !tbaa !16
  %54 = getelementptr inbounds i8, ptr %53, i64 64
  %55 = load ptr, ptr %54, align 8, !tbaa !20
  %56 = tail call i32 @pclose(ptr noundef %55)
  %57 = load ptr, ptr %47, align 8, !tbaa !16
  %58 = getelementptr inbounds i8, ptr %57, i64 56
  store ptr null, ptr %58, align 8, !tbaa !21
  br label %59

59:                                               ; preds = %51, %46
  %60 = phi ptr [ %57, %51 ], [ %48, %46 ]
  %61 = getelementptr inbounds i8, ptr %60, i64 64
  store ptr null, ptr %61, align 8, !tbaa !20
  br label %62

62:                                               ; preds = %59, %41
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @pclose(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noalias noundef ptr @popen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fflush(ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { 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 #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, !7, i64 8}
!6 = !{!"_ZTS21TinyCommonGraphicsApp", !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 41, !10, i64 42, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !10, i64 60, !8, i64 64}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"float", !8, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"vtable pointer", !9, i64 0}
!14 = !{!15, !7, i64 96}
!15 = !{!"_ZTS14TinyOpenGL3App", !6, i64 0, !7, i64 80, !7, i64 88, !7, i64 96}
!16 = !{!15, !7, i64 80}
!17 = !{!18, !19, i64 100}
!18 = !{!"_ZTS26TinyOpenGL3AppInternalData", !19, i64 0, !19, i64 4, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !19, i64 40, !19, i64 44, !19, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !19, i64 88, !19, i64 92, !19, i64 96, !19, i64 100}
!19 = !{!"int", !8, i64 0}
!20 = !{!18, !7, i64 64}
!21 = !{!18, !7, i64 56}


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