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

; 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.SettingsDataV1 = type { i32, i32, i32 }
%struct.ImageDetailsV1 = type { i32, i32, i32, i32 }
%struct._G_fpos_t = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%struct.TCOD_ColorRGB = type { i8, i8, i8 }
%struct.TCOD_Console = type { i32, i32, ptr, i32, i32, %struct.TCOD_ColorRGB, %struct.TCOD_ColorRGB, i8, %struct.TCOD_ColorRGB, i32, ptr, ptr }

@.str.5 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_save_apf = external hidden unnamed_addr constant [58 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @TCOD_console_validate_(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: 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) #2

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #3

declare i24 @TCOD_console_get_char_background(ptr noundef, i32 noundef, i32 noundef) #4

declare i32 @TCOD_console_get_char(ptr noundef, i32 noundef, i32 noundef) #4

declare i24 @TCOD_console_get_char_foreground(ptr noundef, i32 noundef, i32 noundef) #4

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

declare i32 @fclose(ptr noundef) #4

; Function Attrs: nounwind uwtable
declare dso_local void @detectBigEndianness() #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @l32(i32 noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @put8(i8 noundef zeroext, ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @put32(i32 noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @putFourCC(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local void @putData(ptr noundef, i32 noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @TCOD_console_save_apf(ptr noundef %0, ptr noundef %1) #5 {
  %3 = alloca i1, align 1
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %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 %struct.SettingsDataV1, align 4
  %13 = alloca %struct.ImageDetailsV1, align 4
  %14 = alloca %struct._G_fpos_t, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %struct.TCOD_ColorRGB, align 1
  %19 = alloca %struct.TCOD_ColorRGB, align 1
  %20 = alloca i32, align 4
  %21 = alloca %struct.TCOD_ColorRGB, align 1
  %22 = alloca %struct.TCOD_ColorRGB, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = call ptr @TCOD_console_validate_(ptr noundef %23)
  store ptr %24, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %28

27:                                               ; preds = %2
  br label %29

28:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str.17, ptr noundef @.str.5, i32 noundef 880, ptr noundef @__PRETTY_FUNCTION__.TCOD_console_save_apf) #7
  unreachable

29:                                               ; preds = %27
  call void @detectBigEndianness()
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call noalias ptr @fopen(ptr noundef %30, ptr noundef @.str.19)
  store ptr %31, ptr %6, align 8, !tbaa !5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = icmp eq ptr %32, null
  br i1 %33, label %34, label %35

34:                                               ; preds = %29
  store i1 false, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %202

35:                                               ; preds = %29
  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
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putFourCC(ptr noundef @.str.22, ptr noundef %36)
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = call i32 @fgetpos(ptr noundef %37, ptr noundef %14)
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef 0, ptr noundef %39)
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putFourCC(ptr noundef @.str.23, ptr noundef %40)
  %41 = load i32, ptr %10, align 4, !tbaa !9
  %42 = add i32 %41, 4
  store i32 %42, ptr %10, align 4, !tbaa !9
  %43 = getelementptr inbounds %struct.SettingsDataV1, ptr %12, i32 0, i32 0
  store i32 0, ptr %43, align 4, !tbaa !11
  %44 = getelementptr inbounds %struct.SettingsDataV1, ptr %12, i32 0, i32 1
  store i32 8, ptr %44, align 4, !tbaa !13
  %45 = getelementptr inbounds %struct.SettingsDataV1, ptr %12, i32 0, i32 2
  store i32 8, ptr %45, align 4, !tbaa !14
  store i32 16, ptr %15, align 4, !tbaa !9
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putFourCC(ptr noundef @.str.24, ptr noundef %46)
  %47 = load i32, ptr %15, align 4, !tbaa !9
  %48 = call i32 @l32(i32 noundef %47)
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %48, ptr noundef %49)
  %50 = call i32 @l32(i32 noundef 1)
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %50, ptr noundef %51)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putData(ptr noundef %12, i32 noundef 12, ptr noundef %52)
  %53 = load i32, ptr %15, align 4, !tbaa !9
  %54 = and i32 %53, 1
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %60

56:                                               ; preds = %35
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext 0, ptr noundef %57)
  %58 = load i32, ptr %10, align 4, !tbaa !9
  %59 = add i32 %58, 1
  store i32 %59, ptr %10, align 4, !tbaa !9
  br label %60

