; LLVM IR from clausecker/24puzzle :: cmd (bitpdb)

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

@stdin = external global ptr, align 8
@stdout = external global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@optind = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %12 = load ptr, ptr @stdin, align 8, !tbaa !9
  store ptr %12, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %13 = load ptr, ptr @stdout, align 8, !tbaa !9
  store ptr %13, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 231, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  br label %14

14:                                               ; preds = %43, %2
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = call i32 @__posix_getopt(i32 noundef %15, ptr noundef %16, ptr noundef @.str) #4
  store i32 %17, ptr %10, align 4, !tbaa !5
  %18 = load i32, ptr %10, align 4, !tbaa !5
  %19 = icmp ne i32 %18, -1
  br i1 %19, label %20, label %44

20:                                               ; preds = %14
  %21 = load i32, ptr %10, align 4, !tbaa !5
  switch i32 %21, label %43 [
    i32 111, label %22
    i32 116, label %30
    i32 63, label %39
    i32 58, label %39
  ]

22:                                               ; preds = %20
  %23 = load ptr, ptr @optarg, align 8, !tbaa !9
  %24 = call noalias ptr @fopen(ptr noundef %23, ptr noundef @.str.1)
  store ptr %24, ptr %8, align 8, !tbaa !9
  %25 = load ptr, ptr %8, align 8, !tbaa !9
  %26 = icmp eq ptr %25, null
  br i1 %26, label %27, label %29

27:                                               ; preds = %22
  %28 = load ptr, ptr @optarg, align 8, !tbaa !9
  call void @perror(ptr noundef %28)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %79

29:                                               ; preds = %22
  br label %43

30:                                               ; preds = %20
  %31 = load ptr, ptr @optarg, align 8, !tbaa !9
  %32 = call i32 @tileset_parse(ptr noundef %9, ptr noundef %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %38

34:                                               ; preds = %30
  %35 = load ptr, ptr @stderr, align 8, !tbaa !9
  %36 = load ptr, ptr @optarg, align 8, !tbaa !9
  %37 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %35, ptr noundef @.str.2, ptr noundef %36) #4
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %79

38:                                               ; preds = %30
  br label %43

39:                                               ; preds = %20, %20
  %40 = load ptr, ptr %5, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %40, i64 0
  %42 = load ptr, ptr %41, align 8, !tbaa !9
  call void @usage(ptr noundef %42)
  br label %43

43:                                               ; preds = %39, %38, %29, %20
  br label %14, !llvm.loop !11

44:                                               ; preds = %14
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = load i32, ptr @optind, align 4, !tbaa !5
  %47 = sub nsw i32 %45, %46
  switch i32 %47, label %64 [
    i32 0, label %68
    i32 1, label %48
  ]

48:                                               ; preds = %44
  %49 = load ptr, ptr %5, align 8, !tbaa !9
  %50 = load i32, ptr @optind, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds ptr, ptr %49, i64 %51
  %53 = load ptr, ptr %52, align 8, !tbaa !9
  %54 = call noalias ptr @fopen(ptr noundef %53, ptr noundef @.str.3)
  store ptr %54, ptr %7, align 8, !tbaa !9
  %55 = load ptr, ptr %7, align 8, !tbaa !9
  %56 = icmp eq ptr %55, null
  br i1 %56, label %57, label %63

57:                                               ; preds = %48
  %58 = load ptr, ptr %5, align 8, !tbaa !9
  %59 = load i32, ptr @optind, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !9
  call void @perror(ptr noundef %62)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %79

63:                                               ; preds = %48
  br label %68

64:                                               ; preds = %44
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = getelementptr inbounds ptr, ptr %65, i64 0
  %67 = load ptr, ptr %66, align 8, !tbaa !9
  call void @usage(ptr noundef %67)
  br label %68

68:                                               ; preds = %64, %63, %44
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = load ptr, ptr %7, align 8, !tbaa !9
  %71 = call i32 @fileno(ptr noundef %70) #4
  %72 = call ptr @pdb_mmap(i32 noundef %69, i32 noundef %71, i32 noundef 0)
  store ptr %72, ptr %6, align 8, !tbaa !9
  %73 = load ptr, ptr %6, align 8, !tbaa !9
  %74 = icmp eq ptr %73, null
  br i1 %74, label %75, label %76

75:                                               ; preds = %68
  call void @perror(ptr noundef @.str.4)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %79

76:                                               ; preds = %68
  %77 = load ptr, ptr %8, align 8, !tbaa !9
  %78 = load ptr, ptr %6, align 8, !tbaa !9
  call void @write_bitpdb(ptr noundef %77, ptr noundef %78)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %79

79:                                               ; preds = %76, %75, %57, %34, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %80 = load i32, ptr %3, align 4
  ret i32 %80
}

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

; Function Attrs: nounwind
declare i32 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) #2

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

declare void @perror(ptr noundef) #3

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

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare hidden void @usage(ptr noundef) #0

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

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @write_bitpdb(ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@stdin = external local_unnamed_addr global ptr, align 8
@stdout = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@optarg = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@stderr = external local_unnamed_addr global ptr, align 8
@.str.2 = external hidden unnamed_addr constant [27 x i8], align 1
@optind = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [9 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @main(i32 noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca i32, align 4
  %4 = load ptr, ptr @stdin, align 8, !tbaa !5
  %5 = load ptr, ptr @stdout, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 231, ptr %3, align 4, !tbaa !9
  br label %.outer

.outer:                                           ; preds = %8, %2
  %.015.ph = phi ptr [ %10, %8 ], [ %5, %2 ]
  br label %6

6:                                                ; preds = %.backedge, %.outer
  %7 = call i32 @__posix_getopt(i32 noundef %0, ptr noundef %1, ptr noundef nonnull @.str) #5
  switch i32 %7, label %.backedge [
    i32 -1, label %23
    i32 111, label %8
    i32 116, label %14
    i32 63, label %21
    i32 58, label %21
  ]

.backedge:                                        ; preds = %6, %14, %21
  br label %6, !llvm.loop !11

8:                                                ; preds = %6
  %9 = load ptr, ptr @optarg, align 8, !tbaa !5
  %10 = call noalias ptr @fopen(ptr noundef %9, ptr noundef nonnull @.str.1)
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %.outer, !llvm.loop !11

12:                                               ; preds = %8
  %13 = load ptr, ptr @optarg, align 8, !tbaa !5
  call void @perror(ptr noundef %13) #6
  br label %46

14:                                               ; preds = %6
  %15 = load ptr, ptr @optarg, align 8, !tbaa !5
  %16 = call i32 @tileset_parse(ptr noundef nonnull %3, ptr noundef %15) #5
  %.not21 = icmp eq i32 %16, 0
  br i1 %.not21, label %.backedge, label %17

17:                                               ; preds = %14
  %18 = load ptr, ptr @stderr, align 8, !tbaa !5
  %19 = load ptr, ptr @optarg, align 8, !tbaa !5
  %20 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %18, ptr noundef nonnull @.str.2, ptr noundef %19) #7
  br label %46

21:                                               ; preds = %6, %6
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  call void @usage(ptr noundef %22)
  br label %.backedge

23:                                               ; preds = %6
  %24 = load i32, ptr @optind, align 4, !tbaa !9
  %25 = sub nsw i32 %0, %24
  switch i32 %25, label %37 [
    i32 0, label %39
    i32 1, label %26
  ]

26:                                               ; preds = %23
  %27 = sext i32 %24 to i64
  %28 = getelementptr inbounds ptr, ptr %1, i64 %27
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = call noalias ptr @fopen(ptr noundef %29, ptr noundef nonnull @.str.3)
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %39

32:                                               ; preds = %26
  %33 = load i32, ptr @optind, align 4, !tbaa !9
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds ptr, ptr %1, i64 %34
  %36 = load ptr, ptr %35, align 8, !tbaa !5
  call void @perror(ptr noundef %36) #6
  br label %46

37:                                               ; preds = %23
  %38 = load ptr, ptr %1, align 8, !tbaa !5
  call void @usage(ptr noundef %38)
  br label %39

39:                                               ; preds = %26, %37, %23
  %.016 = phi ptr [ %4, %37 ], [ %30, %26 ], [ %4, %23 ]
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = call i32 @fileno(ptr noundef %.016) #5
  %42 = call ptr @pdb_mmap(i32 noundef %40, i32 noundef %41, i32 noundef 0) #5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %44, label %45

44:                                               ; preds = %39
  call void @perror(ptr noundef nonnull @.str.4) #6
  br label %46

45:                                               ; preds = %39
  call void @write_bitpdb(ptr noundef %.015.ph, ptr noundef nonnull %42)
  br label %46

46:                                               ; preds = %45, %44, %32, %17, %12
  %.0 = phi i32 [ 1, %17 ], [ 1, %12 ], [ 1, %44 ], [ 0, %45 ], [ 1, %32 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  ret i32 %.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: nounwind
declare i32 @__posix_getopt(i32 noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #3

declare i32 @tileset_parse(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @usage(ptr noundef) local_unnamed_addr #0

declare ptr @pdb_mmap(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

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

; Function Attrs: nounwind uwtable
declare hidden void @write_bitpdb(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 = { 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 #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 }
attributes #6 = { cold }
attributes #7 = { cold 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"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass