; LLVM IR from achilles288/robot-monitor-graphics :: src/base/internal/shader.ll (ZN3rmg8internal6Shader13compileShaderEjPKc)

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

@.str = external hidden unnamed_addr constant [55 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [97 x i8], align 1
@_ZN3rmg8internal14glCreateShaderE = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [58 x i8], align 1
@_ZN3rmg8internal14glShaderSourceE = external global ptr, align 8
@_ZN3rmg8internal15glCompileShaderE = external global ptr, align 8
@_ZN3rmg8internal13glGetShaderivE = external global ptr, align 8
@_ZN3rmg8internal18glGetShaderInfoLogE = external global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef %0, ptr noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca [65536 x i8], align 16
  %10 = alloca i32, align 4
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 35633
  br i1 %17, label %18, label %29

18:                                               ; preds = %2
  %19 = load i32, ptr %4, align 4, !tbaa !5
  %20 = icmp ne i32 %19, 35632
  br i1 %20, label %21, label %29

21:                                               ; preds = %18
  %22 = load i32, ptr %4, align 4, !tbaa !5
  %23 = icmp eq i32 %22, 35633
  br i1 %23, label %27, label %24

24:                                               ; preds = %21
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = icmp eq i32 %25, 35632
  br label %27

27:                                               ; preds = %24, %21
  %28 = phi i1 [ true, %21 ], [ %26, %24 ]
  call void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext %28, ptr noundef @.str, ptr noundef @.str.1, i32 noundef 47)
  store i32 0, ptr %3, align 4
  br label %95

29:                                               ; preds = %18, %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %30 = load ptr, ptr @_ZN3rmg8internal14glCreateShaderE, align 8, !tbaa !9
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = call noundef i32 %30(i32 noundef %31)
  store i32 %32, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %33 = load ptr, ptr %5, align 8, !tbaa !9
  %34 = call noalias ptr @fopen(ptr noundef %33, ptr noundef @.str.2)
  store ptr %34, ptr %7, align 8, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !9
  %36 = icmp eq ptr %35, null
  br i1 %36, label %37, label %40

37:                                               ; preds = %29
  %38 = load ptr, ptr %5, align 8, !tbaa !9
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %38)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %94

40:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 65536, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #5
  %41 = load ptr, ptr %7, align 8, !tbaa !9
  %42 = call i32 @getc(ptr noundef %41)
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %11, align 1, !tbaa !11
  br label %44

44:                                               ; preds = %53, %40
  %45 = load i8, ptr %11, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp ne i32 %46, -1
  br i1 %47, label %48, label %51

48:                                               ; preds = %44
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = icmp slt i32 %49, 65535
  br label %51

51:                                               ; preds = %48, %44
  %52 = phi i1 [ false, %44 ], [ %50, %48 ]
  br i1 %52, label %53, label %63

53:                                               ; preds = %51
  %54 = load i8, ptr %11, align 1, !tbaa !11
  %55 = load i32, ptr %10, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [65536 x i8], ptr %9, i64 0, i64 %56
  store i8 %54, ptr %57, align 1, !tbaa !11
  %58 = load ptr, ptr %7, align 8, !tbaa !9
  %59 = call i32 @getc(ptr noundef %58)
  %60 = trunc i32 %59 to i8
  store i8 %60, ptr %11, align 1, !tbaa !11
  %61 = load i32, ptr %10, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %10, align 4, !tbaa !5
  br label %44, !llvm.loop !12

63:                                               ; preds = %51
  %64 = load i32, ptr %10, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [65536 x i8], ptr %9, i64 0, i64 %65
  store i8 0, ptr %66, align 1, !tbaa !11
  %67 = load ptr, ptr %7, align 8, !tbaa !9
  %68 = call i32 @fclose(ptr noundef %67)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %69 = getelementptr inbounds [65536 x i8], ptr %9, i64 0, i64 0
  store ptr %69, ptr %14, align 8, !tbaa !9
  %70 = load ptr, ptr @_ZN3rmg8internal14glShaderSourceE, align 8, !tbaa !9
  %71 = load i32, ptr %6, align 4, !tbaa !5
  call void %70(i32 noundef %71, i32 noundef 1, ptr noundef %14, ptr noundef null)
  %72 = load ptr, ptr @_ZN3rmg8internal15glCompileShaderE, align 8, !tbaa !9
  %73 = load i32, ptr %6, align 4, !tbaa !5
  call void %72(i32 noundef %73)
  %74 = load ptr, ptr @_ZN3rmg8internal13glGetShaderivE, align 8, !tbaa !9
  %75 = load i32, ptr %6, align 4, !tbaa !5
  call void %74(i32 noundef %75, i32 noundef 35713, ptr noundef %12)
  %76 = load ptr, ptr @_ZN3rmg8internal13glGetShaderivE, align 8, !tbaa !9
  %77 = load i32, ptr %6, align 4, !tbaa !5
  call void %76(i32 noundef %77, i32 noundef 35716, ptr noundef %13)
  %78 = load i32, ptr %13, align 4, !tbaa !5
  %79 = icmp sgt i32 %78, 0
  br i1 %79, label %80, label %91

80:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %81 = load i32, ptr %13, align 4, !tbaa !5
  %82 = add nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = call noalias ptr @malloc(i64 noundef %83) #6
  store ptr %84, ptr %15, align 8, !tbaa !9
  %85 = load ptr, ptr @_ZN3rmg8internal18glGetShaderInfoLogE, align 8, !tbaa !9
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = load i32, ptr %13, align 4, !tbaa !5
  %88 = load ptr, ptr %15, align 8, !tbaa !9
  call void %85(i32 noundef %86, i32 noundef %87, ptr noundef null, ptr noundef %88)
  %89 = load ptr, ptr %15, align 8, !tbaa !9
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, ptr noundef %89)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  br label %93

91:                                               ; preds = %63
  %92 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %92, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %93

93:                                               ; preds = %91, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 65536, ptr %9) #5
  br label %94

94:                                               ; preds = %93, %37
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %95

95:                                               ; preds = %94, %27
  %96 = load i32, ptr %3, align 4
  ret i32 %96
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) #1

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

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

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

declare i32 @getc(ptr noundef) #3

declare i32 @fclose(ptr noundef) #3

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #4

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

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@.str = external hidden unnamed_addr constant [55 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [97 x i8], align 1
@_ZN3rmg8internal14glCreateShaderE = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [58 x i8], align 1
@_ZN3rmg8internal14glShaderSourceE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal15glCompileShaderE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal13glGetShaderivE = external local_unnamed_addr global ptr, align 8
@_ZN3rmg8internal18glGetShaderInfoLogE = external local_unnamed_addr global ptr, align 8
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN3rmg8internal6Shader13compileShaderEjPKc(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = alloca [65536 x i8], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = add i32 %0, -35634
  %or.cond = icmp ult i32 %7, -2
  br i1 %or.cond, label %8, label %9

8:                                                ; preds = %2
  tail call void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext false, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 47)
  br label %38

9:                                                ; preds = %2
  %10 = load ptr, ptr @_ZN3rmg8internal14glCreateShaderE, align 8, !tbaa !5
  %11 = tail call noundef i32 %10(i32 noundef %0)
  %12 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.2)
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %9
  %15 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %1)
  br label %38

16:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 65536, ptr nonnull %3) #5
  %17 = tail call i32 @getc(ptr noundef nonnull %12)
  %sext.mask30 = and i32 %17, 255
  %.not = icmp eq i32 %sext.mask30, 255
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %16, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %16 ]
  %.026.in32 = phi i32 [ %19, %.lr.ph ], [ %17, %16 ]
  %.026 = trunc i32 %.026.in32 to i8
  %18 = getelementptr inbounds [65536 x i8], ptr %3, i64 0, i64 %indvars.iv
  store i8 %.026, ptr %18, align 1, !tbaa !9
  %19 = tail call i32 @getc(ptr noundef nonnull %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %sext.mask = and i32 %19, 255
  %20 = icmp ne i32 %sext.mask, 255
  %21 = icmp ult i64 %indvars.iv, 65534
  %22 = and i1 %20, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %16
  %.027.lcssa = phi i64 [ 0, %16 ], [ %indvars.iv.next, %.lr.ph ]
  %23 = getelementptr inbounds [65536 x i8], ptr %3, i64 0, i64 %.027.lcssa
  store i8 0, ptr %23, align 1, !tbaa !9
  %24 = tail call i32 @fclose(ptr noundef nonnull %12)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  store i32 0, ptr %4, align 4, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  store ptr %3, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr @_ZN3rmg8internal14glShaderSourceE, align 8, !tbaa !5
  call void %25(i32 noundef %11, i32 noundef 1, ptr noundef nonnull %6, ptr noundef null)
  %26 = load ptr, ptr @_ZN3rmg8internal15glCompileShaderE, align 8, !tbaa !5
  call void %26(i32 noundef %11)
  %27 = load ptr, ptr @_ZN3rmg8internal13glGetShaderivE, align 8, !tbaa !5
  call void %27(i32 noundef %11, i32 noundef 35713, ptr noundef nonnull %4)
  %28 = load ptr, ptr @_ZN3rmg8internal13glGetShaderivE, align 8, !tbaa !5
  call void %28(i32 noundef %11, i32 noundef 35716, ptr noundef nonnull %5)
  %29 = load i32, ptr %5, align 4, !tbaa !12
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %31, label %37

31:                                               ; preds = %._crit_edge
  %32 = add nuw nsw i32 %29, 1
  %33 = zext nneg i32 %32 to i64
  %34 = call noalias ptr @malloc(i64 noundef %33) #6
  %35 = load ptr, ptr @_ZN3rmg8internal18glGetShaderInfoLogE, align 8, !tbaa !5
  call void %35(i32 noundef %11, i32 noundef %29, ptr noundef null, ptr noundef %34)
  %36 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, ptr noundef %34)
  br label %37

37:                                               ; preds = %._crit_edge, %31
  %.0 = phi i32 [ 0, %31 ], [ %11, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 65536, ptr nonnull %3) #5
  br label %38

38:                                               ; preds = %14, %37, %8
  %.2 = phi i32 [ 0, %8 ], [ 0, %14 ], [ %.0, %37 ]
  ret i32 %.2
}

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z12__rmg_expectbPKcS0_i(i1 noundef zeroext, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #4

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

attributes #0 = { 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 #1 = { inlinehint 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass