#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ grep(char *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  int nmatch;
  FILE *fp;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s regexp [file ...]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  nmatch = 0;
  if (argc == 2) {
    if (grep(argv[1], stdin, NULL))
      nmatch++;
  } else {
    for (int i = 2; i < argc; i++) {
      if ((fp = fopen(argv[i], "r")) == NULL) {
        fprintf(stderr, "can't open %s\n", argv[i]);
        continue;
      }
      if (grep(argv[1], fp, (argc > 3) ? argv[i] : NULL) > 0)
        nmatch++;
      fclose(fp);
    }
  }
  return nmatch = 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    119a <main+0x4a>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11de <main+0x8e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e2e(%rip),%rax
mov    (%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <grep@plt>
cmp    $0x0,%rax
je     11d9 <main+0x89>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12bb <main+0x16b>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12b6 <main+0x166>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe19(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    123d <main+0xed>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xdec(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12a8 <main+0x158>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1270 <main+0x120>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
jmp    127b <main+0x12b>
xor    %eax,%eax
mov    %rax,-0x40(%rbp)
jmp    127b <main+0x12b>
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rdx
call   1040 <grep@plt>
cmp    $0x0,%rax
jle    129f <main+0x14f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e5 <main+0x95>
jmp    12bb <main+0x16b>
movl   $0x0,-0x14(%rbp)
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    120a <main+0xba>
mov    %edi,%r12d
cmp    $0x2,%edi
jne    1195 <main+0x45>
mov    0x8(%rbx),%rdi
mov    0x2e6e(%rip),%rax
mov    (%rax),%rsi
xor    %edx,%edx
call   1040 <grep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,%r13d
mov    $0x2,%r15d
lea    0xe78(%rip),%r14
jmp    11d2 <main+0x82>
nopw   0x0(%rax,%rax,1)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%r15,8),%rdx
lea    0xe5b(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     1184 <main+0x34>
mov    (%rbx,%r15,8),%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b0 <main+0x60>
mov    %rax,%rbp
cmp    $0x3,%r12d
jne    11f0 <main+0xa0>
xor    %edx,%edx
jmp    11f4 <main+0xa4>
mov    (%rbx,%r15,8),%rdx
mov    0x8(%rbx),%rdi
mov    %rbp,%rsi
call   1040 <grep@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    11c9 <main+0x79>
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xde3(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Usage: %s regexp [file ...]\0A\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [15 x i8] c"can't open %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %10
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = icmp eq i32 %0, 2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
br i1 %11, label %16, label %13
13: ; preds = %10
%14 = icmp eq i32 %0, 3
%15 = zext i32 %0 to i64
br label %20
16: ; preds = %10
%17 = load i8*, i8** %12
%18 = load i32*, i32** @stdin
%19 = tail call i64 @grep(i8* %17, i32* %18, i8* null)
br label %41
20: ; preds = %13, %38
%21 = phi i64 [ 2, %13 ], [ %39, %38 ]
%22 = getelementptr inbounds i8*, i8** %1, i64 %21
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %22
%29 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %28)
br label %38
30: ; preds = %20
%31 = load i8*, i8** %12
br i1 %14, label %34, label %32
32: ; preds = %30
%33 = load i8*, i8** %22
br label %34
34: ; preds = %30, %32
%35 = phi i8* [ %33, %32 ], [ null, %30 ]
%36 = tail call i64 @grep(i8* %31, i32* %24, i8* %35)
%37 = tail call i32 @fclose(i32* %24)
br label %38
38: ; preds = %34, %26
%39 = add nuw nsw i64 %21, 1
%40 = icmp eq i64 %39, %15
br i1 %40, label %41, label %20
41: ; preds = %38, %16
ret i32 0
}