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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
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 main(int argc, char *argv[]) {
  FILE *SF, *DF;
  unsigned short uwbuffer[1000];
  signed short swbuffer[1000];
  int usw;
  int n, k;
  if (argc < 3) {
    fprintf(stderr,
            "\nusage: uw2sw <unsigned word file> <signed word file>\n\n");
    return 1;
  }
  SF = fopen(argv[1], "r");
  if (SF == NULL) {
    fprintf(stderr, "\ncan't open %s!\n", argv[1]);
    return 1;
  }
  DF = fopen(argv[2], "w");
  if (DF == NULL) {
    fprintf(stderr, "\ncan't open %s!\n", argv[2]);
    return 1;
  }
  do {
    n = fread(&uwbuffer, sizeof(short), 1000, SF);
    for (k = 0; k < n; k++) {
      usw = uwbuffer[k];
      usw -= 2048;
      swbuffer[k] = usw;
    }
    fwrite(&swbuffer, sizeof(short), n, DF);
  } while (n == 1000);
  fclose(SF);
  fclose(DF);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1196 <main+0x46>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1309 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe93(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0x94>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1309 <main+0x1b9>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1232 <main+0xe2>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xe1b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1309 <main+0x1b9>
jmp    1237 <main+0xe7>
lea    -0x7f0(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x3e8,%edx
call   1030 <fread@plt>
mov    %eax,-0xfc8(%rbp)
movl   $0x0,-0xfcc(%rbp)
mov    -0xfcc(%rbp),%eax
cmp    -0xfc8(%rbp),%eax
jge    12c5 <main+0x175>
movslq -0xfcc(%rbp),%rax
movzwl -0x7f0(%rbp,%rax,2),%eax
ff
mov    %eax,-0xfc4(%rbp)
mov    -0xfc4(%rbp),%eax
sub    $0x800,%eax
mov    %eax,-0xfc4(%rbp)
mov    -0xfc4(%rbp),%eax
mov    %ax,%cx
movslq -0xfcc(%rbp),%rax
mov    %cx,-0xfc0(%rbp,%rax,2)
ff
mov    -0xfcc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfcc(%rbp)
jmp    1261 <main+0x111>
lea    -0xfc0(%rbp),%rdi
mov    -0xfc8(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
call   1070 <fwrite@plt>
cmpl   $0x3e8,-0xfc8(%rbp)
je     1237 <main+0xe7>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xfa0,%rsp
cmp    $0x2,%edi
jg     1185 <main+0x35>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    1366 <main+0x216>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1311 <main+0x1c1>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1320 <main+0x1d0>
mov    %rax,%r14
lea    0x7d0(%rsp),%r15
mov    %rsp,%r12
jmp    11ee <main+0x9e>
nopl   (%rax)
mov    %r12,%rdi
mov    $0x2,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    $0x3e8,%ebp
jne    1354 <main+0x204>
mov    %r15,%rdi
mov    $0x2,%esi
mov    $0x3e8,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1342 <main+0x1f2>
mov    %ebp,%eax
cmp    $0x10,%ebp
jae    1220 <main+0xd0>
xor    %ecx,%ecx
jmp    12e0 <main+0x190>
nopl   0x0(%rax,%rax,1)
mov    %eax,%ecx
and    $0xfffffff0,%ecx
lea    -0x10(%rcx),%rsi
mov    %rsi,%rdx
shr    $0x4,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     1300 <main+0x1b0>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
xor    %esi,%esi
movdqa 0xdb2(%rip),%xmm2
xchg   %ax,%ax
movdqa 0x7d0(%rsp,%rsi,2),%xmm0
paddw  %xmm2,%xmm0
movdqa 0x7e0(%rsp,%rsi,2),%xmm1
paddw  %xmm2,%xmm1
movdqa %xmm0,(%rsp,%rsi,2)
movdqa %xmm1,0x10(%rsp,%rsi,2)
movdqa 0x7f0(%rsp,%rsi,2),%xmm0
paddw  %xmm2,%xmm0
movdqa 0x800(%rsp,%rsi,2),%xmm1
paddw  %xmm2,%xmm1
movdqa %xmm0,0x20(%rsp,%rsi,2)
movdqa %xmm1,0x30(%rsp,%rsi,2)
add    $0x20,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1250 <main+0x100>
test   $0x1,%dl
je     12cf <main+0x17f>
movdqa 0x7d0(%rsp,%rsi,2),%xmm0
paddw  %xmm2,%xmm0
movdqa 0x7e0(%rsp,%rsi,2),%xmm1
paddw  %xmm2,%xmm1
movdqa %xmm0,(%rsp,%rsi,2)
movdqa %xmm1,0x10(%rsp,%rsi,2)
cmp    %rax,%rcx
je     11d0 <main+0x80>
nopl   0x0(%rax,%rax,1)
movzwl 0x7d0(%rsp,%rcx,2),%edx
add    $0xfffff800,%edx
mov    %dx,(%rsp,%rcx,2)
add    $0x1,%rcx
cmp    %rcx,%rax
jne    12e0 <main+0x190>
jmp    11d0 <main+0x80>
xor    %esi,%esi
movdqa 0xcf6(%rip),%xmm2
test   $0x1,%dl
jne    12aa <main+0x15a>
jmp    12cf <main+0x17f>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
jmp    132d <main+0x1dd>
mov    0x2cb9(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rbp),%rdx
lea    0xd16(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%eax
jmp    1366 <main+0x216>
mov    %rsp,%rdi
mov    $0x2,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xfa0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [56 x i8] c"\0Ausage: uw2sw <unsigned word file> <signed word file>\0A\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"\0Acan't open %s!\0A\00"
@.str.3 = [2 x i8] c"w\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 [1000 x i16]
%9 = alloca [1000 x i16]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 3
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %82
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %82
31: ; preds = %18
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 2
%34 = load i8*, i8** %33
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %35, i32** %7
%36 = load i32*, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %44
38: ; preds = %31
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 1, i32* %3
br label %82
44: ; preds = %31
br label %45
45: ; preds = %74, %44
%46 = bitcast [1000 x i16]* %8 to i16**
%47 = load i32*, i32** %6
%48 = call i32 @fread(i16** %46, i32 2, i32 1000, i32* %47)
store i32 %48, i32* %11
store i32 0, i32* %12
br label %49
49: ; preds = %66, %45
%50 = load i32, i32* %12
%51 = load i32, i32* %11
%52 = icmp slt i32 %50, %51
br i1 %52, label %53, label %69
53: ; preds = %49
%54 = load i32, i32* %12
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [1000 x i16], [1000 x i16]* %8, i64 0, i64 %55
%57 = load i16, i16* %56
%58 = zext i16 %57 to i32
store i32 %58, i32* %10
%59 = load i32, i32* %10
%60 = sub nsw i32 %59, 2048
store i32 %60, i32* %10
%61 = load i32, i32* %10
%62 = trunc i32 %61 to i16
%63 = load i32, i32* %12
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [1000 x i16], [1000 x i16]* %9, i64 0, i64 %64
store i16 %62, i16* %65
br label %66
66: ; preds = %53
%67 = load i32, i32* %12
%68 = add nsw i32 %67, 1
store i32 %68, i32* %12
br label %49
69: ; preds = %49
%70 = bitcast [1000 x i16]* %9 to i16**
%71 = load i32, i32* %11
%72 = load i32*, i32** %7
%73 = call i32 @fwrite(i16** %70, i32 2, i32 %71, i32* %72)
br label %74
74: ; preds = %69
%75 = load i32, i32* %11
%76 = icmp eq i32 %75, 1000
br i1 %76, label %45, label %77
77: ; preds = %74
%78 = load i32*, i32** %6
%79 = call i32 @fclose(i32* %78)
%80 = load i32*, i32** %7
%81 = call i32 @fclose(i32* %80)
store i32 0, i32* %3
br label %82
82: ; preds = %77, %38, %25, %15
%83 = load i32, i32* %3
ret i32 %83
}

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