#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*/ free(char *);
scalar_t__ get_str(char **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ show_help();
scalar_t__ strcmp(char *, char *);
scalar_t__ strstr(char *, char *);
int /*<<< orphan*/ to_lower_case(char **);
int main(int argc, char **argv) {
  char *pattern, *str;
  if (argc < 2 || argc > 3 ||
      (!strcmp("--help", argv[1]) || !strcmp("-h", argv[1]))) {
    show_help();
  } else if (argc == 3 && strcmp(argv[1], "-i") &&
             strcmp(argv[1], "--ignorecase")) {
    printf("%s is not a valid argument. Exiting!\n", argv[1]);
    return 1;
  } else {
    pattern = argv[argc - 1];
    if (argc == 3)
      to_lower_case(&pattern);
    str = NULL;
    while (get_str(&str)) {
      if (argc == 3)
        to_lower_case(&str);
      if (strstr(str, argv[argc - 1])) {
        printf("%s\n", str);
      }
    }
    free(str);
  }
  return 0;
  if (argc < 2 || argc > 3 ||
      (!strcmp("--help", argv[1]) || !strcmp("-h", argv[1]))) {
    printf("usage: <command> | selstr [-i/--ignorecase] <string>\n\n");
    printf("-i/--ignorecase\t\tfilter text ignoring case\n");
    printf("<string>\t\tstring to filter input with\n");
  } else if (argc == 3 && strcmp(argv[1], "-i") &&
             strcmp(argv[1], "--ignorecase")) {
    printf("%s is not a valid argument. Exiting!\n", argv[1]);
    return 1;
  } else {
    char *str = NULL;
    while (get_str(&str)) {
      if (strstr(str, argv[argc - 1])) {
        printf("%s\n", str);
      }
    }
    free(str);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11d6 <main+0x66>
cmpl   $0x3,-0x8(%rbp)
jg     11d6 <main+0x66>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe57(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11d6 <main+0x66>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe40(%rip),%rdi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11e2 <main+0x72>
mov    $0x0,%al
call   1070 <show_help@plt>
jmp    12e9 <main+0x179>
cmpl   $0x3,-0x8(%rbp)
jne    124a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     124a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf4(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     124a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12f0 <main+0x180>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1272 <main+0x102>
lea    -0x18(%rbp),%rdi
call   1060 <to_lower_case@plt>
movq   $0x0,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1080 <get_str@plt>
cmp    $0x0,%rax
je     12db <main+0x16b>
cmpl   $0x3,-0x8(%rbp)
jne    12a0 <main+0x130>
lea    -0x20(%rbp),%rdi
call   1060 <to_lower_case@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     12d6 <main+0x166>
mov    -0x20(%rbp),%rsi
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127a <main+0x10a>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    12e9 <main+0x179>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
lea    -0x4(%r14),%eax
cmp    $0xfffffffe,%eax
jb     120b <main+0x8b>
mov    %rsi,%r15
mov    0x8(%rsi),%rsi
lea    0xe5d(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <main+0x8b>
mov    0x8(%r15),%rsi
lea    0xe4f(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120b <main+0x8b>
cmp    $0x3,%r14d
jne    1220 <main+0xa0>
mov    0x8(%r15),%rdi
lea    0xe37(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1233 <main+0xb3>
mov    0x8(%r15),%rdi
lea    0xe25(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1233 <main+0xb3>
mov    0x8(%r15),%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
jmp    1214 <main+0x94>
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <show_help@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    -0x1(%r14),%eax
mov    (%r15,%rax,8),%rcx
lea    (%r15,%rax,8),%r15
mov    %rcx,0x8(%rsp)
jmp    124a <main+0xca>
mov    0x10(%r15),%rax
add    $0x10,%r15
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1070 <to_lower_case@plt>
movq   $0x0,(%rsp)
mov    %rsp,%rdi
call   1090 <get_str@plt>
test   %rax,%rax
je     12a7 <main+0x127>
mov    %rsp,%rbx
jmp    127d <main+0xfd>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   1090 <get_str@plt>
test   %rax,%rax
je     12a7 <main+0x127>
cmp    $0x3,%r14d
jne    128b <main+0x10b>
mov    %rbx,%rdi
call   1070 <to_lower_case@plt>
mov    (%rsp),%rdi
mov    (%r15),%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     1270 <main+0xf0>
mov    (%rsp),%rdi
call   1040 <puts@plt>
jmp    1270 <main+0xf0>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
jmp    1214 <main+0x94>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [13 x i8] c"--ignorecase\00"
@.str.4 = [38 x i8] c"%s is not a valid argument. Exiting!\0A\00"
@.str.5 = [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 i8*
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %25, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 3
br i1 %12, label %25, label %13
13: ; preds = %10
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %19, %13, %10, %2
%26 = call i32 (...) @show_help()
br label %85
27: ; preds = %19
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 3
br i1 %29, label %30, label %47
30: ; preds = %27
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %47
36: ; preds = %30
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %36
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %45)
store i32 1, i32* %3
br label %86
47: ; preds = %36, %30, %27
%48 = load i8**, i8*** %5
%49 = load i32, i32* %4
%50 = sub nsw i32 %49, 1
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %48, i64 %51
%53 = load i8*, i8** %52
store i8* %53, i8** %6
%54 = load i32, i32* %4
%55 = icmp eq i32 %54, 3
br i1 %55, label %56, label %58
56: ; preds = %47
%57 = call i32 @to_lower_case(i8** %6)
br label %58
58: ; preds = %56, %47
store i8* null, i8** %7
br label %59
59: ; preds = %80, %58
%60 = call i64 @get_str(i8** %7)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %81
62: ; preds = %59
%63 = load i32, i32* %4
%64 = icmp eq i32 %63, 3
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @to_lower_case(i8** %7)
br label %67
67: ; preds = %65, %62
%68 = load i8*, i8** %7
%69 = load i8**, i8*** %5
%70 = load i32, i32* %4
%71 = sub nsw i32 %70, 1
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds i8*, i8** %69, i64 %72
%74 = load i8*, i8** %73
%75 = call i64 @strstr(i8* %68, i8* %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %67
%78 = load i8*, i8** %7
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %77, %67
br label %59
81: ; preds = %59
%82 = load i8*, i8** %7
%83 = call i32 @free(i8* %82)
br label %84
84: ; preds = %81
br label %85
85: ; preds = %84, %25
store i32 0, i32* %3
br label %86
86: ; preds = %85, %42
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [3 x i8] c"-i\00"
@.str.3 = [13 x i8] c"--ignorecase\00"
@.str.4 = [38 x i8] c"%s is not a valid argument. Exiting!\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast i8** %3 to i8*
%6 = bitcast i8** %4 to i8*
%7 = add i32 %0, -4
%8 = icmp ult i32 %7, -2
br i1 %8, label %18, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i64 @strcmp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %9
%15 = load i8*, i8** %10
%16 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14, %9, %2
%19 = tail call i32 (...) @show_help()
br label %63
20: ; preds = %14
%21 = icmp eq i32 %0, 3
br i1 %21, label %22, label %33
22: ; preds = %20
%23 = load i8*, i8** %10
%24 = tail call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %38, label %26
26: ; preds = %22
%27 = load i8*, i8** %10
%28 = tail call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %26
%31 = load i8*, i8** %10
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %31)
br label %63
33: ; preds = %20
%34 = add nsw i32 %0, -1
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
store i8* %37, i8** %3
br label %42
38: ; preds = %26, %22
%39 = getelementptr inbounds i8*, i8** %1, i64 2
%40 = load i8*, i8** %39
store i8* %40, i8** %3
%41 = call i32 @to_lower_case(i8** %3)
br label %42
42: ; preds = %33, %38
%43 = phi i8** [ %39, %38 ], [ %36, %33 ]
store i8* null, i8** %4
%44 = call i64 @get_str(i8** %4)
%45 = icmp eq i64 %44, 0
br i1 %45, label %60, label %46
46: ; preds = %42, %57
br i1 %21, label %47, label %49
47: ; preds = %46
%48 = call i32 @to_lower_case(i8** %4)
br label %49
49: ; preds = %47, %46
%50 = load i8*, i8** %4
%51 = load i8*, i8** %43
%52 = call i64 @strstr(i8* %50, i8* %51)
%53 = icmp eq i64 %52, 0
br i1 %53, label %57, label %54
54: ; preds = %49
%55 = load i8*, i8** %4
%56 = call i32 @puts(i8* dereferenceable(1) %55)
br label %57
57: ; preds = %54, %49
%58 = call i64 @get_str(i8** %4)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %46
60: ; preds = %57, %42
%61 = load i8*, i8** %4
%62 = call i32 @free(i8* %61)
br label %63
63: ; preds = %18, %60, %30
%64 = phi i32 [ 1, %30 ], [ 0, %60 ], [ 0, %18 ]
ret i32 %64
}