#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*/ NormalizeSignature(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
unsigned int CountTableInstances(char *InputPathname, char *Signature) {
  char Buffer[256];
  FILE *InputFile;
  unsigned int Instances = 0;
  InputFile = fopen(InputPathname, "rt");
  if (!InputFile) {
    printf("Could not open %s\n", InputPathname);
    return 0;
  }
  while (fgets(Buffer, 256, InputFile)) {
    if ((Buffer[0] == ' ') || (Buffer[0] == '\n')) {
      continue;
    }
    NormalizeSignature(Buffer);
    if (!strncmp(Buffer, Signature, 4)) {
      Instances++;
    }
  }
  fclose(InputFile);
  return Instances;
}


x86 assembly (clang, -O0):
<CountTableInstances>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x12c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe78(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmpq   $0x0,-0x128(%rbp)
jne    11be <CountTableInstances+0x5e>
mov    -0x10(%rbp),%rsi
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125d <CountTableInstances+0xfd>
jmp    11c3 <CountTableInstances+0x63>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x100,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1248 <CountTableInstances+0xe8>
movsbl -0x120(%rbp),%eax
cmp    $0x20,%eax
je     1205 <CountTableInstances+0xa5>
movsbl -0x120(%rbp),%eax
cmp    $0xa,%eax
jne    120a <CountTableInstances+0xaa>
jmp    11c3 <CountTableInstances+0x63>
lea    -0x120(%rbp),%rdi
call   1070 <NormalizeSignature@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1243 <CountTableInstances+0xe3>
mov    -0x12c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x12c(%rbp)
jmp    11c3 <CountTableInstances+0x63>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x12c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CountTableInstances>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe86(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11fc <CountTableInstances+0x9c>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
xor    %r15d,%r15d
test   %rax,%rax
je     11f2 <CountTableInstances+0x92>
mov    %rsp,%rbp
jmp    11c5 <CountTableInstances+0x65>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbp,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11f2 <CountTableInstances+0x92>
movzbl (%rsp),%eax
cmp    $0x20,%al
je     11b0 <CountTableInstances+0x50>
cmp    $0xa,%al
je     11b0 <CountTableInstances+0x50>
mov    %rbp,%rdi
call   1070 <NormalizeSignature@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%eax
adc    $0x0,%r15d
jmp    11b0 <CountTableInstances+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    120e <CountTableInstances+0xae>
lea    0xe00(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
@.str.1 = [19 x i8] c"Could not open %s\0A\00"
define i32 @CountTableInstances(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %27, label %25
10: ; preds = %2
%11 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %30
12: ; preds = %25, %14
%13 = load i8, i8* %4
switch i8 %13, label %17 [
i8 32, label %14
i8 10, label %14
]
14: ; preds = %12, %12
%15 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %27, label %12
17: ; preds = %12
%18 = call i32 @NormalizeSignature(i8* %4)
%19 = call i32 @strncmp(i8* %4, i8* %1, i32 4)
%20 = icmp eq i32 %19, 0
%21 = zext i1 %20 to i32
%22 = add i32 %26, %21
%23 = call i64 @fgets(i8* %4, i32 256, i32* %5)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %7, %17
%26 = phi i32 [ %22, %17 ], [ 0, %7 ]
br label %12
27: ; preds = %17, %14, %7
%28 = phi i32 [ 0, %7 ], [ %26, %14 ], [ %22, %17 ]
%29 = call i32 @fclose(i32* %5)
br label %30
30: ; preds = %27, %10
%31 = phi i32 [ %28, %27 ], [ 0, %10 ]
ret i32 %31
}