#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *strstr(char *, char *);
void findpat(FILE *fp, char *fname, char *pattern, bool except, bool number) {
  char line[1000] = "";
  unsigned lineno = 0;
  while (fgets(line, 1000, fp) != NULL) {
    lineno++;
    if ((strstr(line, pattern) != NULL) ^ except) {
      if (*fname != '\0')
        printf("%s - ", fname);
      if (number)
        printf("%u: ", lineno);
      printf("%s", line);
    }
  }
}


x86 assembly (clang, -O0):
<findpat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1040 <memset@plt>
movl   $0x0,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     122b <findpat+0xeb>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
xor    -0x1c(%rbp),%eax
cmp    $0x0,%eax
je     1226 <findpat+0xe6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11f3 <findpat+0xb3>
mov    -0x10(%rbp),%rsi
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
je     1211 <findpat+0xd1>
mov    -0x414(%rbp),%esi
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x410(%rbp),%rsi
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    117b <findpat+0x3b>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findpat>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %r8d,0xc(%rsp)
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbp
lea    0x10(%rsp),%rbx
mov    $0x3e8,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1211 <findpat+0xd1>
mov    $0x1,%ebx
lea    0x10(%rsp),%r14
jmp    11c9 <findpat+0x89>
nopl   0x0(%rax,%rax,1)
lea    0xe64(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r14,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
je     1211 <findpat+0xd1>
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <strstr@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
cmp    %r12d,%ecx
je     11b1 <findpat+0x71>
cmpb   $0x0,(%r15)
je     11f8 <findpat+0xb8>
lea    0xe12(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
cmpl   $0x0,0xc(%rsp)
je     11a0 <findpat+0x60>
lea    0xe00(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a0 <findpat+0x60>
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s - \00"
@.str.1 = [5 x i8] c"%u: \00"
@.str.2 = [3 x i8] c"%s\00"
define void @findpat(i32* %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1000 x i8]
%12 = alloca i32
store i32* %0, i32** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = bitcast [1000 x i8]* %11 to i8*
store i32 0, i32* %12
br label %14
14: ; preds = %47, %5
%15 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%16 = load i32*, i32** %6
%17 = call i32* @fgets(i8* %15, i32 1000, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %48
19: ; preds = %14
%20 = load i32, i32* %12
%21 = add i32 %20, 1
store i32 %21, i32* %12
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%23 = load i8*, i8** %8
%24 = call i32* @strstr(i8* %22, i8* %23)
%25 = icmp ne i32* %24, null
%26 = zext i1 %25 to i32
%27 = load i32, i32* %9
%28 = xor i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %47
30: ; preds = %19
%31 = load i8*, i8** %7
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %7
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %35, %30
%39 = load i32, i32* %10
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i32, i32* %12
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %41, %38
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %11, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %44, %19
br label %14
48: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s - \00"
@.str.1 = [5 x i8] c"%u: \00"
@.str.2 = [3 x i8] c"%s\00"
define void @findpat(i32* nocapture %0, i8* %1, i8* nocapture %2, i32 %3, i32 %4) {
%6 = alloca [1000 x i8]
%7 = getelementptr inbounds [1000 x i8], [1000 x i8]* %6, i64 0, i64 0
%8 = call i32* @fgets(i8* %7, i32 1000, i32* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %32, label %10
10: ; preds = %5
%11 = icmp eq i32 %4, 0
br label %12
12: ; preds = %10, %29
%13 = phi i32 [ 0, %10 ], [ %14, %29 ]
%14 = add i32 %13, 1
%15 = call i32* @strstr(i8* %7, i8* dereferenceable(1) %2)
%16 = icmp ne i32* %15, null
%17 = zext i1 %16 to i32
%18 = icmp eq i32 %17, %3
br i1 %18, label %29, label %19
19: ; preds = %12
%20 = load i8, i8* %1
%21 = icmp eq i8 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %24
24: ; preds = %22, %19
br i1 %11, label %27, label %25
25: ; preds = %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %27
27: ; preds = %25, %24
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %7)
br label %29
29: ; preds = %27, %12
%30 = call i32* @fgets(i8* %7, i32 1000, i32* %0)
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %12
32: ; preds = %29, %5
ret void
}