; LLVM IR from libtcod/libtcod :: src/libtcod (zip_c)

; 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.TCOD_ColorRGB = type { i8, i8, i8 }

; 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: 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) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @TCOD_zip_get_int(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i24 @TCOD_zip_get_color(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @TCOD_zip_get_image(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca %struct.TCOD_ColorRGB, align 1
  %9 = alloca i24, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i32 @TCOD_zip_get_int(ptr noundef %10)
  store i32 %11, ptr %4, align 4, !tbaa !9
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @TCOD_zip_get_int(ptr noundef %12)
  store i32 %13, ptr %5, align 4, !tbaa !9
  %14 = load i32, ptr %4, align 4, !tbaa !9
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = call ptr @TCOD_image_new(i32 noundef %14, i32 noundef %15)
  store ptr %16, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %37, %1
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %40

21:                                               ; preds = %17
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %33, %21
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr %4, align 4, !tbaa !9
  %25 = icmp slt i32 %23, %24
  br i1 %25, label %26, label %36

26:                                               ; preds = %22
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = call i24 @TCOD_zip_get_color(ptr noundef %30)
  store i24 %31, ptr %8, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 1 %8, i64 3, i1 false)
  %32 = load i24, ptr %9, align 4
  call void @TCOD_image_put_pixel(ptr noundef %27, i32 noundef %28, i32 noundef %29, i24 %32)
  br label %33

33:                                               ; preds = %26
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %6, align 4, !tbaa !9
  br label %22, !llvm.loop !11

36:                                               ; preds = %22
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %7, align 4, !tbaa !9
  br label %17, !llvm.loop !13

40:                                               ; preds = %17
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %41
}

declare ptr @TCOD_image_new(i32 noundef, i32 noundef) #3

declare void @TCOD_image_put_pixel(ptr noundef, i32 noundef, i32 noundef, i24) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

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

; Function Attrs: nounwind uwtable
declare dso_local i24 @TCOD_zip_get_color(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @TCOD_zip_get_image(ptr noundef %0) local_unnamed_addr #0 {
  %2 = tail call i32 @TCOD_zip_get_int(ptr noundef %0)
  %3 = tail call i32 @TCOD_zip_get_int(ptr noundef %0)
  %4 = tail call ptr @TCOD_image_new(i32 noundef %2, i32 noundef %3) #2
  %5 = icmp sgt i32 %3, 0
  %6 = icmp sgt i32 %2, 0
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %.preheader.us, label %._crit_edge18

.preheader.us:                                    ; preds = %1, %._crit_edge.us
  %.01517.us = phi i32 [ %10, %._crit_edge.us ], [ 0, %1 ]
  br label %7

7:                                                ; preds = %.preheader.us, %7
  %.016.us = phi i32 [ 0, %.preheader.us ], [ %9, %7 ]
  %8 = tail call i24 @TCOD_zip_get_color(ptr noundef %0)
  tail call void @TCOD_image_put_pixel(ptr noundef %4, i32 noundef %.016.us, i32 noundef %.01517.us, i24 %8) #2
  %9 = add nuw nsw i32 %.016.us, 1
  %exitcond.not = icmp eq i32 %9, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !5

._crit_edge.us:                                   ; preds = %7
  %10 = add nuw nsw i32 %.01517.us, 1
  %exitcond20.not = icmp eq i32 %10, %3
  br i1 %exitcond20.not, label %._crit_edge18, label %.preheader.us, !llvm.loop !7

._crit_edge18:                                    ; preds = %._crit_edge.us, %1
  ret ptr %4
}

declare ptr @TCOD_image_new(i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @TCOD_image_put_pixel(ptr noundef, i32 noundef, i32 noundef, i24) local_unnamed_addr #1

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 = { "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 }

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass