#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
void read_file(char filename[], char pattern[9][9]) {
  FILE *fp;
  char line[BUFSIZ];
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fprintf(stderr, "cannot open pattern file '%s'\n", filename);
    exit(EXIT_FAILURE);
  }
  for (int i = 0; i < 9; i++) {
    fgets(line, sizeof line, fp);
    for (int j = 0; j < 9; j++) {
      pattern[i][j] = line[j];
    }
  }
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c6 <read_file+0x86>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe4f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x9,-0x2c(%rbp)
jge    123d <read_file+0xfd>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rax
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
call   1030 <fgets@plt>
movl   $0x0,-0x30(%rbp)
cmpl   $0x9,-0x30(%rbp)
jge    122a <read_file+0xea>
mov    -0x38(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
imul   $0x9,%rcx,%rcx
add    %rcx,%rax
movslq -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11f1 <read_file+0xb1>
jmp    122f <read_file+0xef>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cd <read_file+0x8d>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r13
mov    0x2e7d(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe8a(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     1291 <read_file+0x151>
mov    %rax,%r12
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,(%r15)
mov    0x8(%rbx),%al
mov    %al,0x8(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x9(%r15)
mov    0x8(%rbx),%al
mov    %al,0x11(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x12(%r15)
mov    0x8(%rbx),%al
mov    %al,0x1a(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x1b(%r15)
mov    0x8(%rbx),%al
mov    %al,0x23(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x24(%r15)
mov    0x8(%rbx),%al
mov    %al,0x2c(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x2d(%r15)
mov    0x8(%rbx),%al
mov    %al,0x35(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x36(%r15)
mov    0x8(%rbx),%al
mov    %al,0x3e(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x3f(%r15)
mov    0x8(%rbx),%al
mov    %al,0x47(%r15)
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %r12,%rdx
call   1030 <fgets@plt>
mov    (%rbx),%rax
mov    %rax,0x48(%r15)
mov    0x8(%rbx),%al
mov    %al,0x50(%r15)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
mov    %r13,%rdx
call   1040 <fprintf@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"cannot open pattern file '%s'\0A\00"
@EXIT_FAILURE = global i32 0
define void @read_file(i8* %0, [9 x i8]* %1) {
%3 = alloca i8*
%4 = alloca [9 x i8]*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store [9 x i8]* %1, [9 x i8]** %4
%10 = load i32, i32* @BUFSIZ
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %6
%13 = alloca i8, i64 %11
store i64 %11, i64* %7
%14 = load i8*, i8** %3
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %5
%16 = load i32*, i32** %5
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %24
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %3
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
store i32 0, i32* %8
br label %25
25: ; preds = %51, %24
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 9
br i1 %27, label %28, label %54
28: ; preds = %25
%29 = trunc i64 %11 to i32
%30 = load i32*, i32** %5
%31 = call i32 @fgets(i8* %13, i32 %29, i32* %30)
store i32 0, i32* %9
br label %32
32: ; preds = %47, %28
%33 = load i32, i32* %9
%34 = icmp slt i32 %33, 9
br i1 %34, label %35, label %50
35: ; preds = %32
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %13, i64 %37
%39 = load i8, i8* %38
%40 = load [9 x i8]*, [9 x i8]** %4
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [9 x i8], [9 x i8]* %40, i64 %42
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [9 x i8], [9 x i8]* %43, i64 0, i64 %45
store i8 %39, i8* %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %32
50: ; preds = %32
br label %51
51: ; preds = %50
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %25
54: ; preds = %25
%55 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"cannot open pattern file '%s'\0A\00"
@EXIT_FAILURE = global i32 0
define void @read_file(i8* %0, [9 x i8]* nocapture writeonly %1) {
%3 = load i32, i32* @BUFSIZ
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %27, label %8
8: ; preds = %2
%9 = getelementptr [9 x i8], [9 x i8]* %1, i64 0, i64 0
%10 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%11 = getelementptr [9 x i8], [9 x i8]* %1, i64 1, i64 0
%12 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%13 = getelementptr [9 x i8], [9 x i8]* %1, i64 2, i64 0
%14 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%15 = getelementptr [9 x i8], [9 x i8]* %1, i64 3, i64 0
%16 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%17 = getelementptr [9 x i8], [9 x i8]* %1, i64 4, i64 0
%18 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%19 = getelementptr [9 x i8], [9 x i8]* %1, i64 5, i64 0
%20 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%21 = getelementptr [9 x i8], [9 x i8]* %1, i64 6, i64 0
%22 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%23 = getelementptr [9 x i8], [9 x i8]* %1, i64 7, i64 0
%24 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
%25 = getelementptr [9 x i8], [9 x i8]* %1, i64 8, i64 0
%26 = call i32 @fgets(i8* %5, i32 %3, i32* %6)
ret void
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%30 = load i32, i32* @EXIT_FAILURE
%31 = tail call i32 @exit(i32 %30)
unreachable
}