60:                                               ; preds = %56, %35
  %61 = load i32, ptr %15, align 4, !tbaa !9
  %62 = add i32 8, %61
  %63 = load i32, ptr %10, align 4, !tbaa !9
  %64 = add i32 %63, %62
  store i32 %64, ptr %10, align 4, !tbaa !9
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.TCOD_Console, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !15
  %68 = getelementptr inbounds %struct.ImageDetailsV1, ptr %13, i32 0, i32 0
  store i32 %67, ptr %68, align 4, !tbaa !19
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TCOD_Console, ptr %69, i32 0, i32 1
  %71 = load i32, ptr %70, align 4, !tbaa !21
  %72 = getelementptr inbounds %struct.ImageDetailsV1, ptr %13, i32 0, i32 1
  store i32 %71, ptr %72, align 4, !tbaa !22
  %73 = getelementptr inbounds %struct.ImageDetailsV1, ptr %13, i32 0, i32 2
  store i32 0, ptr %73, align 4, !tbaa !23
  %74 = getelementptr inbounds %struct.ImageDetailsV1, ptr %13, i32 0, i32 3
  store i32 0, ptr %74, align 4, !tbaa !24
  store i32 20, ptr %11, align 4, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putFourCC(ptr noundef @.str.25, ptr noundef %75)
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = call i32 @l32(i32 noundef %76)
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %77, ptr noundef %78)
  %79 = call i32 @l32(i32 noundef 1)
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %79, ptr noundef %80)
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putData(ptr noundef %13, i32 noundef 16, ptr noundef %81)
  %82 = load i32, ptr %11, align 4, !tbaa !9
  %83 = and i32 %82, 1
  %84 = icmp ne i32 %83, 0
  br i1 %84, label %85, label %89

85:                                               ; preds = %60
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext 0, ptr noundef %86)
  %87 = load i32, ptr %10, align 4, !tbaa !9
  %88 = add i32 %87, 1
  store i32 %88, ptr %10, align 4, !tbaa !9
  br label %89

89:                                               ; preds = %85, %60
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = add i32 8, %90
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = add i32 %92, %91
  store i32 %93, ptr %10, align 4, !tbaa !9
  %94 = getelementptr inbounds %struct.ImageDetailsV1, ptr %13, i32 0, i32 0
  %95 = load i32, ptr %94, align 4, !tbaa !19
  %96 = getelementptr inbounds %struct.ImageDetailsV1, ptr %13, i32 0, i32 1
  %97 = load i32, ptr %96, align 4, !tbaa !22
  %98 = mul i32 %95, %97
  %99 = mul i32 %98, 7
  store i32 %99, ptr %16, align 4, !tbaa !9
  %100 = load i32, ptr %16, align 4, !tbaa !9
  %101 = zext i32 %100 to i64
  %102 = add i64 32, %101
  %103 = trunc i64 %102 to i32
  store i32 %103, ptr %17, align 4, !tbaa !9
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putFourCC(ptr noundef @.str.26, ptr noundef %104)
  %105 = load i32, ptr %17, align 4, !tbaa !9
  %106 = call i32 @l32(i32 noundef %105)
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %106, ptr noundef %107)
  %108 = call i32 @l32(i32 noundef 2)
  %109 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %108, ptr noundef %109)
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  call void @putFourCC(ptr noundef @.str.27, ptr noundef %110)
  %111 = call i32 @l32(i32 noundef 0)
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %111, ptr noundef %112)
  %113 = call i32 @l32(i32 noundef 255)
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %113, ptr noundef %114)
  %115 = call i32 @l32(i32 noundef 255)
  %116 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %115, ptr noundef %116)
  %117 = call i32 @l32(i32 noundef 1)
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %117, ptr noundef %118)
  %119 = call i32 @l32(i32 noundef 0)
  %120 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %119, ptr noundef %120)
  %121 = load i32, ptr %16, align 4, !tbaa !9
  %122 = call i32 @l32(i32 noundef %121)
  %123 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %122, ptr noundef %123)
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %124

124:                                              ; preds = %175, %89
  %125 = load i32, ptr %8, align 4, !tbaa !9
  %126 = load ptr, ptr %4, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.TCOD_Console, ptr %126, i32 0, i32 0
  %128 = load i32, ptr %127, align 8, !tbaa !15
  %129 = icmp slt i32 %125, %128
  br i1 %129, label %130, label %178

130:                                              ; preds = %124
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %131

