#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 countchars(char *, int);
scalar_t__ getchars(char *, int);
int /*<<< orphan*/ printf(char *);
int strcopy(char *, int, char *, int);
int strindex(char *, char *);
int main(int argc, char **argv) {
  char line[1000];
  int matches = 0;
  char pattern[1000];
  int pattern_i = 0;
  for (int a = 1; a < argc; a++) {
    int arg_len = countchars(argv[a], 1000);
    pattern_i = strcopy(argv[a], arg_len, pattern, pattern_i);
    if (a + 1 < argc)
      pattern[pattern_i++] = ' ';
  }
  if (pattern_i == 0) {
    pattern[pattern_i++] = ';';
  }
  pattern[pattern_i] = '\0';
  while (getchars(line, 1000) > 0) {
    if (strindex(line, pattern) > -1) {
      printf(line);
      matches++;
    }
  }
  return matches;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x800,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x404(%rbp)
movl   $0x0,-0x7f4(%rbp)
movl   $0x1,-0x7f8(%rbp)
mov    -0x7f8(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1228 <main+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x7f8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x3e8,%esi
call   1030 <countchars@plt>
mov    %eax,-0x7fc(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x7f8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x7fc(%rbp),%esi
lea    -0x7f0(%rbp),%rdx
mov    -0x7f4(%rbp),%ecx
call   1070 <strcopy@plt>
mov    %eax,-0x7f4(%rbp)
mov    -0x7f8(%rbp),%eax
add    $0x1,%eax
cmp    -0x8(%rbp),%eax
jge    120f <main+0xbf>
mov    -0x7f4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x7f4(%rbp)
cltq
movb   $0x20,-0x7f0(%rbp,%rax,1)
20
jmp    1214 <main+0xc4>
mov    -0x7f8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7f8(%rbp)
jmp    1187 <main+0x37>
cmpl   $0x0,-0x7f4(%rbp)
jne    1250 <main+0x100>
mov    -0x7f4(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x7f4(%rbp)
cltq
movb   $0x3b,-0x7f0(%rbp,%rax,1)
3b
movslq -0x7f4(%rbp),%rax
movb   $0x0,-0x7f0(%rbp,%rax,1)
lea    -0x400(%rbp),%rdi
mov    $0x3e8,%esi
call   1040 <getchars@plt>
cmp    $0x0,%rax
jle    12b6 <main+0x166>
lea    -0x400(%rbp),%rdi
lea    -0x7f0(%rbp),%rsi
call   1060 <strindex@plt>
cmp    $0xffffffff,%eax
jle    12b1 <main+0x161>
lea    -0x400(%rbp),%rdi
call   1050 <printf@plt>
mov    -0x404(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x404(%rbp)
jmp    125f <main+0x10f>
mov    -0x404(%rbp),%eax
add    $0x800,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7d8,%rsp
cmp    $0x2,%edi
jl     11d9 <main+0x89>
mov    %rsi,%r13
mov    %edi,%r15d
mov    $0x1,%r12d
sub    %r15,%r12
xor    %ebp,%ebp
mov    $0x2,%ebx
mov    %rsp,%r14
jmp    11a2 <main+0x52>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%rax
add    $0x1,%rax
add    $0x1,%rbx
cmp    $0x2,%rax
je     11d5 <main+0x85>
mov    -0x8(%r13,%rbx,8),%rdi
mov    $0x3e8,%esi
call   1030 <countchars@plt>
mov    -0x8(%r13,%rbx,8),%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
call   1070 <strcopy@plt>
mov    %eax,%ebp
cmp    %r15,%rbx
jae    1190 <main+0x40>
movslq %ebp,%rax
add    $0x1,%ebp
movb   $0x20,(%rsp,%rax,1)
jmp    1190 <main+0x40>
test   %ebp,%ebp
jne    11e2 <main+0x92>
movb   $0x3b,(%rsp)
mov    $0x1,%ebp
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
lea    0x3f0(%rsp),%rdi
mov    $0x3e8,%esi
call   1040 <getchars@plt>
xor    %ebx,%ebx
test   %rax,%rax
jle    123e <main+0xee>
lea    0x3f0(%rsp),%rbp
mov    %rsp,%r14
jmp    1222 <main+0xd2>
nop
mov    %rbp,%rdi
mov    $0x3e8,%esi
call   1040 <getchars@plt>
test   %rax,%rax
jle    123e <main+0xee>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1060 <strindex@plt>
test   %eax,%eax
js     1210 <main+0xc0>
mov    %rbp,%rdi
call   1050 <printf@plt>
add    $0x1,%ebx
jmp    1210 <main+0xc0>
mov    %ebx,%eax
add    $0x7d8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1000 x i8]
%7 = alloca i32
%8 = alloca [1000 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %9
store i32 1, i32* %10
br label %12
12: ; preds = %42, %2
%13 = load i32, i32* %10
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %45
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = load i32, i32* %10
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8*, i8** %17, i64 %19
%21 = load i8*, i8** %20
%22 = call i32 @countchars(i8* %21, i32 1000)
store i32 %22, i32* %11
%23 = load i8**, i8*** %5
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = load i32, i32* %11
%29 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%30 = load i32, i32* %9
%31 = call i32 @strcopy(i8* %27, i32 %28, i8* %29, i32 %30)
store i32 %31, i32* %9
%32 = load i32, i32* %10
%33 = add nsw i32 %32, 1
%34 = load i32, i32* %4
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %41
36: ; preds = %16
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
%39 = sext i32 %37 to i64
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %39
store i8 32, i8* %40
br label %41
41: ; preds = %36, %16
br label %42
42: ; preds = %41
%43 = load i32, i32* %10
%44 = add nsw i32 %43, 1
store i32 %44, i32* %10
br label %12
45: ; preds = %12
%46 = load i32, i32* %9
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i32, i32* %9
%50 = add nsw i32 %49, 1
store i32 %50, i32* %9
%51 = sext i32 %49 to i64
%52 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %51
store i8 59, i8* %52
br label %53
53: ; preds = %48, %45
%54 = load i32, i32* %9
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 %55
store i8 0, i8* %56
br label %57
57: ; preds = %71, %53
%58 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%59 = call i64 @getchars(i8* %58, i32 1000)
%60 = icmp sgt i64 %59, 0
br i1 %60, label %61, label %72
61: ; preds = %57
%62 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%63 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%64 = call i32 @strindex(i8* %62, i8* %63)
%65 = icmp sgt i32 %64, -1
br i1 %65, label %66, label %71
66: ; preds = %61
%67 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%68 = call i32 @printf(i8* %67)
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %71
71: ; preds = %66, %61
br label %57
72: ; preds = %57
%73 = load i32, i32* %7
ret i32 %73
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca [1000 x i8]
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %30
8: ; preds = %2
%9 = zext i32 %0 to i64
%10 = zext i32 %0 to i64
br label %13
11: ; preds = %27
%12 = icmp eq i32 %28, 0
br i1 %12, label %30, label %31
13: ; preds = %8, %27
%14 = phi i64 [ 1, %8 ], [ %21, %27 ]
%15 = phi i32 [ 0, %8 ], [ %28, %27 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %14
%17 = load i8*, i8** %16
%18 = call i32 @countchars(i8* %17, i32 1000)
%19 = load i8*, i8** %16
%20 = call i32 @strcopy(i8* %19, i32 %18, i8* %6, i32 %15)
%21 = add nuw nsw i64 %14, 1
%22 = icmp ult i64 %21, %9
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = add nsw i32 %20, 1
%25 = sext i32 %20 to i64
%26 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %25
store i8 32, i8* %26
br label %27
27: ; preds = %23, %13
%28 = phi i32 [ %24, %23 ], [ %20, %13 ]
%29 = icmp eq i64 %21, %10
br i1 %29, label %11, label %13
30: ; preds = %2, %11
store i8 59, i8* %6
br label %31
31: ; preds = %30, %11
%32 = phi i32 [ 1, %30 ], [ %28, %11 ]
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i64 @getchars(i8* %5, i32 1000)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %31, %44
%38 = phi i32 [ %45, %44 ], [ 0, %31 ]
%39 = call i32 @strindex(i8* %5, i8* %6)
%40 = icmp sgt i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @printf(i8* %5)
%43 = add nsw i32 %38, 1
br label %44
44: ; preds = %41, %37
%45 = phi i32 [ %43, %41 ], [ %38, %37 ]
%46 = call i64 @getchars(i8* %5, i32 1000)
%47 = icmp sgt i64 %46, 0
br i1 %47, label %37, label %48
48: ; preds = %44, %31
%49 = phi i32 [ 0, %31 ], [ %45, %44 ]
ret i32 %49
}