#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 /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char *argv[]) {
  char line[256] = {0};
  int found = 0;
  FILE *f = NULL;
  printf("\nThis program finds a pattern into the input lines\nThe patern is "
         "give as a command line arguments.");
  if (argc < 2) {
    printf("\nerror: Correct usage\n\t./exec_file pattern [optional] "
           "named_files_where_to_find_pattern");
    exit(0);
  }
  while (argc-- > 2) {
    if ((f = fopen(argv[argc], "r")) == NULL) {
      printf("\nerror: Couldn't open file: %s", argv[argc]);
      continue;
    }
    found = 0;
    memset(line, 0, 256);
    while (fgets(line, 256, f) != NULL) {
      if (strstr(line, argv[1]) != NULL) {
        if (!found)
          printf("\nIn file %s", argv[argc]);
        printf("\n\t%s", line);
        memset(line, 0, 256);
        found++;
      }
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
movl   $0x0,-0x114(%rbp)
movq   $0x0,-0x120(%rbp)
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x2,-0x8(%rbp)
jge    11ce <main+0x6e>
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11d3 <main+0x73>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x2,%eax
jle    12f4 <main+0x194>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xec1(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
jne    122f <main+0xcf>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d3 <main+0x73>
movl   $0x0,-0x114(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x120(%rbp),%rdx
mov    $0x100,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     12ef <main+0x18f>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     12ea <main+0x18a>
cmpl   $0x0,-0x114(%rbp)
jne    12b3 <main+0x153>
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    -0x114(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x114(%rbp)
jmp    124c <main+0xec>
jmp    11d3 <main+0x73>
mov    -0x114(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r12
mov    %edi,%r13d
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xe18(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%r13d
jl     1323 <main+0x1c3>
jne    1211 <main+0xb1>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbx
xor    %ebp,%ebp
lea    -0x1(%r13),%eax
lea    (%r12,%rax,8),%r14
mov    %r13d,%r15d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r14),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
jne    1270 <main+0x110>
mov    (%r14),%rsi
lea    0xe6f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    -0x1(%r15),%eax
add    $0xfffffffffffffff8,%r14
cmp    $0x3,%r15d
mov    %eax,%r15d
jg     1230 <main+0xd0>
jmp    11fd <main+0x9d>
nopl   0x0(%rax,%rax,1)
mov    %rax,%r13
xor    %ebp,%ebp
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1310 <main+0x1b0>
xor    %ebp,%ebp
jmp    12d8 <main+0x178>
nopl   (%rax)
lea    0xe41(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1040 <memset@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r13,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1310 <main+0x1b0>
mov    0x8(%r12),%rsi
mov    %rbx,%rdi
call   1080 <strstr@plt>
test   %rax,%rax
je     12c3 <main+0x163>
test   %ebp,%ebp
jne    12a0 <main+0x140>
mov    (%r14),%rsi
lea    0xde4(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    12a0 <main+0x140>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x1(%r15),%r13d
cmp    $0x4,%r15d
jge    1216 <main+0xb6>
jmp    11fd <main+0x9d>
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [99 x i8] c"\0AThis program finds a pattern into the input lines\0AThe patern is give as a command line arguments.\00"
@.str.1 = [88 x i8] c"\0Aerror: Correct usage\0A\09./exec_file pattern [optional] named_files_where_to_find_pattern\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"\0Aerror: Couldn't open file: %s\00"
@.str.4 = [12 x i8] c"\0AIn file %s\00"
@.str.5 = [5 x i8] c"\0A\09%s\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 i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [256 x i8]* %6 to i8*
store i32 0, i32* %7
store i32* null, i32** %8
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %2
br label %17
17: ; preds = %69, %29, %16
%18 = load i32, i32* %4
%19 = add nsw i32 %18, -1
store i32 %19, i32* %4
%20 = icmp sgt i32 %18, 2
br i1 %20, label %21, label %70
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %27, i32** %8
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %36
29: ; preds = %21
%30 = load i8**, i8*** %5
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %34)
br label %17
36: ; preds = %21
store i32 0, i32* %7
%37 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%38 = call i32 @memset(i8* %37, i32 0, i32 256)
br label %39
39: ; preds = %68, %36
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%41 = load i32*, i32** %8
%42 = call i32* @fgets(i8* %40, i32 256, i32* %41)
%43 = icmp ne i32* %42, null
br i1 %43, label %44, label %69
44: ; preds = %39
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32* @strstr(i8* %45, i8* %48)
%50 = icmp ne i32* %49, null
br i1 %50, label %51, label %68
51: ; preds = %44
%52 = load i32, i32* %7
%53 = icmp ne i32 %52, 0
br i1 %53, label %61, label %54
54: ; preds = %51
%55 = load i8**, i8*** %5
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %54, %51
%62 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %62)
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%65 = call i32 @memset(i8* %64, i32 0, i32 256)
%66 = load i32, i32* %7
%67 = add nsw i32 %66, 1
store i32 %67, i32* %7
br label %68
68: ; preds = %61, %44
br label %39
69: ; preds = %39
br label %17
70: ; preds = %17
%71 = load i32, i32* %7
ret i32 %71
}

LLVM IR (-O2):
@.str = [99 x i8] c"\0AThis program finds a pattern into the input lines\0AThe patern is give as a command line arguments.\00"
@.str.1 = [88 x i8] c"\0Aerror: Correct usage\0A\09./exec_file pattern [optional] named_files_where_to_find_pattern\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [31 x i8] c"\0Aerror: Couldn't open file: %s\00"
@.str.4 = [12 x i8] c"\0AIn file %s\00"
@.str.5 = [5 x i8] c"\0A\09%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @.str, i64 0, i64 0))
%6 = icmp slt i32 %0, 2
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %58, label %9
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 1
br label %17
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %54, %34
%15 = phi i32 [ 0, %34 ], [ %55, %54 ]
%16 = icmp sgt i32 %36, 3
br i1 %16, label %17, label %58
17: ; preds = %9, %14
%18 = phi i32 [ %0, %9 ], [ %35, %14 ]
%19 = phi i32 [ 0, %9 ], [ %15, %14 ]
%20 = zext i32 %18 to i64
br label %21
21: ; preds = %17, %29
%22 = phi i64 [ %20, %17 ], [ %23, %29 ]
%23 = add nsw i64 %22, -1
%24 = and i64 %23, 4294967295
%25 = getelementptr inbounds i8*, i8** %1, i64 %24
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i8*, i8** %25
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %30)
%32 = trunc i64 %22 to i32
%33 = icmp sgt i32 %32, 3
br i1 %33, label %21, label %58
34: ; preds = %21
%35 = trunc i64 %23 to i32
%36 = trunc i64 %22 to i32
%37 = call i32 @memset(i8* %4, i32 0, i32 256)
%38 = call i32* @fgets(i8* %4, i32 256, i32* %27)
%39 = icmp eq i32* %38, null
br i1 %39, label %14, label %40
40: ; preds = %34, %54
%41 = phi i32 [ %55, %54 ], [ 0, %34 ]
%42 = load i8*, i8** %10
%43 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %42)
%44 = icmp eq i32* %43, null
br i1 %44, label %54, label %45
45: ; preds = %40
%46 = icmp eq i32 %41, 0
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = load i8*, i8** %25
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %47, %45
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%52 = call i32 @memset(i8* %4, i32 0, i32 256)
%53 = add nsw i32 %41, 1
br label %54
54: ; preds = %50, %40
%55 = phi i32 [ %53, %50 ], [ %41, %40 ]
%56 = call i32* @fgets(i8* %4, i32 256, i32* %27)
%57 = icmp eq i32* %56, null
br i1 %57, label %14, label %40
58: ; preds = %14, %29, %7
%59 = phi i32 [ 0, %7 ], [ %19, %29 ], [ %15, %14 ]
ret i32 %59
}