131:                                              ; preds = %171, %130
  %132 = load i32, ptr %9, align 4, !tbaa !9
  %133 = load ptr, ptr %4, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.TCOD_Console, ptr %133, i32 0, i32 1
  %135 = load i32, ptr %134, align 4, !tbaa !21
  %136 = icmp slt i32 %132, %135
  br i1 %136, label %137, label %174

137:                                              ; preds = %131
  call void @llvm.lifetime.start.p0(i64 3, ptr %18) #6
  call void @llvm.lifetime.start.p0(i64 3, ptr %19) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #6
  %138 = load ptr, ptr %4, align 8, !tbaa !5
  %139 = load i32, ptr %8, align 4, !tbaa !9
  %140 = load i32, ptr %9, align 4, !tbaa !9
  %141 = call i32 @TCOD_console_get_char(ptr noundef %138, i32 noundef %139, i32 noundef %140)
  store i32 %141, ptr %20, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 3, ptr %21) #6
  %142 = load ptr, ptr %4, align 8, !tbaa !5
  %143 = load i32, ptr %8, align 4, !tbaa !9
  %144 = load i32, ptr %9, align 4, !tbaa !9
  %145 = call i24 @TCOD_console_get_char_foreground(ptr noundef %142, i32 noundef %143, i32 noundef %144)
  store i24 %145, ptr %21, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %18, ptr align 1 %21, i64 3, i1 false), !tbaa.struct !25
  call void @llvm.lifetime.end.p0(i64 3, ptr %21) #6
  call void @llvm.lifetime.start.p0(i64 3, ptr %22) #6
  %146 = load ptr, ptr %4, align 8, !tbaa !5
  %147 = load i32, ptr %8, align 4, !tbaa !9
  %148 = load i32, ptr %9, align 4, !tbaa !9
  %149 = call i24 @TCOD_console_get_char_background(ptr noundef %146, i32 noundef %147, i32 noundef %148)
  store i24 %149, ptr %22, align 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %19, ptr align 1 %22, i64 3, i1 false), !tbaa.struct !25
  call void @llvm.lifetime.end.p0(i64 3, ptr %22) #6
  %150 = load i32, ptr %20, align 4, !tbaa !9
  %151 = trunc i32 %150 to i8
  %152 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %151, ptr noundef %152)
  %153 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %18, i32 0, i32 0
  %154 = load i8, ptr %153, align 1, !tbaa !27
  %155 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %154, ptr noundef %155)
  %156 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %18, i32 0, i32 1
  %157 = load i8, ptr %156, align 1, !tbaa !28
  %158 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %157, ptr noundef %158)
  %159 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %18, i32 0, i32 2
  %160 = load i8, ptr %159, align 1, !tbaa !29
  %161 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %160, ptr noundef %161)
  %162 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %19, i32 0, i32 0
  %163 = load i8, ptr %162, align 1, !tbaa !27
  %164 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %163, ptr noundef %164)
  %165 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %19, i32 0, i32 1
  %166 = load i8, ptr %165, align 1, !tbaa !28
  %167 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %166, ptr noundef %167)
  %168 = getelementptr inbounds %struct.TCOD_ColorRGB, ptr %19, i32 0, i32 2
  %169 = load i8, ptr %168, align 1, !tbaa !29
  %170 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext %169, ptr noundef %170)
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #6
  call void @llvm.lifetime.end.p0(i64 3, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 3, ptr %18) #6
  br label %171

171:                                              ; preds = %137
  %172 = load i32, ptr %9, align 4, !tbaa !9
  %173 = add nsw i32 %172, 1
  store i32 %173, ptr %9, align 4, !tbaa !9
  br label %131, !llvm.loop !30

174:                                              ; preds = %131
  br label %175

175:                                              ; preds = %174
  %176 = load i32, ptr %8, align 4, !tbaa !9
  %177 = add nsw i32 %176, 1
  store i32 %177, ptr %8, align 4, !tbaa !9
  br label %124, !llvm.loop !32

178:                                              ; preds = %124
  %179 = load i32, ptr %17, align 4, !tbaa !9
  %180 = and i32 %179, 1
  %181 = icmp ne i32 %180, 0
  br i1 %181, label %182, label %186

182:                                              ; preds = %178
  %183 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put8(i8 noundef zeroext 0, ptr noundef %183)
  %184 = load i32, ptr %10, align 4, !tbaa !9
  %185 = add i32 %184, 1
  store i32 %185, ptr %10, align 4, !tbaa !9
  br label %186

