#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(int *, 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, "int2short < entrada > salida\n");
    return 1;
  }
  fprintf(stderr, "int2short: running\n");
  for (;;) {
    int x[4096];
    short y[4096];
    int r = fread(x, sizeof(int), 4096, stdin);
    if (r == 0)
      break;
    {
      int i;
      for (i = 0; i < r; i++) {
        if (x[i] < -32768)
          y[i] = -32768;
        else if (x[i] > 32767)
          y[i] = 32767;
        else
          y[i] = (short)x[i];
      }
    }
    fwrite(y, sizeof(short), r, stdout);
  }
  fprintf(stderr, "int2short: done\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x6020,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1174 <main+0x44>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b7 <main+0x187>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
call   1040 <fprintf@plt>
lea    -0x4010(%rbp),%rdi
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %eax,-0x6014(%rbp)
cmpl   $0x0,-0x6014(%rbp)
jne    11c0 <main+0x90>
jmp    129b <main+0x16b>
movl   $0x0,-0x6018(%rbp)
mov    -0x6018(%rbp),%eax
cmp    -0x6014(%rbp),%eax
jge    1276 <main+0x146>
movslq -0x6018(%rbp),%rax
cmpl   $0xffff8000,-0x4010(%rbp,%rax,4)
jge    120a <main+0xda>
movslq -0x6018(%rbp),%rax
movw   $0x8000,-0x6010(%rbp,%rax,2)
jmp    125d <main+0x12d>
movslq -0x6018(%rbp),%rax
cmpl   $0x7fff,-0x4010(%rbp,%rax,4)
jle    1238 <main+0x108>
movslq -0x6018(%rbp),%rax
movw   $0x7fff,-0x6010(%rbp,%rax,2)
ff ff 7f
jmp    1258 <main+0x128>
movslq -0x6018(%rbp),%rax
mov    -0x4010(%rbp,%rax,4),%eax
mov    %ax,%cx
movslq -0x6018(%rbp),%rax
mov    %cx,-0x6010(%rbp,%rax,2)
ff
jmp    125d <main+0x12d>
jmp    1262 <main+0x132>
mov    -0x6018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x6018(%rbp)
jmp    11ca <main+0x9a>
lea    -0x6010(%rbp),%rdi
mov    -0x6014(%rbp),%edx
mov    0x2d46(%rip),%rax
mov    (%rax),%ecx
mov    $0x2,%esi
call   1050 <fwrite@plt>
jmp    1189 <main+0x59>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd87(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x6020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x6008,%rsp
mov    %edi,%eax
mov    0x2e8e(%rip),%rcx
mov    (%rcx),%edi
cmp    $0x2,%eax
jl     1167 <main+0x37>
lea    0xea8(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
jmp    1282 <main+0x152>
lea    0xeb0(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e6e(%rip),%r12
mov    (%r12),%ecx
lea    0x2000(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     126b <main+0x13b>
mov    $0x7fff,%ebp
mov    $0x8000,%ebx
mov    0x2e22(%rip),%r15
mov    %rsp,%r14
lea    0x2000(%rsp),%r13
jmp    11ec <main+0xbc>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x2,%esi
mov    %eax,%edx
call   1050 <fwrite@plt>
mov    (%r12),%ecx
mov    %r13,%rdi
mov    $0x4,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
test   %eax,%eax
je     126b <main+0x13b>
test   %eax,%eax
jle    11c0 <main+0x90>
mov    %eax,%ecx
cmp    $0x8,%eax
jae    1200 <main+0xd0>
xor    %edx,%edx
jmp    1240 <main+0x110>
nopl   0x0(%rax,%rax,1)
mov    %ecx,%edx
and    $0xfffffff8,%edx
xor    %esi,%esi
nopw   0x0(%rax,%rax,1)
movdqa 0x2000(%rsp,%rsi,4),%xmm0
packssdw 0x2010(%rsp,%rsi,4),%xmm0
movdqa %xmm0,(%rsp,%rsi,2)
add    $0x8,%rsi
cmp    %rsi,%rdx
jne    1210 <main+0xe0>
cmp    %rcx,%rdx
je     11c0 <main+0x90>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x2000(%rsp,%rdx,4),%esi
cmp    $0x7fff,%esi
cmovge %ebp,%esi
cmp    $0xffff8001,%esi
cmovl  %ebx,%esi
mov    %si,(%rsp,%rdx,2)
add    $0x1,%rdx
cmp    %rdx,%rcx
jne    1240 <main+0x110>
jmp    11c0 <main+0x90>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x6008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"int2short < entrada > salida\0A\00"
@.str.1 = [20 x i8] c"int2short: running\0A\00"
@stdin = global i32 0
@stdout = global i32 0
@.str.2 = [17 x i8] c"int2short: done\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i32]
%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 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %76
9: ; preds = %2
%10 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%11 = bitcast [4096 x i32]* %3 to i8*
%12 = bitcast [4096 x i16]* %4 to i8*
%13 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i32 @fread(i32* %13, i32 4, i32 4096, i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %73, label %17
17: ; preds = %9
%18 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 0
br label %19
19: ; preds = %17, %67
%20 = phi i32 [ %15, %17 ], [ %71, %67 ]
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %67
22: ; preds = %19
%23 = zext i32 %20 to i64
%24 = icmp ult i32 %20, 8
br i1 %24, label %53, label %25
25: ; preds = %22
%26 = and i64 %23, 4294967288
br label %27
27: ; preds = %27, %25
%28 = phi i64 [ 0, %25 ], [ %49, %27 ]
%29 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 %28
%30 = bitcast i32* %29 to <4 x i32>*
%31 = load <4 x i32>, <4 x i32>* %30
%32 = getelementptr inbounds i32, i32* %29, i64 4
%33 = bitcast i32* %32 to <4 x i32>*
%34 = load <4 x i32>, <4 x i32>* %33
%35 = icmp slt <4 x i32> %31, <i32 32767, i32 32767, i32 32767, i32 32767>
%36 = icmp slt <4 x i32> %34, <i32 32767, i32 32767, i32 32767, i32 32767>
%37 = select <4 x i1> %35, <4 x i32> %31, <4 x i32> <i32 32767, i32 32767, i32 32767, i32 32767>
%38 = select <4 x i1> %36, <4 x i32> %34, <4 x i32> <i32 32767, i32 32767, i32 32767, i32 32767>
%39 = icmp sgt <4 x i32> %37, <i32 -32768, i32 -32768, i32 -32768, i32 -32768>
%40 = icmp sgt <4 x i32> %38, <i32 -32768, i32 -32768, i32 -32768, i32 -32768>
%41 = select <4 x i1> %39, <4 x i32> %37, <4 x i32> <i32 -32768, i32 -32768, i32 -32768, i32 -32768>
%42 = select <4 x i1> %40, <4 x i32> %38, <4 x i32> <i32 -32768, i32 -32768, i32 -32768, i32 -32768>
%43 = trunc <4 x i32> %41 to <4 x i16>
%44 = trunc <4 x i32> %42 to <4 x i16>
%45 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 %28
%46 = bitcast i16* %45 to <4 x i16>*
store <4 x i16> %43, <4 x i16>* %46
%47 = getelementptr inbounds i16, i16* %45, i64 4
%48 = bitcast i16* %47 to <4 x i16>*
store <4 x i16> %44, <4 x i16>* %48
%49 = add nuw i64 %28, 8
%50 = icmp eq i64 %49, %26
br i1 %50, label %51, label %27
51: ; preds = %27
%52 = icmp eq i64 %26, %23
br i1 %52, label %67, label %53
53: ; preds = %22, %51
%54 = phi i64 [ 0, %22 ], [ %26, %51 ]
br label %55
55: ; preds = %53, %55
%56 = phi i64 [ %65, %55 ], [ %54, %53 ]
%57 = getelementptr inbounds [4096 x i32], [4096 x i32]* %3, i64 0, i64 %56
%58 = load i32, i32* %57
%59 = icmp slt i32 %58, 32767
%60 = select i1 %59, i32 %58, i32 32767
%61 = icmp sgt i32 %60, -32768
%62 = select i1 %61, i32 %60, i32 -32768
%63 = trunc i32 %62 to i16
%64 = getelementptr inbounds [4096 x i16], [4096 x i16]* %4, i64 0, i64 %56
store i16 %63, i16* %64
%65 = add nuw nsw i64 %56, 1
%66 = icmp eq i64 %65, %23
br i1 %66, label %67, label %55
67: ; preds = %55, %51, %19
%68 = load i32, i32* @stdout
%69 = call i32 @fwrite(i16* %18, i32 2, i32 %20, i32 %68)
%70 = load i32, i32* @stdin
%71 = call i32 @fread(i32* %13, i32 4, i32 4096, i32 %70)
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %19
73: ; preds = %67, %9
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %76
76: ; preds = %73, %7
%77 = phi i32 [ 1, %7 ], [ 0, %73 ]
ret i32 %77
}