; LLVM IR from danginsburg/opengles3-book :: Chapter_2/Hello_Triangle (Hello_Triangle)

; 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.ESContext = type { ptr, ptr, i32, i32, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.UserData = type { i32 }

@__const.Init.vShaderStr = external hidden unnamed_addr constant [253 x i8], align 16
@__const.Init.fShaderStr = external hidden unnamed_addr constant [323 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @LoadShader(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

; Function Attrs: nounwind uwtable
define dso_local i32 @Init(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [253 x i8], align 16
  %6 = alloca [323 x i8], align 16
  %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 i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.ESContext, ptr %14, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !9
  store ptr %16, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 253, ptr %5) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %5, ptr align 16 @__const.Init.vShaderStr, i64 253, i1 false)
  call void @llvm.lifetime.start.p0(i64 323, ptr %6) #6
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %6, ptr align 16 @__const.Init.fShaderStr, i64 323, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %17 = getelementptr inbounds [253 x i8], ptr %5, i64 0, i64 0
  %18 = call i32 @LoadShader(i32 noundef 35633, ptr noundef %17)
  store i32 %18, ptr %7, align 4, !tbaa !13
  %19 = getelementptr inbounds [323 x i8], ptr %6, i64 0, i64 0
  %20 = call i32 @LoadShader(i32 noundef 35632, ptr noundef %19)
  store i32 %20, ptr %8, align 4, !tbaa !13
  %21 = call i32 @glCreateProgram()
  store i32 %21, ptr %9, align 4, !tbaa !13
  %22 = load i32, ptr %9, align 4, !tbaa !13
  %23 = icmp eq i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %54

25:                                               ; preds = %1
  %26 = load i32, ptr %9, align 4, !tbaa !13
  %27 = load i32, ptr %7, align 4, !tbaa !13
  call void @glAttachShader(i32 noundef %26, i32 noundef %27)
  %28 = load i32, ptr %9, align 4, !tbaa !13
  %29 = load i32, ptr %8, align 4, !tbaa !13
  call void @glAttachShader(i32 noundef %28, i32 noundef %29)
  %30 = load i32, ptr %9, align 4, !tbaa !13
  call void @glLinkProgram(i32 noundef %30)
  %31 = load i32, ptr %9, align 4, !tbaa !13
  call void @glGetProgramiv(i32 noundef %31, i32 noundef 35714, ptr noundef %10)
  %32 = load i32, ptr %10, align 4, !tbaa !13
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %50, label %34

34:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !13
  %35 = load i32, ptr %9, align 4, !tbaa !13
  call void @glGetProgramiv(i32 noundef %35, i32 noundef 35716, ptr noundef %12)
  %36 = load i32, ptr %12, align 4, !tbaa !13
  %37 = icmp sgt i32 %36, 1
  br i1 %37, label %38, label %48

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

48:                                               ; preds = %38, %34
  %49 = load i32, ptr %9, align 4, !tbaa !13
  call void @glDeleteProgram(i32 noundef %49)
  store i32 0, ptr %2, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %54

50:                                               ; preds = %25
  %51 = load i32, ptr %9, align 4, !tbaa !13
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.UserData, ptr %52, i32 0, i32 0
  store i32 %51, ptr %53, align 4, !tbaa !14
  call void @glClearColor(float noundef 1.000000e+00, float noundef 1.000000e+00, float noundef 1.000000e+00, float noundef 0.000000e+00)
  store i32 1, ptr %2, align 4
  store i32 1, ptr %11, align 4
  br label %54

54:                                               ; preds = %50, %48, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 323, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 253, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %55 = load i32, ptr %2, align 4
  ret i32 %55
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

declare void @glClearColor(float noundef, float noundef, float noundef, float 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { 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, !6, i64 8}
!10 = !{!"ESContext", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !6, i64 24, !12, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !11, 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"

@__const.Init.vShaderStr = external hidden unnamed_addr constant [253 x i8], align 16
@__const.Init.fShaderStr = external hidden unnamed_addr constant [323 x i8], align 16
@.str.1 = external hidden unnamed_addr constant [27 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @LoadShader(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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @Init(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = alloca [253 x i8], align 16
  %3 = alloca [323 x i8], align 16
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 253, ptr nonnull %2) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(253) %2, ptr noundef nonnull align 16 dereferenceable(253) @__const.Init.vShaderStr, i64 253, i1 false)
  call void @llvm.lifetime.start.p0(i64 323, ptr nonnull %3) #6
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(323) %3, ptr noundef nonnull align 16 dereferenceable(323) @__const.Init.fShaderStr, i64 323, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  %8 = call i32 @LoadShader(i32 noundef 35633, ptr noundef nonnull %2)
  %9 = call i32 @LoadShader(i32 noundef 35632, ptr noundef nonnull %3)
  %10 = call i32 @glCreateProgram() #6
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %22, label %12

12:                                               ; preds = %1
  call void @glAttachShader(i32 noundef %10, i32 noundef %8) #6
  call void @glAttachShader(i32 noundef %10, i32 noundef %9) #6
  call void @glLinkProgram(i32 noundef %10) #6
  call void @glGetProgramiv(i32 noundef %10, i32 noundef 35714, ptr noundef nonnull %4) #6
  %13 = load i32, ptr %4, align 4, !tbaa !12
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %14, label %21

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

17:                                               ; preds = %14
  %18 = zext nneg i32 %15 to i64
  %19 = call noalias ptr @malloc(i64 noundef %18) #7
  call void @glGetProgramInfoLog(i32 noundef %10, i32 noundef %15, ptr noundef null, ptr noundef %19) #6
  call void (ptr, ...) @esLogMessage(ptr noundef nonnull @.str.1, ptr noundef %19) #6
  call void @free(ptr noundef %19) #6
  br label %20

20:                                               ; preds = %17, %14
  call void @glDeleteProgram(i32 noundef %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #6
  br label %22

21:                                               ; preds = %12
  store i32 %10, ptr %7, align 4, !tbaa !13
  call void @glClearColor(float noundef 1.000000e+00, float noundef 1.000000e+00, float noundef 1.000000e+00, float noundef 0.000000e+00) #6
  br label %22

22:                                               ; preds = %1, %21, %20
  %.0 = phi i32 [ 1, %21 ], [ 0, %20 ], [ 0, %1 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 323, ptr nonnull %3) #6
  call void @llvm.lifetime.end.p0(i64 253, ptr nonnull %2) #6
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #5

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

declare void @glClearColor(float noundef, float noundef, float noundef, float 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { nounwind }
attributes #7 = { 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, !7, i64 8}
!6 = !{!"ESContext", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !11, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88}
!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 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0}


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