#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 */

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int write(int, char *, int);
int should_skip(int fd, char *fname, int len) {
  char buf[4096];
  int sz;
  strncpy(buf, fname, len);
  buf[len - 1] = '\n';
  buf[len] = '\0';
  sz = write(fd, buf, len);
  assert(sz > 0);
  sz = read(fd, buf, 4095);
  assert(sz > 0);
  buf[sz] = '\0';
  if (strncmp(buf, "ignore", sz - 1) == 0)
    return 1;
  if (strncmp(buf, "index", sz - 1) == 0)
    return 0;
  fprintf(stderr,
          "Bad filter response: %s\n"
          "currently only 'ignore' and 'index' are supported.\n",
          buf);
  return 1;
}


x86 assembly (clang, -O0):
<should_skip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0xa,-0x1020(%rbp,%rax,1)
0a
movslq -0x14(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
mov    -0x8(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <write@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0xfff,%edx
call   1060 <read@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movslq -0x1024(%rbp),%rax
movb   $0x0,-0x1020(%rbp,%rax,1)
lea    -0x1020(%rbp),%rdi
mov    -0x1024(%rbp),%edx
sub    $0x1,%edx
lea    0xddc(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    123f <should_skip+0xdf>
movl   $0x1,-0x4(%rbp)
jmp    1294 <should_skip+0x134>
lea    -0x1020(%rbp),%rdi
mov    -0x1024(%rbp),%edx
sub    $0x1,%edx
lea    0xdb1(%rip),%rsi
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    1271 <should_skip+0x111>
movl   $0x0,-0x4(%rbp)
jmp    1294 <should_skip+0x134>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
lea    -0x1020(%rbp),%rdx
lea    0xd85(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<should_skip>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %edx,%ebx
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <strncpy@plt>
movslq %ebx,%rdx
movw   $0xa,-0x1(%rdx,%r14,1)
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <write@plt>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1070 <assert@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xfff,%edx
call   1060 <read@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1070 <assert@plt>
movslq %ebx,%rbx
movb   $0x0,(%rsp,%rbx,1)
add    $0xffffffff,%ebx
lea    0xe35(%rip),%rsi
mov    %r14,%rdi
mov    %ebx,%edx
call   1040 <strncmp@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1211 <should_skip+0xb1>
lea    0xe21(%rip),%rsi
mov    %rsp,%rdi
mov    %ebx,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     120f <should_skip+0xaf>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe08(%rip),%rsi
mov    %rsp,%rdx
call   1080 <fprintf@plt>
jmp    1211 <should_skip+0xb1>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"ignore\00"
@.str.1 = [6 x i8] c"index\00"
@stderr = global i32 0
@.str.2 = [76 x i8] c"Bad filter response: %s\0Acurrently only 'ignore' and 'index' are supported.\0A\00"
define i32 @should_skip(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i32
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call i32 @strncpy(i8* %10, i8* %11, i32 %12)
%14 = load i32, i32* %7
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %16
store i8 10, i8* %17
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %19
store i8 0, i8* %20
%21 = load i32, i32* %5
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call i32 @write(i32 %21, i8* %22, i32 %23)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp sgt i32 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* %5
%30 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 4095)
store i32 %31, i32* %9
%32 = load i32, i32* %9
%33 = icmp sgt i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%40 = load i32, i32* %9
%41 = sub nsw i32 %40, 1
%42 = call i64 @strncmp(i8* %39, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %3
store i32 1, i32* %4
br label %56
45: ; preds = %3
%46 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%47 = load i32, i32* %9
%48 = sub nsw i32 %47, 1
%49 = call i64 @strncmp(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %45
store i32 0, i32* %4
br label %56
52: ; preds = %45
%53 = load i32, i32* @stderr
%54 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%55 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0), i8* %54)
store i32 1, i32* %4
br label %56
56: ; preds = %52, %51, %44
%57 = load i32, i32* %4
ret i32 %57
}

LLVM IR (-O2):
@.str = [7 x i8] c"ignore\00"
@.str.1 = [6 x i8] c"index\00"
@stderr = global i32 0
@.str.2 = [76 x i8] c"Bad filter response: %s\0Acurrently only 'ignore' and 'index' are supported.\0A\00"
define i32 @should_skip(i32 %0, i8* %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = call i32 @strncpy(i8* %5, i8* %1, i32 %2)
%7 = add nsw i32 %2, -1
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %8
store i8 10, i8* %9
%10 = sext i32 %2 to i64
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %10
store i8 0, i8* %11
%12 = call i32 @write(i32 %0, i8* %5, i32 %2)
%13 = icmp sgt i32 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @read(i32 %0, i8* %5, i32 4095)
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = sext i32 %16 to i64
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %20
store i8 0, i8* %21
%22 = add nsw i32 %16, -1
%23 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %3
%26 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.2, i64 0, i64 0), i8* %5)
br label %31
31: ; preds = %25, %3, %28
%32 = phi i32 [ 1, %28 ], [ 1, %3 ], [ 0, %25 ]
ret i32 %32
}