#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*/ exit(int);
scalar_t__ ferror(int /*<<< orphan*/);
int find(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  char *pattern;
  int found = 0;
  if (argc == 1) {
    printf("Pattern program usage: Pattern file_1, file_2, ...\n\n");
    return 0;
  }
  pattern = *++argv;
  if (*++argv == NULL) {
    found = find(pattern, stdin);
    if (found == 1) {
      printf("\nPattern found in stdin file\n");
    }
    exit(0);
  } else {
    FILE *fp;
    char *prog;
    while (--argc > 1) {
      prog = *argv;
      if ((fp = fopen(*argv++, "r")) == NULL) {
        fprintf(stderr, "can't open %s\n", prog);
        exit(1);
      } else {
        found = find(pattern, fp);
        if (found == 1) {
          printf("Pattern found in %s file\n\n", prog);
        }
      }
    }
  }
  if (ferror(stdout)) {
    fprintf(stderr, "%s: error writing stdout\n", argv[0]);
    exit(2);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    119d <main+0x3d>
lea    0xe72(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
cmpq   $0x0,0x8(%rax)
jne    1203 <main+0xa3>
mov    -0x18(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%rsi
call   1060 <find@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    11fc <main+0x9c>
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
jmp    1208 <main+0xa8>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
cmp    $0x1,%eax
jle    12ac <main+0x14c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%rax
mov    %eax,%edi
lea    0xe13(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1276 <main+0x116>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rdx
lea    0xdee(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <find@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    12a2 <main+0x142>
mov    -0x30(%rbp),%rsi
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a7 <main+0x147>
jmp    1208 <main+0xa8>
jmp    12b1 <main+0x151>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     12ef <main+0x18f>
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd9f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
xor    %edi,%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jne    119d <main+0x2d>
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsi,%rbx
mov    0x8(%rsi),%r14
mov    0x10(%rsi),%r15
test   %r15,%r15
jne    11d9 <main+0x69>
mov    0x2e34(%rip),%rax
mov    (%rax),%rsi
mov    %r14,%rdi
call   1070 <find@plt>
cmp    $0x1,%eax
jne    127f <main+0x10f>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
jmp    127f <main+0x10f>
mov    %edi,%ebp
cmp    $0x3,%edi
jl     1268 <main+0xf8>
lea    0xe15(%rip),%rsi
mov    %r15d,%edi
call   1080 <fopen@plt>
test   %rax,%rax
je     1246 <main+0xd6>
add    $0x18,%rbx
lea    0xe0e(%rip),%r12
lea    0xdf6(%rip),%r13
mov    %r14,%rdi
mov    %rax,%rsi
call   1070 <find@plt>
cmp    $0x1,%eax
jne    1227 <main+0xb7>
mov    %r12,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x4,%ebp
jb     126c <main+0xfc>
mov    (%rbx),%r15
add    $0x8,%rbx
mov    %r15d,%edi
mov    %r13,%rsi
call   1080 <fopen@plt>
add    $0xffffffff,%ebp
test   %rax,%rax
jne    120a <main+0x9a>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
lea    0xdac(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x10,%rbx
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
call   1040 <ferror@plt>
test   %rax,%rax
jne    1286 <main+0x116>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd93(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [53 x i8] c"Pattern program usage: Pattern file_1, file_2, ...\0A\0A\00"
@stdin = global i32* null
@.str.1 = [30 x i8] c"\0APattern found in stdin file\0A\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"can't open %s\0A\00"
@.str.4 = [27 x i8] c"Pattern found in %s file\0A\0A\00"
@stdout = global i32 0
@.str.5 = [26 x i8] c"%s: error writing stdout\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
ret i32 0
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i32 1
store i8** %16, i8*** %5
%17 = load i8*, i8** %16
store i8* %17, i8** %6
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %32
22: ; preds = %14
%23 = load i8*, i8** %6
%24 = load i32*, i32** @stdin
%25 = call i32 @find(i8* %23, i32* %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp eq i32 %26, 1
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %22
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %14
br label %33
33: ; preds = %61, %32
%34 = load i32, i32* %4
%35 = add nsw i32 %34, -1
store i32 %35, i32* %4
%36 = icmp sgt i32 %35, 1
br i1 %36, label %37, label %62
37: ; preds = %33
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
store i8* %39, i8** %9
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i32 1
store i8** %41, i8*** %5
%42 = load i8*, i8** %40
%43 = ptrtoint i8* %42 to i32
%44 = call i32* @fopen(i32 %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %44, i32** %8
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %51
46: ; preds = %37
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %9
%49 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %37
%52 = load i8*, i8** %6
%53 = load i32*, i32** %8
%54 = call i32 @find(i8* %52, i32* %53)
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i8*, i8** %9
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %58)
br label %60
60: ; preds = %57, %51
br label %61
61: ; preds = %60
br label %33
62: ; preds = %33
br label %63
63: ; preds = %62
%64 = load i32, i32* @stdout
%65 = call i64 @ferror(i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %74
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 0
%71 = load i8*, i8** %70
%72 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %71)
%73 = call i32 @exit(i32 2)
unreachable
74: ; preds = %63
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [15 x i8] c"can't open %s\0A\00"
@.str.4 = [27 x i8] c"Pattern found in %s file\0A\0A\00"
@stdout = global i32 0
@.str.5 = [26 x i8] c"%s: error writing stdout\0A\00"
@str = [29 x i8] c"\0APattern found in stdin file\00"
@str.6 = [52 x i8] c"Pattern program usage: Pattern file_1, file_2, ...\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.6, i64 0, i64 0))
ret i32 0
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %6
%13 = icmp sgt i32 %0, 2
br i1 %13, label %14, label %53
14: ; preds = %12
%15 = ptrtoint i8* %10 to i64
%16 = trunc i64 %15 to i32
%17 = tail call i32* @fopen(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %29, label %19
19: ; preds = %14
%20 = getelementptr inbounds i8*, i8** %1, i64 3
br label %34
21: ; preds = %6
%22 = load i32*, i32** @stdin
%23 = tail call i32 @find(i8* %8, i32* %22)
%24 = icmp eq i32 %23, 1
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %27
27: ; preds = %25, %21
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %46, %14
%30 = phi i8* [ %10, %14 ], [ %47, %46 ]
%31 = load i32, i32* @stderr
%32 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %19, %46
%35 = phi i32* [ %17, %19 ], [ %51, %46 ]
%36 = phi i8** [ %20, %19 ], [ %48, %46 ]
%37 = phi i32 [ %0, %19 ], [ %39, %46 ]
%38 = phi i8* [ %10, %19 ], [ %47, %46 ]
%39 = add nsw i32 %37, -1
%40 = tail call i32 @find(i8* %8, i32* %35)
%41 = icmp eq i32 %40, 1
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %44
44: ; preds = %34, %42
%45 = icmp ugt i32 %37, 3
br i1 %45, label %46, label %53
46: ; preds = %44
%47 = load i8*, i8** %36
%48 = getelementptr inbounds i8*, i8** %36, i64 1
%49 = ptrtoint i8* %47 to i64
%50 = trunc i64 %49 to i32
%51 = tail call i32* @fopen(i32 %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%52 = icmp eq i32* %51, null
br i1 %52, label %29, label %34
53: ; preds = %44, %12
%54 = phi i8** [ %9, %12 ], [ %36, %44 ]
%55 = load i32, i32* @stdout
%56 = tail call i64 @ferror(i32 %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %54
%61 = tail call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %60)
%62 = tail call i32 @exit(i32 2)
unreachable
63: ; preds = %53
%64 = tail call i32 @exit(i32 0)
unreachable
}