#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 */
scalar_t__ custom_getline(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 (custom_getline(line, 1000)) {
      if (strstr(line, argv[1]) != NULL) {
        printf("%s\n", 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     1170 <main+0x40>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11dc <main+0xac>
jmp    1175 <main+0x45>
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <custom_getline@plt>
cmp    $0x0,%rax
je     11d7 <main+0xa7>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1050 <strstr@plt>
cmp    $0x0,%rax
je     11d2 <main+0xa2>
lea    -0x400(%rbp),%rsi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    1175 <main+0x45>
jmp    11dc <main+0xac>
mov    -0x404(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x3f0,%rsp
cmp    $0x2,%edi
jne    1190 <main+0x60>
mov    %rsi,%r14
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1040 <custom_getline@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     119e <main+0x6e>
mov    %rsp,%rbx
jmp    1172 <main+0x42>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1040 <custom_getline@plt>
test   %rax,%rax
je     119e <main+0x6e>
mov    0x8(%r14),%rsi
mov    %rbx,%rdi
call   1050 <strstr@plt>
test   %rax,%rax
je     1160 <main+0x30>
mov    %rbx,%rdi
call   1030 <puts@plt>
add    $0x1,%ebp
jmp    1160 <main+0x30>
lea    0xe69(%rip),%rdi
call   1030 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x3f0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Usage: find pattern\0A\00"
@.str.1 = [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 [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 %31
12: ; preds = %2
br label %13
13: ; preds = %29, %12
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%15 = call i64 @custom_getline(i8* %14, i32 1000)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %30
17: ; preds = %13
%18 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @strstr(i8* %18, i8* %21)
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25)
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %29
29: ; preds = %24, %17
br label %13
30: ; preds = %13
br label %31
31: ; preds = %30, %10
%32 = load i32, i32* %7
ret i32 %32
}

LLVM IR (-O2):
@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 @custom_getline(i8* %4, i32 1000)
%8 = icmp eq i64 %7, 0
br i1 %8, label %25, label %9
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 %25
13: ; preds = %9, %21
%14 = phi i32 [ 0, %9 ], [ %22, %21 ]
%15 = load i8*, i8** %10
%16 = call i32* @strstr(i8* %4, i8* dereferenceable(1) %15)
%17 = icmp eq i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %13
%19 = call i32 @puts(i8* %4)
%20 = add nsw i32 %14, 1
br label %21
21: ; preds = %18, %13
%22 = phi i32 [ %20, %18 ], [ %14, %13 ]
%23 = call i64 @custom_getline(i8* %4, i32 1000)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %13
25: ; preds = %21, %6, %11
%26 = phi i32 [ 0, %11 ], [ 0, %6 ], [ %22, %21 ]
ret i32 %26
}