#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 uint8_t;
typedef int uint64_t;
typedef int int64_t;
typedef int int16_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int int_sqrt(int);
int log16(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int i, j;
  uint64_t sse = 0;
  uint64_t dev;
  FILE *f[2];
  uint8_t buf[2][2048];
  uint64_t psnr;
  int len = argc < 4 ? 1 : atoi(argv[3]);
  int64_t max = (1 << (8 * len)) - 1;
  int shift = argc < 5 ? 0 : atoi(argv[4]);
  int skip_bytes = argc < 6 ? 0 : atoi(argv[5]);
  int size0 = 0;
  int size1 = 0;
  if (argc < 3) {
    printf(
        "tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\n");
    printf("For WAV files use the following:\n");
    printf("./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\n");
    return -1;
  }
  f[0] = fopen(argv[1], "rb");
  f[1] = fopen(argv[2], "rb");
  if (!f[0] || !f[1]) {
    fprintf(stderr, "Could not open input files.\n");
    return -1;
  }
  fseek(f[shift < 0], shift < 0 ? -shift : shift, SEEK_SET);
  fseek(f[0], skip_bytes, SEEK_CUR);
  fseek(f[1], skip_bytes, SEEK_CUR);
  for (;;) {
    int s0 = fread(buf[0], 1, 2048, f[0]);
    int s1 = fread(buf[1], 1, 2048, f[1]);
    for (j = 0; j < ((s0) > (s1) ? (s1) : (s0)); j++) {
      int64_t a = buf[0][j];
      int64_t b = buf[1][j];
      if (len == 2) {
        a = (int16_t)(a | (buf[0][++j] << 8));
        b = (int16_t)(b | (buf[1][j] << 8));
      }
      sse += (a - b) * (a - b);
    }
    size0 += s0;
    size1 += s1;
    if (s0 + s1 <= 0)
      break;
  }
  i = ((size0) > (size1) ? (size1) : (size0)) / len;
  if (!i)
    i = 1;
  dev =
      int_sqrt(((sse / i) * 100 * 100) + (((sse % i) * 100 * 100) + i / 2) / i);
  if (sse)
    psnr = ((2 * log16(max << 16) + log16(i) - log16(sse)) * 284619LL * 100 +
            (1LL << 31)) /
           (1LL << 32);
  else
    psnr = 1000 * 100 - 1;
  printf("stddev:%5d.%02d PSNR:%3d.%02d bytes:%9d/%9d\n", (int)(dev / 100),
         (int)(dev % 100), (int)(psnr / 100), (int)(psnr % 100), size0, size1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11ba <main+0x3a>
mov    $0x1,%eax
mov    %eax,-0x4060(%rbp)
jmp    11cd <main+0x4d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x4060(%rbp)
mov    -0x4060(%rbp),%eax
mov    %eax,-0x4038(%rbp)
mov    -0x4038(%rbp),%ecx
shl    $0x3,%ecx
mov    $0x1,%eax
shl    %cl,%eax
sub    $0x1,%eax
mov    %eax,-0x403c(%rbp)
cmpl   $0x5,-0x8(%rbp)
jge    1209 <main+0x89>
xor    %eax,%eax
mov    %eax,-0x4064(%rbp)
jmp    121c <main+0x9c>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x4064(%rbp)
mov    -0x4064(%rbp),%eax
mov    %eax,-0x4040(%rbp)
cmpl   $0x6,-0x8(%rbp)
jge    123f <main+0xbf>
xor    %eax,%eax
mov    %eax,-0x4068(%rbp)
jmp    1252 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x4068(%rbp)
mov    -0x4068(%rbp),%eax
mov    %eax,-0x4044(%rbp)
movl   $0x0,-0x4048(%rbp)
movl   $0x0,-0x404c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    12b2 <main+0x132>
lea    0xd7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16ae <main+0x52e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xddf(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xdc7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     12f8 <main+0x178>
cmpq   $0x0,-0x28(%rbp)
jne    1319 <main+0x199>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16ae <main+0x52e>
cmpl   $0x0,-0x4040(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
cltq
mov    -0x30(%rbp,%rax,8),%rax
mov    %rax,-0x4070(%rbp)
cmpl   $0x0,-0x4040(%rbp)
jge    1356 <main+0x1d6>
xor    %eax,%eax
sub    -0x4040(%rbp),%eax
mov    %eax,-0x4074(%rbp)
jmp    1362 <main+0x1e2>
mov    -0x4040(%rbp),%eax
mov    %eax,-0x4074(%rbp)
mov    -0x4070(%rbp),%rdi
mov    -0x4074(%rbp),%esi
mov    0x2c5a(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x4044(%rbp),%esi
mov    0x2c5a(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
mov    -0x28(%rbp),%rdi
mov    -0x4044(%rbp),%esi
mov    0x2c42(%rip),%rax
mov    (%rax),%edx
call   1060 <fseek@plt>
lea    -0x4030(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %eax,-0x4050(%rbp)
lea    -0x4030(%rbp),%rdi
add    $0x2000,%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %eax,-0x4054(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x4078(%rbp)
mov    -0x4050(%rbp),%eax
cmp    -0x4054(%rbp),%eax
jle    1427 <main+0x2a7>
mov    -0x4054(%rbp),%eax
mov    %eax,-0x407c(%rbp)
jmp    1433 <main+0x2b3>
mov    -0x4050(%rbp),%eax
mov    %eax,-0x407c(%rbp)
mov    -0x4078(%rbp),%eax
mov    -0x407c(%rbp),%ecx
cmp    %ecx,%eax
jge    14e5 <main+0x365>
movslq -0x18(%rbp),%rax
mov    -0x4030(%rbp,%rax,4),%eax
mov    %eax,-0x4058(%rbp)
movslq -0x18(%rbp),%rax
mov    -0x2030(%rbp,%rax,4),%eax
mov    %eax,-0x405c(%rbp)
cmpl   $0x2,-0x4038(%rbp)
jne    14b6 <main+0x336>
mov    -0x4058(%rbp),%eax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
movslq %ecx,%rcx
mov    -0x4030(%rbp,%rcx,4),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x4058(%rbp)
mov    -0x405c(%rbp),%eax
movslq -0x18(%rbp),%rcx
mov    -0x2030(%rbp,%rcx,4),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    %eax,-0x405c(%rbp)
mov    -0x4058(%rbp),%eax
sub    -0x405c(%rbp),%eax
mov    -0x4058(%rbp),%ecx
sub    -0x405c(%rbp),%ecx
imul   %ecx,%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    13fb <main+0x27b>
mov    -0x4050(%rbp),%eax
add    -0x4048(%rbp),%eax
mov    %eax,-0x4048(%rbp)
mov    -0x4054(%rbp),%eax
add    -0x404c(%rbp),%eax
mov    %eax,-0x404c(%rbp)
mov    -0x4050(%rbp),%eax
add    -0x4054(%rbp),%eax
cmp    $0x0,%eax
jg     1523 <main+0x3a3>
jmp    1528 <main+0x3a8>
jmp    13ad <main+0x22d>
mov    -0x4048(%rbp),%eax
cmp    -0x404c(%rbp),%eax
jle    154b <main+0x3cb>
mov    -0x404c(%rbp),%eax
mov    %eax,-0x4080(%rbp)
jmp    1557 <main+0x3d7>
mov    -0x4048(%rbp),%eax
mov    %eax,-0x4080(%rbp)
mov    -0x4080(%rbp),%eax
cltd
idivl  -0x4038(%rbp)
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1578 <main+0x3f8>
movl   $0x1,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
imul   $0x64,%eax,%eax
imul   $0x64,%eax,%edi
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
imul   $0x64,%edx,%eax
imul   $0x64,%eax,%eax
mov    %eax,-0x4084(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4084(%rbp),%eax
add    %ecx,%eax
cltd
idivl  -0x14(%rbp)
add    %eax,%edi
call   10a0 <int_sqrt@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     163a <main+0x4ba>
mov    -0x403c(%rbp),%edi
shl    $0x10,%edi
call   1080 <log16@plt>
shl    $0x1,%eax
mov    %eax,-0x408c(%rbp)
mov    -0x14(%rbp),%edi
call   1080 <log16@plt>
mov    %eax,%ecx
mov    -0x408c(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x4088(%rbp)
mov    -0x1c(%rbp),%edi
call   1080 <log16@plt>
mov    %eax,%ecx
mov    -0x4088(%rbp),%eax
sub    %ecx,%eax
cltq
imul   $0x457cb,%rax,%rax
imul   $0x64,%rax,%rax
movabs $0x80000000,%rcx
add    %rcx,%rax
movabs $0x100000000,%rcx
cqto
idiv   %rcx
mov    %eax,-0x4034(%rbp)
jmp    1644 <main+0x4c4>
movl   $0x1869f,-0x4034(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x20(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %edx,-0x4090(%rbp)
mov    -0x4034(%rbp),%eax
mov    $0x64,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x4034(%rbp),%eax
mov    $0x64,%edi
cltd
idiv   %edi
mov    %edx,%r8d
mov    -0x4090(%rbp),%edx
mov    -0x4048(%rbp),%r9d
mov    -0x404c(%rbp),%eax
lea    0xa23(%rip),%rdi
mov    %eax,(%rsp)
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4038,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
cmp    $0x4,%edi
jge    11be <main+0x2e>
cmp    $0x3,%ebp
jne    11f0 <main+0x60>
mov    $0x1,%r13d
mov    $0xff,%r12d
jmp    11e3 <main+0x53>
mov    0x18(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r13d
lea    0x0(,%r13,8),%ecx
mov    $0xffffffff,%r12d
shl    %cl,%r12d
not    %r12d
cmp    $0x4,%ebp
jne    121e <main+0x8e>
movl   $0x0,0x8(%rsp)
xor    %r15d,%r15d
jmp    1246 <main+0xb6>
lea    0xe56(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1494 <main+0x304>
mov    0x20(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
cmp    $0x6,%ebp
jae    1239 <main+0xa9>
movl   $0x0,0x8(%rsp)
jmp    1246 <main+0xb6>
mov    0x28(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,0x8(%rsp)
mov    0x8(%rbx),%rdi
lea    0xdaf(%rip),%rbp
mov    %rbp,%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rax,0x20(%rsp)
mov    0x10(%rbx),%rdi
mov    %rbp,%rsi
call   1080 <fopen@plt>
mov    %rax,0x28(%rsp)
mov    %r14,0x10(%rsp)
test   %r14,%r14
je     138d <main+0x1fd>
mov    %rax,%rbp
test   %rax,%rax
je     138d <main+0x1fd>
mov    %r12d,0xc(%rsp)
mov    %r15d,%eax
shr    $0x1f,%eax
mov    0x20(%rsp,%rax,8),%rdi
mov    %r15d,%esi
neg    %esi
cmovs  %r15d,%esi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
call   1070 <fseek@plt>
mov    0x2d2e(%rip),%r14
mov    (%r14),%edx
mov    0x10(%rsp),%rdi
mov    0x8(%rsp),%ebx
mov    %ebx,%esi
call   1070 <fseek@plt>
mov    (%r14),%edx
mov    %rbp,0x18(%rsp)
mov    %rbp,%rdi
mov    %ebx,%esi
call   1070 <fseek@plt>
xor    %ebp,%ebp
xor    %r15d,%r15d
xor    %r12d,%r12d
jmp    12ff <main+0x16f>
nopl   0x0(%rax)
add    %r14d,%r15d
add    %eax,%r12d
add    %r14d,%eax
jle    13ac <main+0x21c>
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    0x10(%rsp),%rcx
call   1040 <fread@plt>
mov    %eax,%r14d
lea    0x2030(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    0x18(%rsp),%rcx
call   1040 <fread@plt>
cmp    %eax,%r14d
mov    %r14d,%r8d
cmovg  %eax,%r8d
test   %r8d,%r8d
jle    12f0 <main+0x160>
xor    %edx,%edx
jmp    135f <main+0x1cf>
nopw   0x0(%rax,%rax,1)
sub    %edi,%esi
imul   %esi,%esi
add    %esi,%ebp
add    $0x1,%edx
cmp    %r8d,%edx
jge    12f0 <main+0x160>
movslq %edx,%rbx
mov    0x30(%rsp,%rbx,4),%esi
mov    0x2030(%rsp,%rbx,4),%edi
cmp    $0x2,%r13d
jne    1350 <main+0x1c0>
lea    0x1(%rbx),%edx
mov    0x34(%rsp,%rbx,4),%ecx
shl    $0x8,%ecx
or     %ecx,%esi
mov    0x2034(%rsp,%rbx,4),%ecx
shl    $0x8,%ecx
or     %ecx,%edi
jmp    1350 <main+0x1c0>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
lea    0xc66(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    1494 <main+0x304>
cmp    %r12d,%r15d
mov    %r15d,%eax
cmovg  %r12d,%eax
cltd
idiv   %r13d
test   %eax,%eax
mov    $0x1,%ebx
cmovne %eax,%ebx
mov    %ebp,%eax
cltd
idiv   %ebx
imul   $0x2710,%eax,%edi
imul   $0x2710,%edx,%ecx
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
add    %ecx,%eax
cltd
idiv   %ebx
add    %eax,%edi
call   10b0 <int_sqrt@plt>
mov    %eax,%r14d
test   %ebp,%ebp
je     143f <main+0x2af>
mov    0xc(%rsp),%edi
shl    $0x10,%edi
call   1090 <log16@plt>
mov    %eax,%r13d
mov    %ebx,%edi
call   1090 <log16@plt>
lea    (%rax,%r13,2),%ebx
mov    %ebp,%edi
call   1090 <log16@plt>
sub    %eax,%ebx
movslq %ebx,%rax
imul   $0x1b24b4c,%rax,%rcx
movabs $0x17fffffff,%rax
add    %rcx,%rax
sub    $0xffffffff80000000,%rcx
test   %rcx,%rcx
cmovns %rcx,%rax
shr    $0x20,%rax
jmp    1444 <main+0x2b4>
mov    $0x1869f,%eax
movslq %r14d,%rdx
imul   $0x51eb851f,%rdx,%rsi
mov    %rsi,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rsi
add    %ecx,%esi
imul   $0x64,%esi,%ecx
sub    %ecx,%edx
movslq %eax,%r8
imul   $0x51eb851f,%r8,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x25,%rcx
add    %eax,%ecx
imul   $0x64,%ecx,%eax
sub    %eax,%r8d
mov    %r12d,(%rsp)
lea    0xb98(%rip),%rdi
xor    %ebx,%ebx
mov    %r15d,%r9d
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x4038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\0A\00"
@.str.1 = [34 x i8] c"For WAV files use the following:\0A\00"
@.str.2 = [60 x i8] c"./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\0A\00"
@.str.3 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.4 = [29 x i8] c"Could not open input files.\0A\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@.str.5 = [45 x i8] c"stddev:%5d.%02d PSNR:%3d.%02d bytes:%9d/%9d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca [2 x i32*]
%11 = alloca [2 x [2048 x i32]]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 4
br i1 %24, label %25, label %26
25: ; preds = %2
br label %31
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 3
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
br label %31
31: ; preds = %26, %25
%32 = phi i32 [ 1, %25 ], [ %30, %26 ]
store i32 %32, i32* %13
%33 = load i32, i32* %13
%34 = mul nsw i32 8, %33
%35 = shl i32 1, %34
%36 = sub nsw i32 %35, 1
store i32 %36, i32* %14
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 5
br i1 %38, label %39, label %40
39: ; preds = %31
br label %45
40: ; preds = %31
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 4
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
br label %45
45: ; preds = %40, %39
%46 = phi i32 [ 0, %39 ], [ %44, %40 ]
store i32 %46, i32* %15
%47 = load i32, i32* %4
%48 = icmp slt i32 %47, 6
br i1 %48, label %49, label %50
49: ; preds = %45
br label %55
50: ; preds = %45
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 5
%53 = load i8*, i8** %52
%54 = call i32 @atoi(i8* %53)
br label %55
55: ; preds = %50, %49
%56 = phi i32 [ 0, %49 ], [ %54, %50 ]
store i32 %56, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
%57 = load i32, i32* %4
%58 = icmp slt i32 %57, 3
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %257
63: ; preds = %55
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i32* @fopen(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%68 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 0
store i32* %67, i32** %68
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 2
%71 = load i8*, i8** %70
%72 = call i32* @fopen(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%73 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 1
store i32* %72, i32** %73
%74 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 0
%75 = load i32*, i32** %74
%76 = icmp ne i32* %75, null
br i1 %76, label %77, label %81
77: ; preds = %63
%78 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 1
%79 = load i32*, i32** %78
%80 = icmp ne i32* %79, null
br i1 %80, label %84, label %81
81: ; preds = %77, %63
%82 = load i32, i32* @stderr
%83 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %257
84: ; preds = %77
%85 = load i32, i32* %15
%86 = icmp slt i32 %85, 0
%87 = zext i1 %86 to i32
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 %88
%90 = load i32*, i32** %89
%91 = load i32, i32* %15
%92 = icmp slt i32 %91, 0
br i1 %92, label %93, label %96
93: ; preds = %84
%94 = load i32, i32* %15
%95 = sub nsw i32 0, %94
br label %98
96: ; preds = %84
%97 = load i32, i32* %15
br label %98
98: ; preds = %96, %93
%99 = phi i32 [ %95, %93 ], [ %97, %96 ]
%100 = load i32, i32* @SEEK_SET
%101 = call i32 @fseek(i32* %90, i32 %99, i32 %100)
%102 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 0
%103 = load i32*, i32** %102
%104 = load i32, i32* %16
%105 = load i32, i32* @SEEK_CUR
%106 = call i32 @fseek(i32* %103, i32 %104, i32 %105)
%107 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 1
%108 = load i32*, i32** %107
%109 = load i32, i32* %16
%110 = load i32, i32* @SEEK_CUR
%111 = call i32 @fseek(i32* %108, i32 %109, i32 %110)
br label %112
112: ; preds = %191, %98
%113 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %11, i64 0, i64 0
%114 = getelementptr inbounds [2048 x i32], [2048 x i32]* %113, i64 0, i64 0
%115 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 0
%116 = load i32*, i32** %115
%117 = call i32 @fread(i32* %114, i32 1, i32 2048, i32* %116)
store i32 %117, i32* %19
%118 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %11, i64 0, i64 1
%119 = getelementptr inbounds [2048 x i32], [2048 x i32]* %118, i64 0, i64 0
%120 = getelementptr inbounds [2 x i32*], [2 x i32*]* %10, i64 0, i64 1
%121 = load i32*, i32** %120
%122 = call i32 @fread(i32* %119, i32 1, i32 2048, i32* %121)
store i32 %122, i32* %20
store i32 0, i32* %7
br label %123
123: ; preds = %176, %112
%124 = load i32, i32* %7
%125 = load i32, i32* %19
%126 = load i32, i32* %20
%127 = icmp sgt i32 %125, %126
br i1 %127, label %128, label %130
128: ; preds = %123
%129 = load i32, i32* %20
br label %132
130: ; preds = %123
%131 = load i32, i32* %19
br label %132
132: ; preds = %130, %128
%133 = phi i32 [ %129, %128 ], [ %131, %130 ]
%134 = icmp slt i32 %124, %133
br i1 %134, label %135, label %179
135: ; preds = %132
%136 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %11, i64 0, i64 0
%137 = load i32, i32* %7
%138 = sext i32 %137 to i64
%139 = getelementptr inbounds [2048 x i32], [2048 x i32]* %136, i64 0, i64 %138
%140 = load i32, i32* %139
store i32 %140, i32* %21
%141 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %11, i64 0, i64 1
%142 = load i32, i32* %7
%143 = sext i32 %142 to i64
%144 = getelementptr inbounds [2048 x i32], [2048 x i32]* %141, i64 0, i64 %143
%145 = load i32, i32* %144
store i32 %145, i32* %22
%146 = load i32, i32* %13
%147 = icmp eq i32 %146, 2
br i1 %147, label %148, label %166
148: ; preds = %135
%149 = load i32, i32* %21
%150 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %11, i64 0, i64 0
%151 = load i32, i32* %7
%152 = add nsw i32 %151, 1
store i32 %152, i32* %7
%153 = sext i32 %152 to i64
%154 = getelementptr inbounds [2048 x i32], [2048 x i32]* %150, i64 0, i64 %153
%155 = load i32, i32* %154
%156 = shl i32 %155, 8
%157 = or i32 %149, %156
store i32 %157, i32* %21
%158 = load i32, i32* %22
%159 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %11, i64 0, i64 1
%160 = load i32, i32* %7
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds [2048 x i32], [2048 x i32]* %159, i64 0, i64 %161
%163 = load i32, i32* %162
%164 = shl i32 %163, 8
%165 = or i32 %158, %164
store i32 %165, i32* %22
br label %166
166: ; preds = %148, %135
%167 = load i32, i32* %21
%168 = load i32, i32* %22
%169 = sub nsw i32 %167, %168
%170 = load i32, i32* %21
%171 = load i32, i32* %22
%172 = sub nsw i32 %170, %171
%173 = mul nsw i32 %169, %172
%174 = load i32, i32* %8
%175 = add nsw i32 %174, %173
store i32 %175, i32* %8
br label %176
176: ; preds = %166
%177 = load i32, i32* %7
%178 = add nsw i32 %177, 1
store i32 %178, i32* %7
br label %123
179: ; preds = %132
%180 = load i32, i32* %19
%181 = load i32, i32* %17
%182 = add nsw i32 %181, %180
store i32 %182, i32* %17
%183 = load i32, i32* %20
%184 = load i32, i32* %18
%185 = add nsw i32 %184, %183
store i32 %185, i32* %18
%186 = load i32, i32* %19
%187 = load i32, i32* %20
%188 = add nsw i32 %186, %187
%189 = icmp sle i32 %188, 0
br i1 %189, label %190, label %191
190: ; preds = %179
br label %192
191: ; preds = %179
br label %112
192: ; preds = %190
%193 = load i32, i32* %17
%194 = load i32, i32* %18
%195 = icmp sgt i32 %193, %194
br i1 %195, label %196, label %198
196: ; preds = %192
%197 = load i32, i32* %18
br label %200
198: ; preds = %192
%199 = load i32, i32* %17
br label %200
200: ; preds = %198, %196
%201 = phi i32 [ %197, %196 ], [ %199, %198 ]
%202 = load i32, i32* %13
%203 = sdiv i32 %201, %202
store i32 %203, i32* %6
%204 = load i32, i32* %6
%205 = icmp ne i32 %204, 0
br i1 %205, label %207, label %206
206: ; preds = %200
store i32 1, i32* %6
br label %207
207: ; preds = %206, %200
%208 = load i32, i32* %8
%209 = load i32, i32* %6
%210 = sdiv i32 %208, %209
%211 = mul nsw i32 %210, 100
%212 = mul nsw i32 %211, 100
%213 = load i32, i32* %8
%214 = load i32, i32* %6
%215 = srem i32 %213, %214
%216 = mul nsw i32 %215, 100
%217 = mul nsw i32 %216, 100
%218 = load i32, i32* %6
%219 = sdiv i32 %218, 2
%220 = add nsw i32 %217, %219
%221 = load i32, i32* %6
%222 = sdiv i32 %220, %221
%223 = add nsw i32 %212, %222
%224 = call i32 @int_sqrt(i32 %223)
store i32 %224, i32* %9
%225 = load i32, i32* %8
%226 = icmp ne i32 %225, 0
br i1 %226, label %227, label %244
227: ; preds = %207
%228 = load i32, i32* %14
%229 = shl i32 %228, 16
%230 = call i32 @log16(i32 %229)
%231 = mul nsw i32 2, %230
%232 = load i32, i32* %6
%233 = call i32 @log16(i32 %232)
%234 = add nsw i32 %231, %233
%235 = load i32, i32* %8
%236 = call i32 @log16(i32 %235)
%237 = sub nsw i32 %234, %236
%238 = sext i32 %237 to i64
%239 = mul nsw i64 %238, 284619
%240 = mul nsw i64 %239, 100
%241 = add nsw i64 %240, 2147483648
%242 = sdiv i64 %241, 4294967296
%243 = trunc i64 %242 to i32
store i32 %243, i32* %12
br label %245
244: ; preds = %207
store i32 99999, i32* %12
br label %245
245: ; preds = %244, %227
%246 = load i32, i32* %9
%247 = sdiv i32 %246, 100
%248 = load i32, i32* %9
%249 = srem i32 %248, 100
%250 = load i32, i32* %12
%251 = sdiv i32 %250, 100
%252 = load i32, i32* %12
%253 = srem i32 %252, 100
%254 = load i32, i32* %17
%255 = load i32, i32* %18
%256 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %247, i32 %249, i32 %251, i32 %253, i32 %254, i32 %255)
store i32 0, i32* %3
br label %257
257: ; preds = %245, %81, %59
%258 = load i32, i32* %3
ret i32 %258
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.4 = [29 x i8] c"Could not open input files.\0A\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@.str.5 = [45 x i8] c"stddev:%5d.%02d PSNR:%3d.%02d bytes:%9d/%9d\0A\00"
@str = [65 x i8] c"tiny_psnr <file1> <file2> [<elem size> [<shift> [<skip bytes>]]]\00"
@str.6 = [33 x i8] c"For WAV files use the following:\00"
@str.7 = [59 x i8] c"./tiny_psnr file1.wav file2.wav 2 0 44 to skip the header.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32*]
%4 = alloca [2 x [2048 x i32]]
%5 = bitcast [2 x i32*]* %3 to i8*
%6 = bitcast [2 x [2048 x i32]]* %4 to i8*
%7 = icmp slt i32 %0, 4
br i1 %7, label %25, label %8
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 3
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = shl nsw i32 %11, 3
%13 = shl nsw i32 -1, %12
%14 = xor i32 %13, -1
%15 = icmp eq i32 %0, 4
br i1 %15, label %31, label %16
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 4
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = icmp ult i32 %0, 6
br i1 %20, label %31, label %21
21: ; preds = %16
%22 = getelementptr inbounds i8*, i8** %1, i64 5
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
br label %31
25: ; preds = %2
%26 = icmp eq i32 %0, 3
br i1 %26, label %31, label %27
27: ; preds = %25
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.6, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str.7, i64 0, i64 0))
br label %144
31: ; preds = %21, %16, %8, %25
%32 = phi i32 [ 0, %25 ], [ 0, %8 ], [ 0, %16 ], [ %24, %21 ]
%33 = phi i32 [ 255, %25 ], [ %14, %8 ], [ %14, %16 ], [ %14, %21 ]
%34 = phi i32 [ 1, %25 ], [ %11, %8 ], [ %11, %16 ], [ %11, %21 ]
%35 = phi i32 [ 0, %25 ], [ 0, %8 ], [ %19, %16 ], [ %19, %21 ]
%36 = getelementptr inbounds i8*, i8** %1, i64 1
%37 = load i8*, i8** %36
%38 = tail call i32* @fopen(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%39 = getelementptr inbounds [2 x i32*], [2 x i32*]* %3, i64 0, i64 0
store i32* %38, i32** %39
%40 = getelementptr inbounds i8*, i8** %1, i64 2
%41 = load i8*, i8** %40
%42 = tail call i32* @fopen(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%43 = getelementptr inbounds [2 x i32*], [2 x i32*]* %3, i64 0, i64 1
store i32* %42, i32** %43
%44 = icmp ne i32* %38, null
%45 = icmp ne i32* %42, null
%46 = and i1 %44, %45
br i1 %46, label %50, label %47
47: ; preds = %31
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
br label %144
50: ; preds = %31
%51 = lshr i32 %35, 31
%52 = zext i32 %51 to i64
%53 = getelementptr inbounds [2 x i32*], [2 x i32*]* %3, i64 0, i64 %52
%54 = load i32*, i32** %53
%55 = tail call i32 @llvm.abs.i32(i32 %35, i1 true)
%56 = load i32, i32* @SEEK_SET
%57 = tail call i32 @fseek(i32* %54, i32 %55, i32 %56)
%58 = load i32, i32* @SEEK_CUR
%59 = tail call i32 @fseek(i32* %38, i32 %32, i32 %58)
%60 = load i32, i32* @SEEK_CUR
%61 = tail call i32 @fseek(i32* %42, i32 %32, i32 %60)
%62 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %4, i64 0, i64 0, i64 0
%63 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %4, i64 0, i64 1, i64 0
%64 = icmp eq i32 %34, 2
br label %65
65: ; preds = %102, %50
%66 = phi i32 [ 0, %50 ], [ %103, %102 ]
%67 = phi i32 [ 0, %50 ], [ %104, %102 ]
%68 = phi i32 [ 0, %50 ], [ %105, %102 ]
%69 = call i32 @fread(i32* %62, i32 1, i32 2048, i32* %38)
%70 = call i32 @fread(i32* %63, i32 1, i32 2048, i32* %42)
%71 = icmp sgt i32 %69, %70
%72 = select i1 %71, i32 %70, i32 %69
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %102
74: ; preds = %65, %93
%75 = phi i32 [ %100, %93 ], [ 0, %65 ]
%76 = phi i32 [ %99, %93 ], [ %66, %65 ]
%77 = sext i32 %75 to i64
%78 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %4, i64 0, i64 0, i64 %77
%79 = load i32, i32* %78
%80 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %4, i64 0, i64 1, i64 %77
%81 = load i32, i32* %80
br i1 %64, label %82, label %93
82: ; preds = %74
%83 = add nsw i32 %75, 1
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %4, i64 0, i64 0, i64 %84
%86 = load i32, i32* %85
%87 = shl i32 %86, 8
%88 = or i32 %87, %79
%89 = getelementptr inbounds [2 x [2048 x i32]], [2 x [2048 x i32]]* %4, i64 0, i64 1, i64 %84
%90 = load i32, i32* %89
%91 = shl i32 %90, 8
%92 = or i32 %91, %81
br label %93
93: ; preds = %82, %74
%94 = phi i32 [ %83, %82 ], [ %75, %74 ]
%95 = phi i32 [ %88, %82 ], [ %79, %74 ]
%96 = phi i32 [ %92, %82 ], [ %81, %74 ]
%97 = sub nsw i32 %95, %96
%98 = mul nsw i32 %97, %97
%99 = add nsw i32 %98, %76
%100 = add nsw i32 %94, 1
%101 = icmp slt i32 %100, %72
br i1 %101, label %74, label %102
102: ; preds = %93, %65
%103 = phi i32 [ %66, %65 ], [ %99, %93 ]
%104 = add nsw i32 %69, %67
%105 = add nsw i32 %70, %68
%106 = add nsw i32 %70, %69
%107 = icmp slt i32 %106, 1
br i1 %107, label %108, label %65
108: ; preds = %102
%109 = icmp sgt i32 %104, %105
%110 = select i1 %109, i32 %105, i32 %104
%111 = sdiv i32 %110, %34
%112 = icmp eq i32 %111, 0
%113 = select i1 %112, i32 1, i32 %111
%114 = sdiv i32 %103, %113
%115 = mul i32 %114, 10000
%116 = srem i32 %103, %113
%117 = mul i32 %116, 10000
%118 = sdiv i32 %113, 2
%119 = add nsw i32 %117, %118
%120 = sdiv i32 %119, %113
%121 = add nsw i32 %120, %115
%122 = tail call i32 @int_sqrt(i32 %121)
%123 = icmp eq i32 %103, 0
br i1 %123, label %137, label %124
124: ; preds = %108
%125 = shl i32 %33, 16
%126 = tail call i32 @log16(i32 %125)
%127 = shl nsw i32 %126, 1
%128 = tail call i32 @log16(i32 %113)
%129 = add nsw i32 %127, %128
%130 = tail call i32 @log16(i32 %103)
%131 = sub i32 %129, %130
%132 = sext i32 %131 to i64
%133 = mul nsw i64 %132, 28461900
%134 = add nsw i64 %133, 2147483648
%135 = sdiv i64 %134, 4294967296
%136 = trunc i64 %135 to i32
br label %137
137: ; preds = %108, %124
%138 = phi i32 [ %136, %124 ], [ 99999, %108 ]
%139 = sdiv i32 %122, 100
%140 = srem i32 %122, 100
%141 = sdiv i32 %138, 100
%142 = srem i32 %138, 100
%143 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %139, i32 %140, i32 %141, i32 %142, i32 %104, i32 %105)
br label %144
144: ; preds = %137, %47, %27
%145 = phi i32 [ -1, %27 ], [ 0, %137 ], [ -1, %47 ]
ret i32 %145
}