#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 scalar_t__ off_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ compare(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fseeko(int /*<<< orphan*/ *, scalar_t__, int /*<<< orphan*/);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
void printmatch(const char *key, FILE *fp, off_t start, const char *fname,
                int cflag) {
  int c, count;
  if (start >= 0) {
    fseeko(fp, start, SEEK_SET);
  }
  for (count = 0; start >= 0 && compare(key, fp) == 0; count++) {
    fseeko(fp, start, SEEK_SET);
    if (cflag == 0 && fname != 0) {
      fputs(fname, stdout);
      fputc(':', stdout);
    }
    while ((c = getc(fp)) != EOF) {
      start++;
      if (cflag == 0) {
        fputc(c, stdout);
      }
      if (c == '\n') {
        break;
      }
    }
    if (c == EOF) {
      break;
    }
  }
  if (cflag != 0) {
    if (fname != 0) {
      fputs(fname, stdout);
      fputc(':', stdout);
    }
    printf("%d\n", count);
  }
}


x86 assembly (clang, -O0):
<printmatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jl     119d <printmatch+0x3d>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
call   1060 <fseeko@plt>
movl   $0x0,-0x2c(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x2d(%rbp)
jl     11cb <printmatch+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <compare@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11db <printmatch+0x7b>
jmp    12b3 <printmatch+0x153>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
call   1060 <fseeko@plt>
cmpl   $0x0,-0x24(%rbp)
jne    122b <printmatch+0xcb>
cmpq   $0x0,-0x20(%rbp)
je     122b <printmatch+0xcb>
mov    -0x20(%rbp),%rdi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
mov    $0x3a,%edi
call   1050 <fputc@plt>
jmp    1230 <printmatch+0xd0>
mov    -0x10(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2da5(%rip),%rcx
cmp    (%rcx),%eax
je     1289 <printmatch+0x129>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1275 <printmatch+0x115>
mov    -0x28(%rbp),%eax
mov    0x2d65(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <fputc@plt>
cmpl   $0xa,-0x28(%rbp)
jne    1284 <printmatch+0x124>
jmp    1289 <printmatch+0x129>
jmp    1230 <printmatch+0xd0>
mov    -0x28(%rbp),%eax
mov    0x2d55(%rip),%rcx
cmp    (%rcx),%eax
jne    12a0 <printmatch+0x140>
jmp    12b3 <printmatch+0x153>
jmp    12a5 <printmatch+0x145>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11a4 <printmatch+0x44>
cmpl   $0x0,-0x24(%rbp)
je     12fc <printmatch+0x19c>
cmpq   $0x0,-0x20(%rbp)
je     12ed <printmatch+0x18d>
mov    -0x20(%rbp),%rdi
mov    0x2cfd(%rip),%rax
mov    (%rax),%esi
call   1040 <fputs@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%esi
mov    $0x3a,%edi
call   1050 <fputc@plt>
mov    -0x2c(%rbp),%esi
lea    0xd09(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printmatch>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %rcx,%r13
mov    %rdi,0x10(%rsp)
test   %rdx,%rdx
js     1289 <printmatch+0x129>
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    0x2e49(%rip),%rax
mov    (%rax),%edx
mov    %rsi,%rdi
mov    %rbp,%rsi
call   1060 <fseeko@plt>
test   %r12d,%r12d
sete   %al
test   %r13,%r13
setne  %cl
and    %al,%cl
mov    %cl,0x3(%rsp)
movl   $0x0,0x4(%rsp)
mov    0x2e13(%rip),%r14
mov    0x2e24(%rip),%r15
mov    %r13,0x8(%rsp)
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1070 <compare@plt>
test   %rax,%rax
jne    1291 <printmatch+0x131>
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <fseeko@plt>
cmpb   $0x0,0x3(%rsp)
je     122a <printmatch+0xca>
mov    (%r14),%esi
mov    %r13,%rdi
call   1040 <fputs@plt>
mov    (%r14),%esi
mov    $0x3a,%edi
call   1050 <fputc@plt>
jmp    122a <printmatch+0xca>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
cmp    $0xa,%r13d
je     1250 <printmatch+0xf0>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r15),%eax
je     1270 <printmatch+0x110>
mov    %eax,%r13d
test   %r12d,%r12d
jne    1220 <printmatch+0xc0>
mov    (%r14),%esi
movsbl %r13b,%edi
call   1050 <fputc@plt>
jmp    1220 <printmatch+0xc0>
nopl   (%rax)
cmpl   $0xa,(%r15)
je     1270 <printmatch+0x110>
lea    -0x1(%rbp),%rax
addl   $0x1,0x4(%rsp)
cmp    $0xfffffffffffffffe,%rax
mov    0x8(%rsp),%r13
jg     11c9 <printmatch+0x69>
jmp    1291 <printmatch+0x131>
mov    0x8(%rsp),%r13
test   %r12d,%r12d
jne    1296 <printmatch+0x136>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movl   $0x0,0x4(%rsp)
test   %r12d,%r12d
je     127a <printmatch+0x11a>
test   %r13,%r13
je     12b8 <printmatch+0x158>
mov    0x2d2e(%rip),%rbx
mov    (%rbx),%esi
mov    %r13,%rdi
call   1040 <fputs@plt>
mov    (%rbx),%esi
mov    $0x3a,%edi
call   1050 <fputc@plt>
lea    0xd41(%rip),%rdi
mov    0x4(%rsp),%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stdout = global i32 0
@EOF = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define void @printmatch(i8* %0, i32* %1, i64 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %6
store i32* %1, i32** %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i32 %4, i32* %10
%13 = load i64, i64* %8
%14 = icmp sge i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %5
%16 = load i32*, i32** %7
%17 = load i64, i64* %8
%18 = load i32, i32* @SEEK_SET
%19 = call i32 @fseeko(i32* %16, i64 %17, i32 %18)
br label %20
20: ; preds = %15, %5
store i32 0, i32* %12
br label %21
21: ; preds = %74, %20
%22 = load i64, i64* %8
%23 = icmp sge i64 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i8*, i8** %6
%26 = load i32*, i32** %7
%27 = call i64 @compare(i8* %25, i32* %26)
%28 = icmp eq i64 %27, 0
br label %29
29: ; preds = %24, %21
%30 = phi i1 [ false, %21 ], [ %28, %24 ]
br i1 %30, label %31, label %77
31: ; preds = %29
%32 = load i32*, i32** %7
%33 = load i64, i64* %8
%34 = load i32, i32* @SEEK_SET
%35 = call i32 @fseeko(i32* %32, i64 %33, i32 %34)
%36 = load i32, i32* %10
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %47
38: ; preds = %31
%39 = load i8*, i8** %9
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i8*, i8** %9
%43 = load i32, i32* @stdout
%44 = call i32 @fputs(i8* %42, i32 %43)
%45 = load i32, i32* @stdout
%46 = call i32 @fputc(i8 signext 58, i32 %45)
br label %47
47: ; preds = %41, %38, %31
br label %48
48: ; preds = %67, %47
%49 = load i32*, i32** %7
%50 = call i32 @getc(i32* %49)
store i32 %50, i32* %11
%51 = load i32, i32* @EOF
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %68
53: ; preds = %48
%54 = load i64, i64* %8
%55 = add nsw i64 %54, 1
store i64 %55, i64* %8
%56 = load i32, i32* %10
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %53
%59 = load i32, i32* %11
%60 = trunc i32 %59 to i8
%61 = load i32, i32* @stdout
%62 = call i32 @fputc(i8 signext %60, i32 %61)
br label %63
63: ; preds = %58, %53
%64 = load i32, i32* %11
%65 = icmp eq i32 %64, 10
br i1 %65, label %66, label %67
66: ; preds = %63
br label %68
67: ; preds = %63
br label %48
68: ; preds = %66, %48
%69 = load i32, i32* %11
%70 = load i32, i32* @EOF
%71 = icmp eq i32 %69, %70
br i1 %71, label %72, label %73
72: ; preds = %68
br label %77
73: ; preds = %68
br label %74
74: ; preds = %73
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
br label %21
77: ; preds = %72, %29
%78 = load i32, i32* %10
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %92
80: ; preds = %77
%81 = load i8*, i8** %9
%82 = icmp ne i8* %81, null
br i1 %82, label %83, label %89
83: ; preds = %80
%84 = load i8*, i8** %9
%85 = load i32, i32* @stdout
%86 = call i32 @fputs(i8* %84, i32 %85)
%87 = load i32, i32* @stdout
%88 = call i32 @fputc(i8 signext 58, i32 %87)
br label %89
89: ; preds = %83, %80
%90 = load i32, i32* %12
%91 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %90)
br label %92
92: ; preds = %89, %77
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stdout = global i32 0
@EOF = global i32 0
@.str = [4 x i8] c"%d\0A\00"
define void @printmatch(i8* %0, i32* %1, i64 %2, i8* %3, i32 %4) {
%6 = icmp sgt i64 %2, -1
br i1 %6, label %7, label %46
7: ; preds = %5
%8 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseeko(i32* %1, i64 %2, i32 %8)
%10 = icmp eq i32 %4, 0
%11 = icmp ne i8* %3, null
%12 = and i1 %11, %10
br label %13
13: ; preds = %7, %43
%14 = phi i32 [ 0, %7 ], [ %44, %43 ]
%15 = phi i64 [ %2, %7 ], [ %33, %43 ]
%16 = tail call i64 @compare(i8* %0, i32* %1)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %46
18: ; preds = %13
%19 = load i32, i32* @SEEK_SET
%20 = tail call i32 @fseeko(i32* %1, i64 %15, i32 %19)
br i1 %12, label %21, label %26
21: ; preds = %18
%22 = load i32, i32* @stdout
%23 = tail call i32 @fputs(i8* %3, i32 %22)
%24 = load i32, i32* @stdout
%25 = tail call i32 @fputc(i8 signext 58, i32 %24)
br label %26
26: ; preds = %21, %18
br label %27
27: ; preds = %26, %38
%28 = phi i64 [ %33, %38 ], [ %15, %26 ]
%29 = tail call i32 @getc(i32* %1)
%30 = load i32, i32* @EOF
%31 = icmp eq i32 %29, %30
br i1 %31, label %46, label %32
32: ; preds = %27
%33 = add nsw i64 %28, 1
br i1 %10, label %34, label %38
34: ; preds = %32
%35 = trunc i32 %29 to i8
%36 = load i32, i32* @stdout
%37 = tail call i32 @fputc(i8 signext %35, i32 %36)
br label %38
38: ; preds = %34, %32
%39 = icmp eq i32 %29, 10
br i1 %39, label %40, label %27
40: ; preds = %38
%41 = load i32, i32* @EOF
%42 = icmp eq i32 %41, 10
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = add nuw nsw i32 %14, 1
%45 = icmp sgt i64 %28, -2
br i1 %45, label %13, label %46
46: ; preds = %13, %40, %43, %27, %5
%47 = phi i32 [ 0, %5 ], [ %14, %27 ], [ %44, %43 ], [ %14, %40 ], [ %14, %13 ]
%48 = icmp eq i32 %4, 0
br i1 %48, label %58, label %49
49: ; preds = %46
%50 = icmp eq i8* %3, null
br i1 %50, label %56, label %51
51: ; preds = %49
%52 = load i32, i32* @stdout
%53 = tail call i32 @fputs(i8* %3, i32 %52)
%54 = load i32, i32* @stdout
%55 = tail call i32 @fputc(i8 signext 58, i32 %54)
br label %56
56: ; preds = %51, %49
%57 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %47)
br label %58
58: ; preds = %56, %46
ret void
}