#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*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned short *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ fwrite(short *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  if (argc > 1) {
    fprintf(stderr, "< input > output\n");
    return 1;
  }
  fprintf(stderr, "%s: running ...\n", argv[0]);
  for (;;) {
    unsigned short x[4096];
    short y[4096];
    int r = fread(x, sizeof(unsigned short), 4096, stdin);
    if (r == 0)
      break;
    {
      int i;
      for (i = 0; i < r; i++) {
        if (x[i] > 32767)
          y[i] = 32767;
        else
          y[i] = (short)x[i];
      }
    }
    fwrite(y, sizeof(short), r, stdout);
  }
  fprintf(stderr, "%s: done\n", argv[0]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1176 <main+0x46>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1298 <main+0x168>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe85(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
lea    -0x2010(%rbp),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%ecx
mov    $0x2,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x4014(%rbp)
cmpl   $0x0,-0x4014(%rbp)
jne    11cb <main+0x9b>
jmp    1273 <main+0x143>
movl   $0x0,-0x4018(%rbp)
mov    -0x4018(%rbp),%eax
cmp    -0x4014(%rbp),%eax
jge    124e <main+0x11e>
movslq -0x4018(%rbp),%rax
movzwl -0x2010(%rbp,%rax,2),%eax
ff
cmp    $0x7fff,%eax
jle    1217 <main+0xe7>
movslq -0x4018(%rbp),%rax
movw   $0x7fff,-0x4010(%rbp,%rax,2)
ff ff 7f
jmp    1235 <main+0x105>
movslq -0x4018(%rbp),%rax
mov    -0x2010(%rbp,%rax,2),%cx
ff
movslq -0x4018(%rbp),%rax
mov    %cx,-0x4010(%rbp,%rax,2)
ff
jmp    123a <main+0x10a>
mov    -0x4018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4018(%rbp)
jmp    11d5 <main+0xa5>
lea    -0x4010(%rbp),%rdi
mov    -0x4014(%rbp),%edx
mov    0x2d6e(%rip),%rax
mov    (%rax),%ecx
mov    $0x2,%esi
call   1050 <fwrite@plt>
jmp    1194 <main+0x64>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd99(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x4020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4018,%rsp
mov    %edi,%eax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%edi
cmp    $0x2,%eax
jl     1169 <main+0x39>
lea    0xeb8(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    1360 <main+0x230>
mov    %rsi,0x8(%rsp)
mov    (%rsi),%rdx
lea    0xeaa(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e62(%rip),%r13
mov    0x0(%r13),%ecx
lea    0x10(%rsp),%rdi
mov    $0x2,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     133f <main+0x20f>
mov    $0x7fff,%r12d
movdqa 0xe4c(%rip),%xmm5
mov    0x2e15(%rip),%r14
lea    0x2010(%rsp),%r15
lea    0x10(%rsp),%rbx
jmp    1208 <main+0xd8>
nopw   0x0(%rax,%rax,1)
mov    (%r14),%ecx
mov    %r15,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1050 <fwrite@plt>
mov    0x0(%r13),%ecx
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
movdqa 0xe00(%rip),%xmm5
test   %eax,%eax
je     133f <main+0x20f>
test   %eax,%eax
jle    11d0 <main+0xa0>
mov    %eax,%ecx
cmp    $0x10,%eax
jae    1220 <main+0xf0>
xor    %edx,%edx
jmp    1310 <main+0x1e0>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%edx
and    $0xfffffff0,%edx
lea    -0x10(%rdx),%rsi
mov    %rsi,%rbp
shr    $0x4,%rbp
add    $0x1,%rbp
test   %rsi,%rsi
je     1335 <main+0x205>
mov    %rbp,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
movdqa 0x10(%rsp,%rsi,2),%xmm0
movdqa 0x20(%rsp,%rsi,2),%xmm1
movdqa 0x30(%rsp,%rsi,2),%xmm2
movdqa 0x40(%rsp,%rsi,2),%xmm3
movdqa %xmm0,%xmm4
psubusw %xmm5,%xmm4
psubw  %xmm4,%xmm0
movdqa %xmm1,%xmm4
psubusw %xmm5,%xmm4
psubw  %xmm4,%xmm1
movdqa %xmm0,0x2010(%rsp,%rsi,2)
movdqa %xmm1,0x2020(%rsp,%rsi,2)
movdqa %xmm2,%xmm0
psubusw %xmm5,%xmm0
psubw  %xmm0,%xmm2
movdqa %xmm3,%xmm0
psubusw %xmm5,%xmm0
psubw  %xmm0,%xmm3
movdqa %xmm2,0x2030(%rsp,%rsi,2)
movdqa %xmm3,0x2040(%rsp,%rsi,2)
add    $0x20,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1250 <main+0x120>
test   $0x1,%bpl
je     1302 <main+0x1d2>
movdqa 0x10(%rsp,%rsi,2),%xmm0
movdqa 0x20(%rsp,%rsi,2),%xmm1
movdqa %xmm0,%xmm2
psubusw %xmm5,%xmm2
psubw  %xmm2,%xmm0
movdqa %xmm1,%xmm2
psubusw %xmm5,%xmm2
psubw  %xmm2,%xmm1
movdqa %xmm0,0x2010(%rsp,%rsi,2)
movdqa %xmm1,0x2020(%rsp,%rsi,2)
cmp    %rcx,%rdx
je     11d0 <main+0xa0>
nopl   0x0(%rax,%rax,1)
movzwl 0x10(%rsp,%rdx,2),%esi
cmp    $0x7fff,%esi
cmovae %r12d,%esi
mov    %si,0x2010(%rsp,%rdx,2)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1310 <main+0x1e0>
jmp    11d0 <main+0xa0>
xor    %esi,%esi
test   $0x1,%bpl
jne    12cc <main+0x19c>
jmp    1302 <main+0x1d2>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rax
mov    (%rax),%rdx
lea    0xcdc(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x4018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"< input > output\0A\00"
@.str.1 = [17 x i8] c"%s: running ...\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [10 x i8] c"%s: done\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4096 x i16]
%7 = alloca [4096 x i16]
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %67
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %56, %15
%22 = getelementptr inbounds [4096 x i16], [4096 x i16]* %6, i64 0, i64 0
%23 = load i32, i32* @stdin
%24 = call i32 @fread(i16* %22, i32 2, i32 4096, i32 %23)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
br label %61
28: ; preds = %21
store i32 0, i32* %9
br label %29
29: ; preds = %53, %28
%30 = load i32, i32* %9
%31 = load i32, i32* %8
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %56
33: ; preds = %29
%34 = load i32, i32* %9
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [4096 x i16], [4096 x i16]* %6, i64 0, i64 %35
%37 = load i16, i16* %36
%38 = zext i16 %37 to i32
%39 = icmp sgt i32 %38, 32767
br i1 %39, label %40, label %44
40: ; preds = %33
%41 = load i32, i32* %9
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4096 x i16], [4096 x i16]* %7, i64 0, i64 %42
store i16 32767, i16* %43
br label %52
44: ; preds = %33
%45 = load i32, i32* %9
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [4096 x i16], [4096 x i16]* %6, i64 0, i64 %46
%48 = load i16, i16* %47
%49 = load i32, i32* %9
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [4096 x i16], [4096 x i16]* %7, i64 0, i64 %50
store i16 %48, i16* %51
br label %52
52: ; preds = %44, %40
br label %53
53: ; preds = %52
%54 = load i32, i32* %9
%55 = add nsw i32 %54, 1
store i32 %55, i32* %9
br label %29
56: ; preds = %29
%57 = getelementptr inbounds [4096 x i16], [4096 x i16]* %7, i64 0, i64 0
%58 = load i32, i32* %8
%59 = load i32, i32* @stdout
%60 = call i32 @fwrite(i16* %57, i32 2, i32 %58, i32 %59)
br label %21
61: ; preds = %27
%62 = load i32, i32* @stderr
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 0
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %65)
store i32 0, i32* %3
br label %67
67: ; preds = %61, %12
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"< input > output\0A\00"
@.str.1 = [17 x i8] c"%s: running ...\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [10 x i8] c"%s: done\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4096 x i16]
%4 = alloca [4096 x i16]
%5 = icmp sgt i32 %0, 1
%6 = load i32, i32* @stderr
br i1 %5, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %111
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = bitcast [4096 x i16]* %3 to i8*
%13 = bitcast [4096 x i16]* %4 to i8*
%14 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 0
%15 = load i32, i32* @stdin
%16 = call i32 @fread(i16* %14, i32 2, i32 4096, i32 %15)
%17 = icmp eq i32 %16, 0
br i1 %17, label %107, label %18
18: ; preds = %9
%19 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 0
br label %20
20: ; preds = %18, %101
%21 = phi i32 [ %16, %18 ], [ %105, %101 ]
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %101
23: ; preds = %20
%24 = zext i32 %21 to i64
%25 = icmp ult i32 %21, 16
br i1 %25, label %90, label %26
26: ; preds = %23
%27 = and i64 %24, 4294967280
%28 = add nsw i64 %27, -16
%29 = lshr exact i64 %28, 4
%30 = add nuw nsw i64 %29, 1
%31 = and i64 %30, 1
%32 = icmp eq i64 %28, 0
br i1 %32, label %70, label %33
33: ; preds = %26
%34 = and i64 %30, 2305843009213693950
br label %35
35: ; preds = %35, %33
%36 = phi i64 [ 0, %33 ], [ %67, %35 ]
%37 = phi i64 [ 0, %33 ], [ %68, %35 ]
%38 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %36
%39 = bitcast i16* %38 to <8 x i16>*
%40 = load <8 x i16>, <8 x i16>* %39
%41 = getelementptr inbounds i16, i16* %38, i64 8
%42 = bitcast i16* %41 to <8 x i16>*
%43 = load <8 x i16>, <8 x i16>* %42
%44 = icmp ult <8 x i16> %40, <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%45 = icmp ult <8 x i16> %43, <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%46 = select <8 x i1> %44, <8 x i16> %40, <8 x i16> <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%47 = select <8 x i1> %45, <8 x i16> %43, <8 x i16> <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%48 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 %36
%49 = bitcast i16* %48 to <8 x i16>*
store <8 x i16> %46, <8 x i16>* %49
%50 = getelementptr inbounds i16, i16* %48, i64 8
%51 = bitcast i16* %50 to <8 x i16>*
store <8 x i16> %47, <8 x i16>* %51
%52 = or i64 %36, 16
%53 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %52
%54 = bitcast i16* %53 to <8 x i16>*
%55 = load <8 x i16>, <8 x i16>* %54
%56 = getelementptr inbounds i16, i16* %53, i64 8
%57 = bitcast i16* %56 to <8 x i16>*
%58 = load <8 x i16>, <8 x i16>* %57
%59 = icmp ult <8 x i16> %55, <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%60 = icmp ult <8 x i16> %58, <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%61 = select <8 x i1> %59, <8 x i16> %55, <8 x i16> <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%62 = select <8 x i1> %60, <8 x i16> %58, <8 x i16> <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%63 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 %52
%64 = bitcast i16* %63 to <8 x i16>*
store <8 x i16> %61, <8 x i16>* %64
%65 = getelementptr inbounds i16, i16* %63, i64 8
%66 = bitcast i16* %65 to <8 x i16>*
store <8 x i16> %62, <8 x i16>* %66
%67 = add nuw i64 %36, 32
%68 = add i64 %37, 2
%69 = icmp eq i64 %68, %34
br i1 %69, label %70, label %35
70: ; preds = %35, %26
%71 = phi i64 [ 0, %26 ], [ %67, %35 ]
%72 = icmp eq i64 %31, 0
br i1 %72, label %88, label %73
73: ; preds = %70
%74 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %71
%75 = bitcast i16* %74 to <8 x i16>*
%76 = load <8 x i16>, <8 x i16>* %75
%77 = getelementptr inbounds i16, i16* %74, i64 8
%78 = bitcast i16* %77 to <8 x i16>*
%79 = load <8 x i16>, <8 x i16>* %78
%80 = icmp ult <8 x i16> %76, <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%81 = icmp ult <8 x i16> %79, <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%82 = select <8 x i1> %80, <8 x i16> %76, <8 x i16> <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%83 = select <8 x i1> %81, <8 x i16> %79, <8 x i16> <i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767, i16 32767>
%84 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 %71
%85 = bitcast i16* %84 to <8 x i16>*
store <8 x i16> %82, <8 x i16>* %85
%86 = getelementptr inbounds i16, i16* %84, i64 8
%87 = bitcast i16* %86 to <8 x i16>*
store <8 x i16> %83, <8 x i16>* %87
br label %88
88: ; preds = %70, %73
%89 = icmp eq i64 %27, %24
br i1 %89, label %101, label %90
90: ; preds = %23, %88
%91 = phi i64 [ 0, %23 ], [ %27, %88 ]
br label %92
92: ; preds = %90, %92
%93 = phi i64 [ %99, %92 ], [ %91, %90 ]
%94 = getelementptr inbounds [4096 x i16], [4096 x i16]* %3, i64 0, i64 %93
%95 = load i16, i16* %94
%96 = icmp ult i16 %95, 32767
%97 = select i1 %96, i16 %95, i16 32767
%98 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 %93
store i16 %97, i16* %98
%99 = add nuw nsw i64 %93, 1
%100 = icmp eq i64 %99, %24
br i1 %100, label %101, label %92
101: ; preds = %92, %88, %20
%102 = load i32, i32* @stdout
%103 = call i32 @fwrite(i16* %19, i32 2, i32 %21, i32 %102)
%104 = load i32, i32* @stdin
%105 = call i32 @fread(i16* %14, i32 2, i32 4096, i32 %104)
%106 = icmp eq i32 %105, 0
br i1 %106, label %107, label %20
107: ; preds = %101, %9
%108 = load i32, i32* @stderr
%109 = load i8*, i8** %1
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %109)
br label %111
111: ; preds = %107, %7
%112 = phi i32 [ 1, %7 ], [ 0, %107 ]
ret i32 %112
}