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

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int is_spellable(char *);
int /*<<< orphan*/ stderr;
size_t strcspn(char *, char *);
int _read_and_test(const char *fn, FILE *fp, bool expected_result) {
  bool passed = true;
  char buf[512];
  while (fgets(buf, sizeof(buf), fp)) {
    buf[strcspn(buf, "\n")] = 0;
    bool result = is_spellable(buf);
    if (result != expected_result) {
      fprintf(stderr, "unexpected %s: %s\n", expected_result ? "pass" : "fail",
              buf);
      passed = false;
    }
  }
  char *message =
      passed ? "Test file '%s' passed.\n" : "TEST FILE '%s' FAILED.\n";
  fprintf(stderr, message, fn);
  return passed ? 0 : -1;
}


x86 assembly (clang, -O0):
<_read_and_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x200,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     11fa <_read_and_test+0xba>
lea    -0x220(%rbp),%rdi
lea    0xec1(%rip),%rsi
call   1040 <strcspn@plt>
movb   $0x0,-0x220(%rbp,%rax,1)
lea    -0x220(%rbp),%rdi
call   1030 <is_spellable@plt>
mov    %eax,-0x224(%rbp)
mov    -0x224(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11f5 <_read_and_test+0xb5>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%ecx
lea    0xe4d(%rip),%rdx
lea    0xe41(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    -0x220(%rbp),%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x18(%rbp)
jmp    115d <_read_and_test+0x1d>
mov    -0x18(%rbp),%edx
lea    0xe31(%rip),%rax
lea    0xe12(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x230(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
mov    -0x230(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_read_and_test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %edx,%r13d
mov    %rsi,%rbx
mov    %rdi,0x8(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11f4 <_read_and_test+0xb4>
test   %r13d,%r13d
lea    0xe97(%rip),%rax
lea    0xe8b(%rip),%r15
cmove  %rax,%r15
mov    $0x1,%r14d
lea    0xeb2(%rip),%r12
lea    0x10(%rsp),%rbp
jmp    11b5 <_read_and_test+0x75>
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     11fa <_read_and_test+0xba>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1040 <strcspn@plt>
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbp,%rdi
call   1030 <is_spellable@plt>
cmp    %r13d,%eax
je     11a0 <_read_and_test+0x60>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
xor    %r14d,%r14d
lea    0xe1b(%rip),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11a0 <_read_and_test+0x60>
mov    $0x1,%r14d
xor    %ebx,%ebx
test   %r14d,%r14d
sete   %bl
lea    0xe2c(%rip),%rax
lea    0xe0d(%rip),%rsi
cmove  %rax,%rsi
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
neg    %ebx
mov    %ebx,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"unexpected %s: %s\0A\00"
@.str.2 = [5 x i8] c"pass\00"
@.str.3 = [5 x i8] c"fail\00"
@.str.4 = [24 x i8] c"Test file '%s' passed.\0A\00"
@.str.5 = [24 x i8] c"TEST FILE '%s' FAILED.\0A\00"
define i32 @_read_and_test(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca [512 x i8]
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 1, i32* %7
br label %11
11: ; preds = %33, %3
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%13 = load i32*, i32** %5
%14 = call i64 @fgets(i8* %12, i32 512, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%18 = call i64 @strcspn(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 %18
store i8 0, i8* %19
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%21 = call i32 @is_spellable(i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = load i32, i32* %6
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %33
25: ; preds = %16
%26 = load i32, i32* @stderr
%27 = load i32, i32* %6
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31)
store i32 0, i32* %7
br label %33
33: ; preds = %25, %16
br label %11
34: ; preds = %11
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0)
store i8* %38, i8** %10
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %10
%41 = load i8*, i8** %4
%42 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* %40, i8* %41)
%43 = load i32, i32* %7
%44 = icmp ne i32 %43, 0
%45 = zext i1 %44 to i64
%46 = select i1 %44, i32 0, i32 -1
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.1 = [19 x i8] c"unexpected %s: %s\0A\00"
@.str.2 = [5 x i8] c"pass\00"
@.str.3 = [5 x i8] c"fail\00"
@.str.4 = [24 x i8] c"Test file '%s' passed.\0A\00"
@.str.5 = [24 x i8] c"TEST FILE '%s' FAILED.\0A\00"
define i32 @_read_and_test(i8* %0, i32* nocapture %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i64 @fgets(i8* %5, i32 512, i32* %1)
%7 = icmp eq i64 %6, 0
br i1 %7, label %24, label %8
8: ; preds = %3
%9 = icmp eq i32 %2, 0
%10 = select i1 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0)
br label %11
11: ; preds = %8, %20
%12 = phi i32 [ 1, %8 ], [ %21, %20 ]
%13 = call i64 @strcspn(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 @is_spellable(i8* %5)
%16 = icmp eq i32 %15, %2
br i1 %16, label %20, label %17
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %5)
br label %20
20: ; preds = %17, %11
%21 = phi i32 [ 0, %17 ], [ %12, %11 ]
%22 = call i64 @fgets(i8* %5, i32 512, i32* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %11
24: ; preds = %20, %3
%25 = phi i32 [ 1, %3 ], [ %21, %20 ]
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0)
%28 = load i32, i32* @stderr
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* %27, i8* %0)
%30 = sext i1 %26 to i32
ret i32 %30
}