#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *gets(char *);
int isPresent(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char **argv) {
  if (argc != 2) {
    printf("Usage : mygrep {String to Search} <{File Name}\n");
    exit(0);
  }
  char search[256];
  strcpy(search, "");
  int i;
  for (i = 1; i < argc; i++) {
    strcat(search, argv[i]);
    if (i != (argc - 1))
      strcat(search, " ");
  }
  char file[256];
  strcpy(file, "");
  while (gets(file) != NULL) {
    if (isPresent(file, search) == 1) {
      printf("%s\n", file);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1198 <main+0x38>
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x114(%rbp)
mov    -0x114(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    121f <main+0xbf>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x114(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1070 <strcat@plt>
mov    -0x114(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     1206 <main+0xa6>
lea    -0x110(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1070 <strcat@plt>
jmp    120b <main+0xab>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    11b5 <main+0x55>
lea    -0x220(%rbp),%rdi
lea    0xe08(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x220(%rbp),%rdi
call   1050 <gets@plt>
cmp    $0x0,%rax
je     127e <main+0x11e>
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1060 <isPresent@plt>
cmp    $0x1,%eax
jne    1279 <main+0x119>
lea    -0x220(%rbp),%rsi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1232 <main+0xd2>
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
cmp    $0x2,%edi
jne    1206 <main+0xa6>
mov    %rsi,%rbx
lea    0xeaf(%rip),%r14
lea    0x100(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    0x8(%rbx),%rsi
mov    %r15,%rdi
call   1070 <strcat@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11f7 <main+0x97>
mov    %rsp,%rbx
lea    0x100(%rsp),%r14
jmp    11dd <main+0x7d>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <gets@plt>
test   %rax,%rax
je     11f7 <main+0x97>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <isPresent@plt>
cmp    $0x1,%eax
jne    11d0 <main+0x70>
mov    %rbx,%rdi
call   1040 <puts@plt>
jmp    11d0 <main+0x70>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [48 x i8] c"Usage : mygrep {String to Search} <{File Name}\0A\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c" \00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca i32
%8 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %17
17: ; preds = %37, %14
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%23 = load i8**, i8*** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strcat(i8* %22, i8* %27)
%29 = load i32, i32* %7
%30 = load i32, i32* %4
%31 = sub nsw i32 %30, 1
%32 = icmp ne i32 %29, %31
br i1 %32, label %33, label %36
33: ; preds = %21
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %33, %21
br label %37
37: ; preds = %36
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %17
40: ; preds = %17
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %55, %40
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%45 = call i32* @gets(i8* %44)
%46 = icmp ne i32* %45, null
br i1 %46, label %47, label %56
47: ; preds = %43
%48 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%50 = call i32 @isPresent(i8* %48, i8* %49)
%51 = icmp eq i32 %50, 1
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %53)
br label %55
55: ; preds = %52, %47
br label %43
56: ; preds = %43
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [1 x i8] zeroinitializer
@str = [47 x i8] c"Usage : mygrep {String to Search} <{File Name}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = icmp eq i32 %0, 2
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%11 = call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strcat(i8* %10, i8* %13)
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32* @gets(i8* %15)
%18 = icmp eq i32* %17, null
br i1 %18, label %27, label %19
19: ; preds = %9, %24
%20 = call i32 @isPresent(i8* %15, i8* %10)
%21 = icmp eq i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @puts(i8* %15)
br label %24
24: ; preds = %22, %19
%25 = call i32* @gets(i8* %15)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %19
27: ; preds = %24, %9
ret i32 0
}