; LLVM IR from danginsburg/opengles3-book :: Common/Source (esShader)

; 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.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @esLoadShader(i32 noundef, ptr noundef) #0

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

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

declare void @esLogMessage(ptr noundef, ...) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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

declare void @glDeleteShader(i32 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @esLoadProgram(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @esLoadShader(i32 noundef 35633, ptr noundef %13)
  store i32 %14, ptr %6, align 4, !tbaa !9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

18:                                               ; preds = %2
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i32 @esLoadShader(i32 noundef 35632, ptr noundef %19)
  store i32 %20, ptr %7, align 4, !tbaa !9
  %21 = load i32, ptr %7, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 0
  br i1 %22, label %23, label %25

23:                                               ; preds = %18
  %24 = load i32, ptr %6, align 4, !tbaa !9
  call void @glDeleteShader(i32 noundef %24)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

25:                                               ; preds = %18
  %26 = call i32 @glCreateProgram()
  store i32 %26, ptr %8, align 4, !tbaa !9
  %27 = load i32, ptr %8, align 4, !tbaa !9
  %28 = icmp eq i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

30:                                               ; preds = %25
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  call void @glAttachShader(i32 noundef %31, i32 noundef %32)
  %33 = load i32, ptr %8, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  call void @glAttachShader(i32 noundef %33, i32 noundef %34)
  %35 = load i32, ptr %8, align 4, !tbaa !9
  call void @glLinkProgram(i32 noundef %35)
  %36 = load i32, ptr %8, align 4, !tbaa !9
  call void @glGetProgramiv(i32 noundef %36, i32 noundef 35714, ptr noundef %9)
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %55, label %39

39:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !9
  %40 = load i32, ptr %8, align 4, !tbaa !9
  call void @glGetProgramiv(i32 noundef %40, i32 noundef 35716, ptr noundef %11)
  %41 = load i32, ptr %11, align 4, !tbaa !9
  %42 = icmp sgt i32 %41, 1
  br i1 %42, label %43, label %53

43:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = mul i64 1, %45
  %47 = call noalias ptr @malloc(i64 noundef %46) #6
  store ptr %47, ptr %12, align 8, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  call void @glGetProgramInfoLog(i32 noundef %48, i32 noundef %49, ptr noundef null, ptr noundef %50)
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  call void (ptr, ...) @esLogMessage(ptr noundef @.str.1, ptr noundef %51)
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %52) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %53

53:                                               ; preds = %43, %39
  %54 = load i32, ptr %8, align 4, !tbaa !9
  call void @glDeleteProgram(i32 noundef %54)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %59

55:                                               ; preds = %30
  %56 = load i32, ptr %6, align 4, !tbaa !9
  call void @glDeleteShader(i32 noundef %56)
  %57 = load i32, ptr %7, align 4, !tbaa !9
  call void @glDeleteShader(i32 noundef %57)
  %58 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %58, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

59:                                               ; preds = %55, %53, %29, %23, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %60 = load i32, ptr %3, align 4
  ret i32 %60
}

declare i32 @glCreateProgram() #3

declare void @glAttachShader(i32 noundef, i32 noundef) #3

declare void @glLinkProgram(i32 noundef) #3

declare void @glGetProgramiv(i32 noundef, i32 noundef, ptr noundef) #3

declare void @glGetProgramInfoLog(i32 noundef, i32 noundef, ptr noundef, ptr noundef) #3

declare void @glDeleteProgram(i32 noundef) #3

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 = { 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 #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 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, 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"

@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @esLoadShader(i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

declare void @esLogMessage(ptr noundef, ...) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture 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) #1

declare void @glDeleteShader(i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local i32 @esLoadProgram(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %5 = tail call i32 @esLoadShader(i32 noundef 35633, ptr noundef %0)
  %6 = icmp eq i32 %5, 0
  br i1 %6, label %24, label %7

7:                                                ; preds = %2
  %8 = tail call i32 @esLoadShader(i32 noundef 35632, ptr noundef %1)
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %7
  tail call void @glDeleteShader(i32 noundef %5) #5
  br label %24

11:                                               ; preds = %7
  %12 = tail call i32 @glCreateProgram() #5
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %24, label %14

14:                                               ; preds = %11
  tail call void @glAttachShader(i32 noundef %12, i32 noundef %5) #5
  tail call void @glAttachShader(i32 noundef %12, i32 noundef %8) #5
  tail call void @glLinkProgram(i32 noundef %12) #5
  call void @glGetProgramiv(i32 noundef %12, i32 noundef 35714, ptr noundef nonnull %3) #5
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %16, label %23

16:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @glGetProgramiv(i32 noundef %12, i32 noundef 35716, ptr noundef nonnull %4) #5
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = icmp sgt i32 %17, 1
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  %20 = zext nneg i32 %17 to i64
  %21 = call noalias ptr @malloc(i64 noundef %20) #6
  call void @glGetProgramInfoLog(i32 noundef %12, i32 noundef %17, ptr noundef null, ptr noundef %21) #5
  call void (ptr, ...) @esLogMessage(ptr noundef nonnull @.str.1, ptr noundef %21) #5
  call void @free(ptr noundef %21) #5
  br label %22

22:                                               ; preds = %19, %16
  call void @glDeleteProgram(i32 noundef %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  br label %24

23:                                               ; preds = %14
  call void @glDeleteShader(i32 noundef %5) #5
  call void @glDeleteShader(i32 noundef %8) #5
  br label %24

24:                                               ; preds = %11, %2, %23, %22, %10
  %.0 = phi i32 [ 0, %10 ], [ %12, %23 ], [ 0, %22 ], [ 0, %2 ], [ 0, %11 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret i32 %.0
}

declare i32 @glCreateProgram() local_unnamed_addr #3

declare void @glAttachShader(i32 noundef, i32 noundef) local_unnamed_addr #3

declare void @glLinkProgram(i32 noundef) local_unnamed_addr #3

declare void @glGetProgramiv(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare void @glGetProgramInfoLog(i32 noundef, i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #3

declare void @glDeleteProgram(i32 noundef) local_unnamed_addr #3

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { mustprogress nounwind willreturn allockind("free") 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 #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/C++ TBAA"}


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