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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned int, unsigned char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ vlogSignature(unsigned char *, unsigned int,
                                 unsigned char *);
void computeSigs(const char *zFilename) {
  FILE *in = fopen(zFilename, "rb");
  unsigned pgsz;
  size_t got;
  unsigned n;
  unsigned char aBuf[50];
  unsigned char aPage[65536];
  if (in == 0) {
    fprintf(stderr, "cannot open \"%s\"\n", zFilename);
    return;
  }
  got = fread(aBuf, 1, sizeof(aBuf), in);
  if (got != sizeof(aBuf)) {
    goto endComputeSigs;
  }
  pgsz = aBuf[16] * 256 + aBuf[17];
  if (pgsz == 1)
    pgsz = 65536;
  if ((pgsz & (pgsz - 1)) != 0) {
    fprintf(stderr, "invalid page size: %02x%02x\n", aBuf[16], aBuf[17]);
    goto endComputeSigs;
  }
  rewind(in);
  for (n = 1; (got = fread(aPage, 1, pgsz, in)) == pgsz; n++) {
    vlogSignature(aPage, pgsz, aBuf);
    printf("%4d: %s\n", n, aBuf);
  }
endComputeSigs:
  fclose(in);
}


x86 assembly (clang, -O0):
<computeSigs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10060,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe76(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11be <computeSigs+0x4e>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12bc <computeSigs+0x14c>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x32,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x32,-0x20(%rbp)
je     11e9 <computeSigs+0x79>
jmp    12b3 <computeSigs+0x143>
movzbl -0x50(%rbp),%eax
shl    $0x8,%eax
movzbl -0x4f(%rbp),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    120a <computeSigs+0x9a>
movl   $0x10000,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1242 <computeSigs+0xd2>
mov    0x2dbb(%rip),%rax
mov    (%rax),%edi
movzbl -0x50(%rbp),%edx
movzbl -0x4f(%rbp),%ecx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    12b3 <computeSigs+0x143>
mov    -0x10(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x1,-0x24(%rbp)
lea    -0x10060(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%ecx
cmp    %rcx,%rax
jne    12ae <computeSigs+0x13e>
lea    -0x10060(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x60(%rbp),%rdx
call   1080 <vlogSignature@plt>
mov    -0x24(%rbp),%esi
lea    -0x60(%rbp),%rdx
lea    0xd97(%rip),%rdi
call   1050 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1252 <computeSigs+0xe2>
jmp    12b3 <computeSigs+0x143>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x10060,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeSigs>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10048,%rsp
mov    %rdi,%rbx
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     125a <computeSigs+0xea>
mov    %rax,%r14
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x32,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x32,%rax
jne    129c <computeSigs+0x12c>
movzbl 0x10(%rsp),%edx
mov    %edx,%eax
shl    $0x8,%eax
movzbl 0x11(%rsp),%ecx
or     %ecx,%eax
cmp    $0x1,%eax
mov    $0x10000,%ebx
cmovne %eax,%ebx
lea    -0x1(%rbx),%eax
test   %eax,%ebx
jne    1285 <computeSigs+0x115>
mov    %r14,%rdi
call   1060 <rewind@plt>
lea    0x40(%rsp),%rdi
mov    $0x1,%ebp
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %rax,%r15
mov    %ebx,%eax
cmp    %rax,%r15
jne    129c <computeSigs+0x12c>
lea    0x40(%rsp),%r12
mov    %rsp,%r13
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r13,%rdx
call   1080 <vlogSignature@plt>
lea    0xdfe(%rip),%rdi
mov    %ebp,%esi
mov    %r13,%rdx
call   1050 <printf@plt>
add    $0x1,%ebp
mov    %r12,%rdi
mov    $0x1,%esi
mov    %ebx,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
je     1220 <computeSigs+0xb0>
jmp    129c <computeSigs+0x12c>
mov    0x2d7f(%rip),%rax
mov    (%rax),%edi
lea    0xd99(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
add    $0x10048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <fprintf@plt>
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x10048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"cannot open \22%s\22\0A\00"
@.str.2 = [29 x i8] c"invalid page size: %02x%02x\0A\00"
@.str.3 = [9 x i8] c"%4d: %s\0A\00"
define void @computeSigs(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca [50 x i8]
%8 = alloca [65536 x i8]
store i8* %0, i8** %2
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %17
13: ; preds = %1
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %2
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %77
17: ; preds = %1
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %3
%20 = call i64 @fread(i8* %18, i32 1, i32 50, i32* %19)
store i64 %20, i64* %5
%21 = load i64, i64* %5
%22 = icmp ne i64 %21, 50
br i1 %22, label %23, label %24
23: ; preds = %17
br label %74
24: ; preds = %17
%25 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 16
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = mul nsw i32 %27, 256
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 17
%30 = load i8, i8* %29
%31 = zext i8 %30 to i32
%32 = add nsw i32 %28, %31
store i32 %32, i32* %4
%33 = load i32, i32* %4
%34 = icmp eq i32 %33, 1
br i1 %34, label %35, label %36
35: ; preds = %24
store i32 65536, i32* %4
br label %36
36: ; preds = %35, %24
%37 = load i32, i32* %4
%38 = load i32, i32* %4
%39 = sub i32 %38, 1
%40 = and i32 %37, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %51
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 16
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 17
%48 = load i8, i8* %47
%49 = zext i8 %48 to i32
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %46, i32 %49)
br label %74
51: ; preds = %36
%52 = load i32*, i32** %3
%53 = call i32 @rewind(i32* %52)
store i32 1, i32* %6
br label %54
54: ; preds = %70, %51
%55 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%56 = load i32, i32* %4
%57 = load i32*, i32** %3
%58 = call i64 @fread(i8* %55, i32 1, i32 %56, i32* %57)
store i64 %58, i64* %5
%59 = load i32, i32* %4
%60 = zext i32 %59 to i64
%61 = icmp eq i64 %58, %60
br i1 %61, label %62, label %73
62: ; preds = %54
%63 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%64 = load i32, i32* %4
%65 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%66 = call i32 @vlogSignature(i8* %63, i32 %64, i8* %65)
%67 = load i32, i32* %6
%68 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%69 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %67, i8* %68)
br label %70
70: ; preds = %62
%71 = load i32, i32* %6
%72 = add i32 %71, 1
store i32 %72, i32* %6
br label %54
73: ; preds = %54
br label %74
74: ; preds = %73, %42, %23
%75 = load i32*, i32** %3
%76 = call i32 @fclose(i32* %75)
br label %77
77: ; preds = %74, %13
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [18 x i8] c"cannot open \22%s\22\0A\00"
@.str.2 = [29 x i8] c"invalid page size: %02x%02x\0A\00"
@.str.3 = [9 x i8] c"%4d: %s\0A\00"
define void @computeSigs(i8* %0) {
%2 = alloca [50 x i8]
%3 = alloca [65536 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%7 = icmp eq i32* %4, null
br i1 %7, label %8, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %44
11: ; preds = %1
%12 = call i64 @fread(i8* %5, i32 1, i32 50, i32* %4)
%13 = icmp eq i64 %12, 50
br i1 %13, label %14, label %42
14: ; preds = %11
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 16
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = shl nuw nsw i32 %17, 8
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 17
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = or i32 %18, %21
%23 = icmp eq i32 %22, 1
%24 = select i1 %23, i32 65536, i32 %22
%25 = tail call i32 @llvm.ctpop.i32(i32 %24)
%26 = icmp ult i32 %25, 2
br i1 %26, label %30, label %27
27: ; preds = %14
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %21)
br label %42
30: ; preds = %14
%31 = tail call i32 @rewind(i32* %4)
%32 = call i64 @fread(i8* %6, i32 1, i32 %24, i32* %4)
%33 = zext i32 %24 to i64
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %42
35: ; preds = %30, %35
%36 = phi i32 [ %39, %35 ], [ 1, %30 ]
%37 = call i32 @vlogSignature(i8* %6, i32 %24, i8* %5)
%38 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %36, i8* %5)
%39 = add i32 %36, 1
%40 = call i64 @fread(i8* %6, i32 1, i32 %24, i32* %4)
%41 = icmp eq i64 %40, %32
br i1 %41, label %35, label %42
42: ; preds = %35, %30, %11, %27
%43 = call i32 @fclose(i32* %4)
br label %44
44: ; preds = %42, %8
ret void
}