#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*/ clear_arr(char *);
scalar_t__ getline_x(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char **argv) {
  char line[1000];
  int found = 0;
  if (argc != 2)
    printf("Usage: find pattern\n");
  else {
    while (getline_x(line, 1000) > 0) {
      clear_arr(line);
      if (strstr(line, *(argv + 1)) != NULL) {
        printf("%s", line);
        found++;
      }
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x404(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1180 <main+0x40>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11f8 <main+0xb8>
jmp    1185 <main+0x45>
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1030 <getline_x@plt>
cmp    $0x0,%rax
jle    11f3 <main+0xb3>
lea    -0x400(%rbp),%rdi
call   1050 <clear_arr@plt>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11ee <main+0xae>
lea    -0x400(%rbp),%rsi
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    1185 <main+0x45>
jmp    11f8 <main+0xb8>
mov    -0x404(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x3e8,%rsp
cmp    $0x2,%edi
jne    11cd <main+0x7d>
mov    %rsi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <getline_x@plt>
test   %rax,%rax
jle    11d9 <main+0x89>
mov    %rsp,%rbx
lea    0xe7f(%rip),%r15
xor    %ebp,%ebp
jmp    11a2 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <getline_x@plt>
test   %rax,%rax
jle    11db <main+0x8b>
mov    %rbx,%rdi
call   1060 <clear_arr@plt>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
test   %rax,%rax
je     1190 <main+0x40>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
jmp    1190 <main+0x40>
lea    0xe2f(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: find pattern\0A\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %33
12: ; preds = %2
br label %13
13: ; preds = %31, %12
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%15 = call i64 @getline_x(i8* %14, i32 1000)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %13
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = call i32 @clear_arr(i8* %18)
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @strstr(i8* %20, i8* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %31
26: ; preds = %17
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %31
31: ; preds = %26, %17
br label %13
32: ; preds = %13
br label %33
33: ; preds = %32, %10
%34 = load i32, i32* %7
ret i32 %34
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@str = [20 x i8] c"Usage: find pattern\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = call i64 @getline_x(i8* %4, i32 1000)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = getelementptr inbounds i8*, i8** %1, i64 1
br label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %26
13: ; preds = %9, %22
%14 = phi i32 [ 0, %9 ], [ %23, %22 ]
%15 = call i32 @clear_arr(i8* %4)
%16 = load i8*, i8** %10
%17 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%21 = add nsw i32 %14, 1
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ %21, %19 ], [ %14, %13 ]
%24 = call i64 @getline_x(i8* %4, i32 1000)
%25 = icmp sgt i64 %24, 0
br i1 %25, label %13, label %26
26: ; preds = %22, %6, %11
%27 = phi i32 [ 0, %11 ], [ 0, %6 ], [ %23, %22 ]
ret i32 %27
}