186:                                              ; preds = %182, %178
  %187 = load i32, ptr %17, align 4, !tbaa !9
  %188 = zext i32 %187 to i64
  %189 = add i64 8, %188
  %190 = load i32, ptr %10, align 4, !tbaa !9
  %191 = zext i32 %190 to i64
  %192 = add i64 %191, %189
  %193 = trunc i64 %192 to i32
  store i32 %193, ptr %10, align 4, !tbaa !9
  %194 = load ptr, ptr %6, align 8, !tbaa !5
  %195 = call i32 @fsetpos(ptr noundef %194, ptr noundef %14)
  %196 = load i32, ptr %10, align 4, !tbaa !9
  %197 = call i32 @l32(i32 noundef %196)
  %198 = load ptr, ptr %6, align 8, !tbaa !5
  call void @put32(i32 noundef %197, ptr noundef %198)
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  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
  br label %199

199:                                              ; preds = %186
  %200 = load ptr, ptr %6, align 8, !tbaa !5
  %201 = call i32 @fclose(ptr noundef %200)
  store i1 true, ptr %3, align 1
  store i32 1, ptr %7, align 4
  br label %202

202:                                              ; preds = %199, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  %203 = load i1, ptr %3, align 1
  ret i1 %203
}

declare i32 @fgetpos(ptr noundef, ptr noundef) #4

declare i32 @fsetpos(ptr noundef, ptr noundef) #4

attributes #0 = { inlinehint 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { noreturn 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 = { "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 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 #6 = { nounwind }
attributes #7 = { noreturn 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 = !{!12, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !10, i64 0}
!16 = !{!"TCOD_Console", !10, i64 0, !10, i64 4, !6, i64 8, !10, i64 16, !10, i64 20, !17, i64 24, !17, i64 27, !18, i64 30, !17, i64 31, !10, i64 36, !6, i64 40, !6, i64 48}
!17 = !{!"TCOD_ColorRGB", !7, i64 0, !7, i64 1, !7, i64 2}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!20, !10, i64 0}
!20 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!21 = !{!16, !10, i64 4}
!22 = !{!20, !10, i64 4}
!23 = !{!20, !10, i64 8}
!24 = !{!20, !10, i64 12}
!25 = !{i64 0, i64 1, !26, i64 1, i64 1, !26, i64 2, i64 1, !26}
!26 = !{!7, !7, i64 0}
!27 = !{!17, !7, i64 0}
!28 = !{!17, !7, i64 1}
!29 = !{!17, !7, i64 2}
!30 = distinct !{!30, !31}
!31 = !{!"llvm.loop.mustprogress"}
!32 = distinct !{!32, !31}


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

%struct.SettingsDataV1 = type { i32, i32, i32 }
%struct.ImageDetailsV1 = type { i32, i32, i32, i32 }
%struct._G_fpos_t = type { i64, %struct.__mbstate_t }
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }

