#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int uint8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int read_mosaic_file(FILE *file, int width, int height, uint8_t *fcontents) {
  assert(width > 0 && height >= 0);
  assert(width < 10000 && height < 10000);
  int col_count = 0;
  int row_count = 0;
  int i = 0;
  int c;
  while ((c = fgetc(file)) != EOF) {
    if (row_count == height) {
      break;
    }
    assert(col_count <= width + 1);
    assert(row_count < height);
    if (col_count < width) {
      if (c >= '0' && c <= '9') {
        fcontents[i] = c - '0';
        i++;
        col_count++;
      } else if (c == '.') {
        fcontents[i] = 10;
        i++;
        col_count++;
      } else if (c == '\r' || c == '\n') {
        fprintf(stderr, "ERROR line %d too short!\n", row_count + 3);
        return EXIT_FAILURE;
      } else {
        fprintf(stderr, "ERROR invalid symbol '%c' in line %d!\n", c,
                row_count + 3);
        return EXIT_FAILURE;
      }
    } else if (col_count == width) {
      if (c == '\n') {
        col_count = 0;
        row_count++;
      } else if (c == '\r') {
        col_count++;
      } else {
        fprintf(stderr, "ERROR line %d too long!\n", row_count + 3);
        return EXIT_FAILURE;
      }
    } else {
      assert(col_count == width + 1);
      if (c != '\n') {
        fprintf(stderr, "ERROR expected new line character at line %d\n",
                row_count + 3);
        return EXIT_FAILURE;
      }
      col_count = 0;
      row_count++;
    }
  }
  if (feof(file)) {
    if (i != width * height) {
      fputs("ERROR too few lines\n", stderr);
      return EXIT_FAILURE;
    }
  } else if (ferror(file)) {
    fputs("I/O error when reading\n", stderr);
    return EXIT_FAILURE;
  } else {
    fputs("ERROR too many lines\n", stderr);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<read_mosaic_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x31(%rbp)
jle    118f <read_mosaic_file+0x2f>
cmpl   $0x0,-0x18(%rbp)
setge  %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
xor    %eax,%eax
cmpl   $0x2710,-0x14(%rbp)
mov    %al,-0x32(%rbp)
jge    11bb <read_mosaic_file+0x5b>
cmpl   $0x2710,-0x18(%rbp)
setl   %al
mov    %al,-0x32(%rbp)
mov    -0x32(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x30(%rbp)
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
je     140e <read_mosaic_file+0x2ae>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1209 <read_mosaic_file+0xa9>
jmp    140e <read_mosaic_file+0x2ae>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x28(%rbp),%eax
cmp    -0x18(%rbp),%eax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1329 <read_mosaic_file+0x1c9>
cmpl   $0x30,-0x30(%rbp)
jl     127c <read_mosaic_file+0x11c>
cmpl   $0x39,-0x30(%rbp)
jg     127c <read_mosaic_file+0x11c>
mov    -0x30(%rbp),%edx
sub    $0x30,%edx
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1324 <read_mosaic_file+0x1c4>
cmpl   $0x2e,-0x30(%rbp)
jne    12ac <read_mosaic_file+0x14c>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movl   $0xa,(%rax,%rcx,4)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    131f <read_mosaic_file+0x1bf>
cmpl   $0xd,-0x30(%rbp)
je     12c0 <read_mosaic_file+0x160>
cmpl   $0xa,-0x30(%rbp)
jne    12ee <read_mosaic_file+0x18e>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
add    $0x3,%edx
lea    0xd2a(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
mov    0x2ce3(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x28(%rbp),%ecx
add    $0x3,%ecx
lea    0xd13(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
jmp    1324 <read_mosaic_file+0x1c4>
jmp    1409 <read_mosaic_file+0x2a9>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    13a4 <read_mosaic_file+0x244>
cmpl   $0xa,-0x30(%rbp)
jne    1354 <read_mosaic_file+0x1f4>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    139f <read_mosaic_file+0x23f>
cmpl   $0xd,-0x30(%rbp)
jne    136c <read_mosaic_file+0x20c>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    139a <read_mosaic_file+0x23a>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
add    $0x3,%edx
lea    0xcbf(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
jmp    139f <read_mosaic_file+0x23f>
jmp    1404 <read_mosaic_file+0x2a4>
mov    -0x24(%rbp),%eax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpl   $0xa,-0x30(%rbp)
je     13f4 <read_mosaic_file+0x294>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
add    $0x3,%edx
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2be6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
movl   $0x0,-0x24(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1409 <read_mosaic_file+0x2a9>
jmp    11dd <read_mosaic_file+0x7d>
mov    -0x10(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%rax
je     145e <read_mosaic_file+0x2fe>
mov    -0x2c(%rbp),%eax
mov    -0x14(%rbp),%ecx
imul   -0x18(%rbp),%ecx
cmp    %ecx,%eax
je     1459 <read_mosaic_file+0x2f9>
mov    0x2b9e(%rip),%rax
mov    (%rax),%esi
lea    0xc45(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2b81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
jmp    14bd <read_mosaic_file+0x35d>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1497 <read_mosaic_file+0x337>
mov    0x2b60(%rip),%rax
mov    (%rax),%esi
lea    0xc1c(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2b43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
mov    0x2b3a(%rip),%rax
mov    (%rax),%esi
lea    0xc0e(%rip),%rdi
call   1040 <fputs@plt>
mov    0x2b1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14c9 <read_mosaic_file+0x369>
mov    0x2b04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_mosaic_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,0x8(%rsp)
mov    %edx,%r13d
mov    %esi,%ebx
mov    %rdi,%rbp
test   %esi,%esi
setg   %al
test   %edx,%edx
setns  %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
mov    %rbx,(%rsp)
cmp    $0x2710,%ebx
setl   %al
cmp    $0x2710,%r13d
setl   %cl
and    %al,%cl
movzbl %cl,%edi
call   1060 <assert@plt>
mov    %rbp,%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    0x2e27(%rip),%rax
xor    %r12d,%r12d
cmp    (%rax),%ebx
mov    %rbp,0x10(%rsp)
je     12d0 <read_mosaic_file+0x170>
test   %r13d,%r13d
je     12d0 <read_mosaic_file+0x170>
mov    (%rsp),%rax
lea    0x1(%rax),%r14d
xor    %r12d,%r12d
xor    %ebp,%ebp
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
xor    %edi,%edi
cmp    %r14d,%r15d
setle  %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmp    %r13d,%ebp
setl   %dil
call   1060 <assert@plt>
cmp    (%rsp),%r15d
jge    1230 <read_mosaic_file+0xd0>
lea    -0x30(%rbx),%eax
cmp    $0x9,%eax
ja     1250 <read_mosaic_file+0xf0>
movslq %r12d,%rcx
mov    0x8(%rsp),%rdx
mov    %eax,(%rdx,%rcx,4)
jmp    1269 <read_mosaic_file+0x109>
nopw   0x0(%rax,%rax,1)
jne    1280 <read_mosaic_file+0x120>
cmp    $0xd,%ebx
je     129f <read_mosaic_file+0x13f>
cmp    $0xa,%ebx
je     1297 <read_mosaic_file+0x137>
jmp    138b <read_mosaic_file+0x22b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
cmp    $0x2e,%ebx
jne    1329 <read_mosaic_file+0x1c9>
movslq %r12d,%r12
mov    0x8(%rsp),%rax
movl   $0xa,(%rax,%r12,4)
add    $0x1,%r12d
add    $0x1,%r15d
jmp    12b0 <read_mosaic_file+0x150>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %edi,%edi
cmp    %r14d,%r15d
sete   %dil
call   1060 <assert@plt>
cmp    $0xa,%ebx
jne    1356 <read_mosaic_file+0x1f6>
add    $0x1,%ebp
xor    %r15d,%r15d
jmp    12b0 <read_mosaic_file+0x150>
mov    %r14d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x10(%rsp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ebx
mov    0x2d25(%rip),%rax
cmp    (%rax),%ebx
je     12d0 <read_mosaic_file+0x170>
cmp    %r13d,%ebp
jne    11f0 <read_mosaic_file+0x90>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     12f8 <read_mosaic_file+0x198>
imul   (%rsp),%r13d
cmp    %r13d,%r12d
jne    1317 <read_mosaic_file+0x1b7>
mov    0x2cd5(%rip),%rax
jmp    13ae <read_mosaic_file+0x24e>
mov    %rbx,%rdi
call   1030 <ferror@plt>
mov    0x2cd1(%rip),%rcx
mov    (%rcx),%esi
test   %rax,%rax
je     1348 <read_mosaic_file+0x1e8>
lea    0xd88(%rip),%rdi
jmp    134f <read_mosaic_file+0x1ef>
mov    0x2cba(%rip),%rax
mov    (%rax),%esi
lea    0xd61(%rip),%rdi
jmp    134f <read_mosaic_file+0x1ef>
cmp    $0xa,%ebx
je     1333 <read_mosaic_file+0x1d3>
cmp    $0xd,%ebx
jne    136b <read_mosaic_file+0x20b>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
add    $0x3,%ebp
lea    0xcba(%rip),%rsi
jmp    139e <read_mosaic_file+0x23e>
lea    0xd66(%rip),%rdi
call   1040 <fputs@plt>
jmp    13a7 <read_mosaic_file+0x247>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
add    $0x3,%ebp
lea    0xcf1(%rip),%rsi
jmp    139e <read_mosaic_file+0x23e>
mov    0x2c66(%rip),%rax
mov    (%rax),%edi
add    $0x3,%ebp
lea    0xc9c(%rip),%rsi
mov    %ebx,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    13a7 <read_mosaic_file+0x247>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
add    $0x3,%ebp
lea    0xca3(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2c22(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"ERROR line %d too short!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"ERROR invalid symbol '%c' in line %d!\0A\00"
@.str.2 = [25 x i8] c"ERROR line %d too long!\0A\00"
@.str.3 = [46 x i8] c"ERROR expected new line character at line %d\0A\00"
@.str.4 = [21 x i8] c"ERROR too few lines\0A\00"
@.str.5 = [24 x i8] c"I/O error when reading\0A\00"
@.str.6 = [22 x i8] c"ERROR too many lines\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @read_mosaic_file(i32* %0, i32 %1, i32 %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32* %3, i32** %9
%14 = load i32, i32* %7
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %4
%17 = load i32, i32* %8
%18 = icmp sge i32 %17, 0
br label %19
19: ; preds = %16, %4
%20 = phi i1 [ false, %4 ], [ %18, %16 ]
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32, i32* %7
%24 = icmp slt i32 %23, 10000
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 10000
br label %28
28: ; preds = %25, %19
%29 = phi i1 [ false, %19 ], [ %27, %25 ]
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %32
32: ; preds = %150, %28
%33 = load i32*, i32** %6
%34 = call i32 @fgetc(i32* %33)
store i32 %34, i32* %13
%35 = load i32, i32* @EOF
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %151
37: ; preds = %32
%38 = load i32, i32* %11
%39 = load i32, i32* %8
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %37
br label %151
42: ; preds = %37
%43 = load i32, i32* %10
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
%46 = icmp sle i32 %43, %45
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i32, i32* %11
%50 = load i32, i32* %8
%51 = icmp slt i32 %49, %50
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i32, i32* %10
%55 = load i32, i32* %7
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %107
57: ; preds = %42
%58 = load i32, i32* %13
%59 = icmp sge i32 %58, 48
br i1 %59, label %60, label %74
60: ; preds = %57
%61 = load i32, i32* %13
%62 = icmp sle i32 %61, 57
br i1 %62, label %63, label %74
63: ; preds = %60
%64 = load i32, i32* %13
%65 = sub nsw i32 %64, 48
%66 = load i32*, i32** %9
%67 = load i32, i32* %12
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i32, i32* %66, i64 %68
store i32 %65, i32* %69
%70 = load i32, i32* %12
%71 = add nsw i32 %70, 1
store i32 %71, i32* %12
%72 = load i32, i32* %10
%73 = add nsw i32 %72, 1
store i32 %73, i32* %10
br label %106
74: ; preds = %60, %57
%75 = load i32, i32* %13
%76 = icmp eq i32 %75, 46
br i1 %76, label %77, label %86
77: ; preds = %74
%78 = load i32*, i32** %9
%79 = load i32, i32* %12
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds i32, i32* %78, i64 %80
store i32 10, i32* %81
%82 = load i32, i32* %12
%83 = add nsw i32 %82, 1
store i32 %83, i32* %12
%84 = load i32, i32* %10
%85 = add nsw i32 %84, 1
store i32 %85, i32* %10
br label %105
86: ; preds = %74
%87 = load i32, i32* %13
%88 = icmp eq i32 %87, 13
br i1 %88, label %92, label %89
89: ; preds = %86
%90 = load i32, i32* %13
%91 = icmp eq i32 %90, 10
br i1 %91, label %92, label %98
92: ; preds = %89, %86
%93 = load i32, i32* @stderr
%94 = load i32, i32* %11
%95 = add nsw i32 %94, 3
%96 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %95)
%97 = load i32, i32* @EXIT_FAILURE
store i32 %97, i32* %5
br label %180
98: ; preds = %89
%99 = load i32, i32* @stderr
%100 = load i32, i32* %13
%101 = load i32, i32* %11
%102 = add nsw i32 %101, 3
%103 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %100, i32 %102)
%104 = load i32, i32* @EXIT_FAILURE
store i32 %104, i32* %5
br label %180
105: ; preds = %77
br label %106
106: ; preds = %105, %63
br label %150
107: ; preds = %42
%108 = load i32, i32* %10
%109 = load i32, i32* %7
%110 = icmp eq i32 %108, %109
br i1 %110, label %111, label %131
111: ; preds = %107
%112 = load i32, i32* %13
%113 = icmp eq i32 %112, 10
br i1 %113, label %114, label %117
114: ; preds = %111
store i32 0, i32* %10
%115 = load i32, i32* %11
%116 = add nsw i32 %115, 1
store i32 %116, i32* %11
br label %130
117: ; preds = %111
%118 = load i32, i32* %13
%119 = icmp eq i32 %118, 13
br i1 %119, label %120, label %123
120: ; preds = %117
%121 = load i32, i32* %10
%122 = add nsw i32 %121, 1
store i32 %122, i32* %10
br label %129
123: ; preds = %117
%124 = load i32, i32* @stderr
%125 = load i32, i32* %11
%126 = add nsw i32 %125, 3
%127 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %126)
%128 = load i32, i32* @EXIT_FAILURE
store i32 %128, i32* %5
br label %180
129: ; preds = %120
br label %130
130: ; preds = %129, %114
br label %149
131: ; preds = %107
%132 = load i32, i32* %10
%133 = load i32, i32* %7
%134 = add nsw i32 %133, 1
%135 = icmp eq i32 %132, %134
%136 = zext i1 %135 to i32
%137 = call i32 @assert(i32 %136)
%138 = load i32, i32* %13
%139 = icmp ne i32 %138, 10
br i1 %139, label %140, label %146
140: ; preds = %131
%141 = load i32, i32* @stderr
%142 = load i32, i32* %11
%143 = add nsw i32 %142, 3
%144 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %141, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %143)
%145 = load i32, i32* @EXIT_FAILURE
store i32 %145, i32* %5
br label %180
146: ; preds = %131
store i32 0, i32* %10
%147 = load i32, i32* %11
%148 = add nsw i32 %147, 1
store i32 %148, i32* %11
br label %149
149: ; preds = %146, %130
br label %150
150: ; preds = %149, %106
br label %32
151: ; preds = %41, %32
%152 = load i32*, i32** %6
%153 = call i64 @feof(i32* %152)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %166
155: ; preds = %151
%156 = load i32, i32* %12
%157 = load i32, i32* %7
%158 = load i32, i32* %8
%159 = mul nsw i32 %157, %158
%160 = icmp ne i32 %156, %159
br i1 %160, label %161, label %165
161: ; preds = %155
%162 = load i32, i32* @stderr
%163 = call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %162)
%164 = load i32, i32* @EXIT_FAILURE
store i32 %164, i32* %5
br label %180
165: ; preds = %155
br label %178
166: ; preds = %151
%167 = load i32*, i32** %6
%168 = call i64 @ferror(i32* %167)
%169 = icmp ne i64 %168, 0
br i1 %169, label %170, label %174
170: ; preds = %166
%171 = load i32, i32* @stderr
%172 = call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %171)
%173 = load i32, i32* @EXIT_FAILURE
store i32 %173, i32* %5
br label %180
174: ; preds = %166
%175 = load i32, i32* @stderr
%176 = call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %175)
%177 = load i32, i32* @EXIT_FAILURE
store i32 %177, i32* %5
br label %180
178: ; preds = %165
%179 = load i32, i32* @EXIT_SUCCESS
store i32 %179, i32* %5
br label %180
180: ; preds = %178, %174, %170, %161, %140, %123, %98, %92
%181 = load i32, i32* %5
ret i32 %181
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [26 x i8] c"ERROR line %d too short!\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [39 x i8] c"ERROR invalid symbol '%c' in line %d!\0A\00"
@.str.2 = [25 x i8] c"ERROR line %d too long!\0A\00"
@.str.3 = [46 x i8] c"ERROR expected new line character at line %d\0A\00"
@.str.4 = [21 x i8] c"ERROR too few lines\0A\00"
@.str.5 = [24 x i8] c"I/O error when reading\0A\00"
@.str.6 = [22 x i8] c"ERROR too many lines\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @read_mosaic_file(i32* nocapture %0, i32 %1, i32 %2, i32* nocapture writeonly %3) {
%5 = icmp sgt i32 %1, 0
%6 = icmp sgt i32 %2, -1
%7 = and i1 %5, %6
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp slt i32 %1, 10000
%11 = icmp slt i32 %2, 10000
%12 = and i1 %10, %11
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @fgetc(i32* %0)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
%18 = icmp eq i32 %2, 0
%19 = or i1 %17, %18
br i1 %19, label %85, label %20
20: ; preds = %4
%21 = add nsw i32 %1, 1
br label %22
22: ; preds = %20, %76
%23 = phi i32 [ %15, %20 ], [ %80, %76 ]
%24 = phi i32 [ 0, %20 ], [ %79, %76 ]
%25 = phi i32 [ 0, %20 ], [ %78, %76 ]
%26 = phi i32 [ 0, %20 ], [ %77, %76 ]
%27 = icmp sle i32 %26, %21
%28 = zext i1 %27 to i32
%29 = tail call i32 @assert(i32 %28)
%30 = icmp slt i32 %25, %2
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = icmp slt i32 %26, %1
br i1 %33, label %34, label %56
34: ; preds = %22
%35 = add i32 %23, -48
%36 = icmp ult i32 %35, 10
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = sext i32 %24 to i64
%39 = getelementptr inbounds i32, i32* %3, i64 %38
store i32 %35, i32* %39
%40 = add nsw i32 %24, 1
%41 = add nsw i32 %26, 1
br label %76
42: ; preds = %34
switch i32 %23, label %52 [
i32 46, label %43
i32 13, label %48
i32 10, label %48
]
43: ; preds = %42
%44 = sext i32 %24 to i64
%45 = getelementptr inbounds i32, i32* %3, i64 %44
store i32 10, i32* %45
%46 = add nsw i32 %24, 1
%47 = add nsw i32 %26, 1
br label %76
48: ; preds = %42, %42
%49 = load i32, i32* @stderr
%50 = add nsw i32 %25, 3
%51 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %50)
br label %103
52: ; preds = %42
%53 = load i32, i32* @stderr
%54 = add nsw i32 %25, 3
%55 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %23, i32 %54)
br label %103
56: ; preds = %22
%57 = icmp eq i32 %26, %1
br i1 %57, label %58, label %65
58: ; preds = %56
switch i32 %23, label %61 [
i32 10, label %59
i32 13, label %76
]
59: ; preds = %58
%60 = add nsw i32 %25, 1
br label %76
61: ; preds = %58
%62 = load i32, i32* @stderr
%63 = add nsw i32 %25, 3
%64 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %63)
br label %103
65: ; preds = %56
%66 = icmp eq i32 %26, %21
%67 = zext i1 %66 to i32
%68 = tail call i32 @assert(i32 %67)
%69 = icmp eq i32 %23, 10
br i1 %69, label %74, label %70
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = add nsw i32 %25, 3
%73 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0), i32 %72)
br label %103
74: ; preds = %65
%75 = add nsw i32 %25, 1
br label %76
76: ; preds = %58, %74, %59, %37, %43
%77 = phi i32 [ %41, %37 ], [ %47, %43 ], [ 0, %59 ], [ 0, %74 ], [ %21, %58 ]
%78 = phi i32 [ %25, %37 ], [ %25, %43 ], [ %60, %59 ], [ %75, %74 ], [ %25, %58 ]
%79 = phi i32 [ %40, %37 ], [ %46, %43 ], [ %24, %59 ], [ %24, %74 ], [ %24, %58 ]
%80 = tail call i32 @fgetc(i32* %0)
%81 = load i32, i32* @EOF
%82 = icmp eq i32 %80, %81
%83 = icmp eq i32 %78, %2
%84 = select i1 %82, i1 true, i1 %83
br i1 %84, label %85, label %22
85: ; preds = %76, %4
%86 = phi i32 [ 0, %4 ], [ %79, %76 ]
%87 = tail call i64 @feof(i32* %0)
%88 = icmp eq i64 %87, 0
br i1 %88, label %95, label %89
89: ; preds = %85
%90 = mul nsw i32 %2, %1
%91 = icmp eq i32 %86, %90
br i1 %91, label %103, label %92
92: ; preds = %89
%93 = load i32, i32* @stderr
%94 = tail call i32 @fputs(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %93)
br label %103
95: ; preds = %85
%96 = tail call i64 @ferror(i32* %0)
%97 = icmp eq i64 %96, 0
%98 = load i32, i32* @stderr
br i1 %97, label %101, label %99
99: ; preds = %95
%100 = tail call i32 @fputs(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %98)
br label %103
101: ; preds = %95
%102 = tail call i32 @fputs(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %98)
br label %103
103: ; preds = %89, %101, %99, %92, %70, %61, %52, %48
%104 = phi i32* [ @EXIT_FAILURE, %92 ], [ @EXIT_FAILURE, %99 ], [ @EXIT_FAILURE, %101 ], [ @EXIT_FAILURE, %48 ], [ @EXIT_FAILURE, %52 ], [ @EXIT_FAILURE, %61 ], [ @EXIT_FAILURE, %70 ], [ @EXIT_SUCCESS, %89 ]
%105 = load i32, i32* %104
ret i32 %105
}