#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int peakval(short *, int);
int peakval_port(short *, int);
int /*<<< orphan*/ printf(char *, ...);
int random();
int /*<<< orphan*/ srandom(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main() {
  int i, s;
  int result, rresult;
  signed short samples[200002];
  srandom(time(NULL));
  for (i = 0; i < 200002; i++) {
    do {
      s = random() & 0x0fff;
    } while (s == 0x8000);
    samples[i] = s;
  }
  samples[5] = 25000;
  rresult = peakval_port(&samples[1], 200002 - 1);
  result = peakval(&samples[1], 200002 - 1);
  if (result == rresult) {
    printf("OK\n");
  } else {
    printf("peak mismatch: %d != %d\n", result, rresult);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x61aa0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x30d42,-0x8(%rbp)
jge    11e7 <main+0x77>
jmp    11ab <main+0x3b>
mov    $0x0,%al
call   1070 <random@plt>
and    $0xfff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x8000,-0xc(%rbp)
je     11ab <main+0x3b>
mov    -0xc(%rbp),%eax
mov    %ax,%cx
movslq -0x8(%rbp),%rax
mov    %cx,-0x61aa0(%rbp,%rax,2)
ff
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1199 <main+0x29>
movw   $0x61a8,-0x61a96(%rbp)
a8 61
lea    -0x61aa0(%rbp),%rdi
add    $0x2,%rdi
mov    $0x30d41,%esi
call   1050 <peakval_port@plt>
mov    %eax,-0x14(%rbp)
lea    -0x61aa0(%rbp),%rdi
add    $0x2,%rdi
mov    $0x30d41,%esi
call   1080 <peakval@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    123f <main+0xcf>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1253 <main+0xe3>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x61a88,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1030 <srandom@plt>
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <random@plt>
and    $0xfff,%eax
mov    %ax,(%rsp,%rbx,2)
add    $0x1,%rbx
cmp    $0x30d42,%rbx
jne    11a0 <main+0x20>
movw   $0x61a8,0xa(%rsp)
lea    0x2(%rsp),%r14
mov    %r14,%rdi
mov    $0x30d41,%esi
call   1060 <peakval_port@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    $0x30d41,%esi
call   1090 <peakval@plt>
cmp    %ebx,%eax
jne    11fc <main+0x7c>
lea    0xe29(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdfd(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"OK\0A\00"
@.str.1 = [25 x i8] c"peak mismatch: %d != %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [200002 x i16]
store i32 0, i32* %1
%7 = call i32 @time(i32* null)
%8 = call i32 @srandom(i32 %7)
store i32 0, i32* %2
br label %9
9: ; preds = %25, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 200002
br i1 %11, label %12, label %28
12: ; preds = %9
br label %13
13: ; preds = %16, %12
%14 = call i32 (...) @random()
%15 = and i32 %14, 4095
store i32 %15, i32* %3
br label %16
16: ; preds = %13
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 32768
br i1 %18, label %13, label %19
19: ; preds = %16
%20 = load i32, i32* %3
%21 = trunc i32 %20 to i16
%22 = load i32, i32* %2
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [200002 x i16], [200002 x i16]* %6, i64 0, i64 %23
store i16 %21, i16* %24
br label %25
25: ; preds = %19
%26 = load i32, i32* %2
%27 = add nsw i32 %26, 1
store i32 %27, i32* %2
br label %9
28: ; preds = %9
%29 = getelementptr inbounds [200002 x i16], [200002 x i16]* %6, i64 0, i64 5
store i16 25000, i16* %29
%30 = getelementptr inbounds [200002 x i16], [200002 x i16]* %6, i64 0, i64 1
%31 = call i32 @peakval_port(i16* %30, i32 200001)
store i32 %31, i32* %5
%32 = getelementptr inbounds [200002 x i16], [200002 x i16]* %6, i64 0, i64 1
%33 = call i32 @peakval(i16* %32, i32 200001)
store i32 %33, i32* %4
%34 = load i32, i32* %4
%35 = load i32, i32* %5
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %39
37: ; preds = %28
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %43
39: ; preds = %28
%40 = load i32, i32* %4
%41 = load i32, i32* %5
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 %41)
br label %43
43: ; preds = %39, %37
%44 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [25 x i8] c"peak mismatch: %d != %d\0A\00"
@str = [3 x i8] c"OK\00"
define i32 @main() {
%1 = alloca [200002 x i16]
%2 = bitcast [200002 x i16]* %1 to i8*
%3 = tail call i32 @time(i32* null)
%4 = tail call i32 @srandom(i32 %3)
br label %5
5: ; preds = %0, %5
%6 = phi i64 [ 0, %0 ], [ %11, %5 ]
%7 = tail call i32 (...) @random()
%8 = trunc i32 %7 to i16
%9 = and i16 %8, 4095
%10 = getelementptr inbounds [200002 x i16], [200002 x i16]* %1, i64 0, i64 %6
store i16 %9, i16* %10
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, 200002
br i1 %12, label %13, label %5
13: ; preds = %5
%14 = getelementptr inbounds [200002 x i16], [200002 x i16]* %1, i64 0, i64 5
store i16 25000, i16* %14
%15 = getelementptr inbounds [200002 x i16], [200002 x i16]* %1, i64 0, i64 1
%16 = call i32 @peakval_port(i16* %15, i32 200001)
%17 = call i32 @peakval(i16* %15, i32 200001)
%18 = icmp eq i32 %17, %16
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %23
21: ; preds = %13
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %16)
br label %23
23: ; preds = %21, %19
%24 = call i32 @exit(i32 0)
unreachable
}