@.str.5 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [18 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@__PRETTY_FUNCTION__.TCOD_console_save_apf = external hidden unnamed_addr constant [58 x i8], align 1
@.str.22 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.23 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.24 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.25 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.26 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.27 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @TCOD_console_validate_(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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

declare i24 @TCOD_console_get_char_background(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare i32 @TCOD_console_get_char(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare i24 @TCOD_console_get_char_foreground(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @detectBigEndianness() local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @l32(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local void @put8(i8 noundef zeroext, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local void @put32(i32 noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local void @putFourCC(ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
declare dso_local void @putData(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @TCOD_console_save_apf(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #5 {
  %3 = alloca %struct.SettingsDataV1, align 4
  %4 = alloca %struct.ImageDetailsV1, align 8
  %5 = alloca %struct._G_fpos_t, align 8
  %6 = tail call ptr @TCOD_console_validate_(ptr noundef %0)
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %8

7:                                                ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str.17, ptr noundef nonnull @.str.5, i32 noundef 880, ptr noundef nonnull @__PRETTY_FUNCTION__.TCOD_console_save_apf) #6
  unreachable

8:                                                ; preds = %2
  tail call void @detectBigEndianness()
  %9 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.19)
  %10 = icmp ne ptr %9, null
  br i1 %10, label %11, label %63

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #7
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #7
  tail call void @putFourCC(ptr noundef nonnull @.str.22, ptr noundef nonnull %9)
  %12 = call i32 @fgetpos(ptr noundef nonnull %9, ptr noundef nonnull %5)
  tail call void @put32(i32 noundef 0, ptr noundef nonnull %9)
  tail call void @putFourCC(ptr noundef nonnull @.str.23, ptr noundef nonnull %9)
  store i32 0, ptr %3, align 4, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 8, ptr %13, align 4, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 8, ptr %14, align 4, !tbaa !11
  tail call void @putFourCC(ptr noundef nonnull @.str.24, ptr noundef nonnull %9)
  %15 = tail call i32 @l32(i32 noundef 16)
  tail call void @put32(i32 noundef %15, ptr noundef nonnull %9)
  %16 = tail call i32 @l32(i32 noundef 1)
  tail call void @put32(i32 noundef %16, ptr noundef nonnull %9)
  call void @putData(ptr noundef nonnull %3, i32 noundef 12, ptr noundef nonnull %9)
  %17 = getelementptr inbounds i8, ptr %6, i64 4
  %18 = getelementptr inbounds i8, ptr %4, i64 4
  %19 = load <2 x i32>, ptr %6, align 8, !tbaa !12
  store <2 x i32> %19, ptr %4, align 8, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 0, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %4, i64 12
  store i32 0, ptr %21, align 4, !tbaa !15
  call void @putFourCC(ptr noundef nonnull @.str.25, ptr noundef nonnull %9)
  %22 = call i32 @l32(i32 noundef 20)
  call void @put32(i32 noundef %22, ptr noundef nonnull %9)
  %23 = call i32 @l32(i32 noundef 1)
  call void @put32(i32 noundef %23, ptr noundef nonnull %9)
  call void @putData(ptr noundef nonnull %4, i32 noundef 16, ptr noundef nonnull %9)
  %24 = load i32, ptr %4, align 8, !tbaa !16
  %25 = load i32, ptr %18, align 4, !tbaa !17
  %26 = mul i32 %24, 7
  %27 = mul i32 %26, %25
  %28 = add i32 %27, 32
  call void @putFourCC(ptr noundef nonnull @.str.26, ptr noundef nonnull %9)
  %29 = call i32 @l32(i32 noundef %28)
  call void @put32(i32 noundef %29, ptr noundef nonnull %9)
  %30 = call i32 @l32(i32 noundef 2)
  call void @put32(i32 noundef %30, ptr noundef nonnull %9)
  call void @putFourCC(ptr noundef nonnull @.str.27, ptr noundef nonnull %9)
  %31 = call i32 @l32(i32 noundef 0)
  call void @put32(i32 noundef %31, ptr noundef nonnull %9)
  %32 = call i32 @l32(i32 noundef 255)
  call void @put32(i32 noundef %32, ptr noundef nonnull %9)
  %33 = call i32 @l32(i32 noundef 255)
  call void @put32(i32 noundef %33, ptr noundef nonnull %9)
  %34 = call i32 @l32(i32 noundef 1)
  call void @put32(i32 noundef %34, ptr noundef nonnull %9)
  %35 = call i32 @l32(i32 noundef 0)
  call void @put32(i32 noundef %35, ptr noundef nonnull %9)
  %36 = call i32 @l32(i32 noundef %27)
  call void @put32(i32 noundef %36, ptr noundef nonnull %9)
  %37 = load i32, ptr %6, align 8, !tbaa !18
  %38 = icmp sgt i32 %37, 0
  br i1 %38, label %.preheader.lr.ph, label %._crit_edge89

.preheader.lr.ph:                                 ; preds = %11
  %39 = load i32, ptr %17, align 4, !tbaa !23
  %40 = icmp sgt i32 %39, 0
  br i1 %40, label %.preheader, label %._crit_edge89

.preheader:                                       ; preds = %.preheader.lr.ph, %._crit_edge
  %41 = phi i32 [ %51, %._crit_edge ], [ %37, %.preheader.lr.ph ]
  %42 = phi i32 [ %52, %._crit_edge ], [ %39, %.preheader.lr.ph ]
  %.08188 = phi i32 [ %53, %._crit_edge ], [ 0, %.preheader.lr.ph ]
  %43 = icmp sgt i32 %42, 0
  br i1 %43, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.08287 = phi i32 [ %48, %.lr.ph ], [ 0, %.preheader ]
  %44 = call i32 @TCOD_console_get_char(ptr noundef nonnull %6, i32 noundef %.08188, i32 noundef %.08287) #7
  %45 = call i24 @TCOD_console_get_char_foreground(ptr noundef nonnull %6, i32 noundef %.08188, i32 noundef %.08287) #7
  %.sroa.03.0.extract.trunc = trunc i24 %45 to i8
  %.sroa.44.0.extract.shift = lshr i24 %45, 8
  %.sroa.44.0.extract.trunc = trunc i24 %.sroa.44.0.extract.shift to i8
  %.sroa.55.0.extract.shift = lshr i24 %45, 16
  %.sroa.55.0.extract.trunc = trunc nuw i24 %.sroa.55.0.extract.shift to i8
  %46 = call i24 @TCOD_console_get_char_background(ptr noundef nonnull %6, i32 noundef %.08188, i32 noundef %.08287) #7
  %.sroa.02.0.extract.trunc = trunc i24 %46 to i8
  %.sroa.4.0.extract.shift = lshr i24 %46, 8
  %.sroa.4.0.extract.trunc = trunc i24 %.sroa.4.0.extract.shift to i8
  %.sroa.5.0.extract.shift = lshr i24 %46, 16
  %.sroa.5.0.extract.trunc = trunc nuw i24 %.sroa.5.0.extract.shift to i8
  %47 = trunc i32 %44 to i8
  call void @put8(i8 noundef zeroext %47, ptr noundef %9)
  call void @put8(i8 noundef zeroext %.sroa.03.0.extract.trunc, ptr noundef %9)
  call void @put8(i8 noundef zeroext %.sroa.44.0.extract.trunc, ptr noundef %9)
  call void @put8(i8 noundef zeroext %.sroa.55.0.extract.trunc, ptr noundef %9)
  call void @put8(i8 noundef zeroext %.sroa.02.0.extract.trunc, ptr noundef %9)
  call void @put8(i8 noundef zeroext %.sroa.4.0.extract.trunc, ptr noundef %9)
  call void @put8(i8 noundef zeroext %.sroa.5.0.extract.trunc, ptr noundef %9)
  %48 = add nuw nsw i32 %.08287, 1
  %49 = load i32, ptr %17, align 4, !tbaa !23
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !24

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %6, align 8, !tbaa !18
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %51 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %41, %.preheader ]
  %52 = phi i32 [ %49, %._crit_edge.loopexit ], [ %42, %.preheader ]
  %53 = add nuw nsw i32 %.08188, 1
  %54 = icmp slt i32 %53, %51
  br i1 %54, label %.preheader, label %._crit_edge89, !llvm.loop !26

._crit_edge89:                                    ; preds = %._crit_edge, %.preheader.lr.ph, %11
  %55 = and i32 %27, 1
  %.not86 = icmp eq i32 %55, 0
  br i1 %.not86, label %57, label %56

56:                                               ; preds = %._crit_edge89
  call void @put8(i8 noundef zeroext 0, ptr noundef %9)
  br label %57

57:                                               ; preds = %56, %._crit_edge89
  %.2 = phi i32 [ 57, %56 ], [ 56, %._crit_edge89 ]
  %58 = add i32 %27, 40
  %59 = add i32 %58, %.2
  %60 = call i32 @fsetpos(ptr noundef %9, ptr noundef nonnull %5)
  %61 = call i32 @l32(i32 noundef %59)
  call void @put32(i32 noundef %61, ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #7
  %62 = call i32 @fclose(ptr noundef %9)
  br label %63

63:                                               ; preds = %8, %57
  ret i1 %10
}

; Function Attrs: nofree nounwind
declare noundef i32 @fgetpos(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fsetpos(ptr nocapture noundef, ptr noundef) local_unnamed_addr #4

attributes #0 = { inlinehint 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 = { noreturn 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 #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 = { 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 #5 = { 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 #6 = { noreturn nounwind }
attributes #7 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !7, i64 8}
!14 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!15 = !{!14, !7, i64 12}
!16 = !{!14, !7, i64 0}
!17 = !{!14, !7, i64 4}
!18 = !{!19, !7, i64 0}
!19 = !{!"TCOD_Console", !7, i64 0, !7, i64 4, !20, i64 8, !7, i64 16, !7, i64 20, !21, i64 24, !21, i64 27, !22, i64 30, !21, i64 31, !7, i64 36, !20, i64 40, !20, i64 48}
!20 = !{!"any pointer", !8, i64 0}
!21 = !{!"TCOD_ColorRGB", !8, i64 0, !8, i64 1, !8, i64 2}
!22 = !{!"_Bool", !8, i64 0}
!23 = !{!19, !7, i64 4}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25, !27}
!27 = !{!"llvm.loop.unswitch.partial.disable"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass