#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 /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, ...);
int isnotfound(char *filename) {
  int status = 0;
  int isfexists();
  char command[256];
  FILE *grepout = NULL;
  char grepline[256];
  int strreplace();
  int nlines = 0;
  if (((filename) == NULL ? 1 : (*(filename) == '\000' ? 1 : 0)))
    goto end_of_job;
  sprintf(command, "%s.err", filename);
  if (!isfexists(command)) {
    status = 1;
    goto end_of_job;
  }
  sprintf(command, "grep -i \"%s\" %s.err", filename, filename);
  grepout = popen(command, "r");
  if (grepout == NULL)
    goto end_of_job;
  while (fgets(grepline, 255, grepout) != NULL) {
    if (strreplace(grepline, "not found", "", 0, 0) > 0)
      nlines++;
    if (strreplace(grepline, "no such", "", 0, 0) > 0)
      nlines++;
  }
  if (nlines > 0)
    status = 1;
  pclose(grepout);
end_of_job:
  return (status);
}


x86 assembly (clang, -O0):
<isnotfound>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x118(%rbp)
movl   $0x0,-0x224(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a5 <isnotfound+0x45>
mov    $0x1,%al
test   $0x1,%al
jne    11d3 <isnotfound+0x73>
jmp    11d8 <isnotfound+0x78>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c4 <isnotfound+0x64>
mov    $0x1,%al
test   $0x1,%al
jne    11d3 <isnotfound+0x73>
jmp    11d8 <isnotfound+0x78>
xor    %eax,%eax
test   $0x1,%al
jne    11d3 <isnotfound+0x73>
jmp    11d8 <isnotfound+0x78>
jmp    131e <isnotfound+0x1be>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    $0x0,%al
call   1030 <isfexists@plt>
cmp    $0x0,%eax
jne    1214 <isnotfound+0xb4>
movl   $0x1,-0xc(%rbp)
jmp    131e <isnotfound+0x1be>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   1080 <sprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xdd3(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
jne    125e <isnotfound+0xfe>
jmp    131e <isnotfound+0x1be>
jmp    1263 <isnotfound+0x103>
lea    -0x220(%rbp),%rdi
mov    -0x118(%rbp),%rdx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12fe <isnotfound+0x19e>
lea    -0x220(%rbp),%rdi
lea    0xd81(%rip),%rsi
lea    0xd83(%rip),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
mov    $0x0,%al
call   1060 <strreplace@plt>
cmp    $0x0,%eax
jle    12bf <isnotfound+0x15f>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
lea    -0x220(%rbp),%rdi
lea    0xd51(%rip),%rsi
lea    0xd49(%rip),%rdx
xor    %r8d,%r8d
mov    %r8d,%ecx
mov    $0x0,%al
call   1060 <strreplace@plt>
cmp    $0x0,%eax
jle    12f9 <isnotfound+0x199>
mov    -0x224(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x224(%rbp)
jmp    1263 <isnotfound+0x103>
cmpl   $0x0,-0x224(%rbp)
jle    1312 <isnotfound+0x1b2>
movl   $0x1,-0xc(%rbp)
mov    -0x118(%rbp),%rdi
call   1040 <pclose@plt>
mov    -0xc(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isnotfound>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
xor    %r12d,%r12d
test   %rdi,%rdi
je     1298 <isnotfound+0x138>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     1298 <isnotfound+0x138>
lea    0xe7d(%rip),%rsi
xor    %r12d,%r12d
lea    0x100(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <isfexists@plt>
test   %eax,%eax
je     1285 <isnotfound+0x125>
lea    0xe3f(%rip),%rsi
lea    0x100(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <sprintf@plt>
lea    0xe32(%rip),%rsi
mov    %r14,%rdi
call   1070 <popen@plt>
test   %rax,%rax
je     1298 <isnotfound+0x138>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     128d <isnotfound+0x12d>
lea    0xe09(%rip),%r13
mov    %rsp,%rbx
lea    0xe00(%rip),%r12
xor    %ebp,%ebp
mov    %rbx,%rdi
lea    0xdea(%rip),%rsi
mov    %r13,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <strreplace@plt>
xor    %r14d,%r14d
test   %eax,%eax
setg   %r14b
add    %ebp,%r14d
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <strreplace@plt>
xor    %ebp,%ebp
test   %eax,%eax
setg   %bpl
add    %r14d,%ebp
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
jne    1220 <isnotfound+0xc0>
xor    %r12d,%r12d
test   %ebp,%ebp
setg   %r12b
jmp    1290 <isnotfound+0x130>
mov    $0x1,%r12d
jmp    1298 <isnotfound+0x138>
xor    %r12d,%r12d
mov    %r15,%rdi
call   1040 <pclose@plt>
mov    %r12d,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%s.err\00"
@.str.1 = [20 x i8] c"grep -i \22%s\22 %s.err\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"not found\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [8 x i8] c"no such\00"
define i32 @isnotfound(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca i32*
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
store i32* null, i32** %5
store i32 0, i32* %7
%8 = load i8*, i8** %2
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %11
10: ; preds = %1
br i1 true, label %18, label %19
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %11
br i1 true, label %18, label %19
17: ; preds = %11
br i1 false, label %18, label %19
18: ; preds = %17, %16, %10
br label %65
19: ; preds = %17, %16, %10
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%21 = load i8*, i8** %2
%22 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @isfexists to i32 (i8*, ...)*)(i8* %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %27, label %26
26: ; preds = %19
store i32 1, i32* %3
br label %65
27: ; preds = %19
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%29 = load i8*, i8** %2
%30 = load i8*, i8** %2
%31 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %28, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %29, i8* %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%33 = call i32* @popen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %33, i32** %5
%34 = load i32*, i32** %5
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %37
36: ; preds = %27
br label %65
37: ; preds = %27
br label %38
38: ; preds = %57, %37
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%40 = load i32*, i32** %5
%41 = call i32* @fgets(i8* %39, i32 255, i32* %40)
%42 = icmp ne i32* %41, null
br i1 %42, label %43, label %58
43: ; preds = %38
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%45 = call i32 (i8*, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, i32, ...)*)(i8* %44, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %50
50: ; preds = %47, %43
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%52 = call i32 (i8*, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, i32, ...)*)(i8* %51, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
%53 = icmp sgt i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %57
57: ; preds = %54, %50
br label %38
58: ; preds = %38
%59 = load i32, i32* %7
%60 = icmp sgt i32 %59, 0
br i1 %60, label %61, label %62
61: ; preds = %58
store i32 1, i32* %3
br label %62
62: ; preds = %61, %58
%63 = load i32*, i32** %5
%64 = call i32 @pclose(i32* %63)
br label %65
65: ; preds = %62, %36, %26, %18
%66 = load i32, i32* %3
ret i32 %66
}

LLVM IR (-O2):
@.str = [7 x i8] c"%s.err\00"
@.str.1 = [20 x i8] c"grep -i \22%s\22 %s.err\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [10 x i8] c"not found\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [8 x i8] c"no such\00"
define i32 @isnotfound(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = icmp eq i8* %0, null
br i1 %6, label %39, label %7
7: ; preds = %1
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %39, label %10
10: ; preds = %7
%11 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = call i32 (i8*, ...) bitcast (i32 (...)* @isfexists to i32 (i8*, ...)*)(i8* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %39, label %14
14: ; preds = %10
%15 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %0)
%16 = call i32* @popen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %39, label %18
18: ; preds = %14
%19 = call i32* @fgets(i8* %5, i32 255, i32* %16)
%20 = icmp eq i32* %19, null
br i1 %20, label %36, label %21
21: ; preds = %18, %21
%22 = phi i32 [ %30, %21 ], [ 0, %18 ]
%23 = call i32 (i8*, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, i32, ...)*)(i8* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
%24 = icmp sgt i32 %23, 0
%25 = zext i1 %24 to i32
%26 = add nsw i32 %22, %25
%27 = call i32 (i8*, i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @strreplace to i32 (i8*, i8*, i8*, i32, i32, ...)*)(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0), i32 0, i32 0)
%28 = icmp sgt i32 %27, 0
%29 = zext i1 %28 to i32
%30 = add nsw i32 %26, %29
%31 = call i32* @fgets(i8* %5, i32 255, i32* %16)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %21
33: ; preds = %21
%34 = icmp sgt i32 %30, 0
%35 = zext i1 %34 to i32
br label %36
36: ; preds = %33, %18
%37 = phi i32 [ 0, %18 ], [ %35, %33 ]
%38 = call i32 @pclose(i32* %16)
br label %39
39: ; preds = %10, %14, %1, %7, %36
%40 = phi i32 [ 0, %1 ], [ 0, %7 ], [ 0, %14 ], [ %37, %36 ], [ 1, %10 ]
ret i32 %40
}