; 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 signext i8 @TCOD_zip_get_char(ptr noundef) #2

; 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_console(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
  %10 = alloca %struct.TCOD_ColorRGB, align 1
  %11 = 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
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = call i32 @TCOD_zip_get_int(ptr noundef %12)
  store i32 %13, ptr %4, align 4, !tbaa !9
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 @TCOD_zip_get_int(ptr noundef %14)
  store i32 %15, ptr %5, align 4, !tbaa !9
  %16 = load i32, ptr %4, align 4, !tbaa !9
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = call ptr @TCOD_console_new(i32 noundef %16, i32 noundef %17)
  store ptr %18, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %19

19:                                               ; preds = %51, %1
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !9
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %23, label %54

23:                                               ; preds = %19
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %47, %23
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %28, label %50

28:                                               ; preds = %24
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load i32, ptr %7, align 4, !tbaa !9
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = call signext i8 @TCOD_zip_get_char(ptr noundef %32)
  %34 = zext i8 %33 to i32
  call void @TCOD_console_set_char(ptr noundef %29, i32 noundef %30, i32 noundef %31, i32 noundef %34)
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = load i32, ptr %7, align 4, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = call i24 @TCOD_zip_get_color(ptr noundef %38)
  store i24 %39, ptr %8, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 1 %8, i64 3, i1 false)
  %40 = load i24, ptr %9, align 4
  call void @TCOD_console_set_char_foreground(ptr noundef %35, i32 noundef %36, i32 noundef %37, i24 %40)
  %41 = load ptr, ptr %3, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = call i24 @TCOD_zip_get_color(ptr noundef %44)
  store i24 %45, ptr %10, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 1 %10, i64 3, i1 false)
  %46 = load i24, ptr %11, align 4
  call void @TCOD_console_set_char_background(ptr noundef %41, i32 noundef %42, i32 noundef %43, i24 %46, i32 noundef 1)
  br label %47

47:                                               ; preds = %28
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %6, align 4, !tbaa !9
  br label %24, !llvm.loop !11

50:                                               ; preds = %24
  br label %51

51:                                               ; preds = %50
  %52 = load i32, ptr %7, align 4, !tbaa !9
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr %7, align 4, !tbaa !9
  br label %19, !llvm.loop !13

54:                                               ; preds = %19
  %55 = 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 %55
}

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

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

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

declare void @TCOD_console_set_char_background(ptr noundef, i32 noundef, i32 noundef, i24, i32 noundef) #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 signext i8 @TCOD_zip_get_char(ptr noundef) local_unnamed_addr #0

; 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_console(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_console_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_edge28

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

7:                                                ; preds = %.preheader.us, %7
  %.026.us = phi i32 [ 0, %.preheader.us ], [ %12, %7 ]
  %8 = tail call signext i8 @TCOD_zip_get_char(ptr noundef %0)
  %9 = zext i8 %8 to i32
  tail call void @TCOD_console_set_char(ptr noundef %4, i32 noundef %.026.us, i32 noundef %.02527.us, i32 noundef %9) #2
  %10 = tail call i24 @TCOD_zip_get_color(ptr noundef %0)
  tail call void @TCOD_console_set_char_foreground(ptr noundef %4, i32 noundef %.026.us, i32 noundef %.02527.us, i24 %10) #2
  %11 = tail call i24 @TCOD_zip_get_color(ptr noundef %0)
  tail call void @TCOD_console_set_char_background(ptr noundef %4, i32 noundef %.026.us, i32 noundef %.02527.us, i24 %11, i32 noundef 1) #2
  %12 = add nuw nsw i32 %.026.us, 1
  %exitcond.not = icmp eq i32 %12, %2
  br i1 %exitcond.not, label %._crit_edge.us, label %7, !llvm.loop !5

._crit_edge.us:                                   ; preds = %7
  %13 = add nuw nsw i32 %.02527.us, 1
  %exitcond30.not = icmp eq i32 %13, %3
  br i1 %exitcond30.not, label %._crit_edge28, label %.preheader.us, !llvm.loop !7

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

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

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

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

declare void @TCOD_console_set_char_background(ptr noundef, i32 noundef, i32 noundef, i24, i32 noundef) 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