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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int fread(short *, int, int, int /*<<< orphan*/ *);
int fwrite(short *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s file-in.rgb24 file-out.rgb16\n", argv[0]);
    return -1;
  }
  FILE *file_in = fopen(argv[1], "rb");
  if (!file_in) {
    fprintf(stderr, "error: %s, could not load input file '%s' for reading\n",
            argv[0], argv[1]);
    exit(1);
  }
  FILE *file_out = fopen(argv[2], "wb");
  if (!file_out) {
    fprintf(stderr, "error: %s, could not load output file '%s' for writing\n",
            argv[0], argv[2]);
    fclose(file_in);
    exit(1);
  }
  uint8_t rgb24[6];
  uint8_t yuv[4];
  while (1) {
    int num_read = fread(rgb24, sizeof(uint8_t), 6, file_in);
    if (feof(file_in)) {
      break;
    } else if (num_read != 6) {
      fprintf(stderr, "error: %s, could not read in data...\n", argv[0]);
      exit(1);
    }
    short red0 = rgb24[0];
    short green0 = rgb24[1];
    short blue0 = rgb24[2];
    short red1 = rgb24[3];
    short green1 = rgb24[4];
    short blue1 = rgb24[5];
    short y0 = (32768 + 19595 * red0 + 38470 * green0 + 7471 * blue0) >> 16;
    short y1 = (32768 + 19595 * red1 + 38470 * green1 + 7471 * blue1) >> 16;
    short red = (red0 + red1) / 2;
    short green = (green0 + green1) / 2;
    short blue = (blue0 + blue1) / 2;
    short cb = (8421376 - 11058 * red - 21709 * green + 32767 * blue) >> 16;
    short cr = (8421376 + 32767 * red - 27438 * green - 5329 * blue) >> 16;
    yuv[0] = y0;
    yuv[1] = cb;
    yuv[2] = y1;
    yuv[3] = cr;
    int num_written = fwrite(yuv, sizeof(uint8_t), 4, file_out);
    if (num_written != 4) {
      fprintf(stderr, "error: %s, could not write data to '%s' (%d written)\n",
              argv[0], argv[2], num_written);
      exit(1);
    }
  };
  fclose(file_in);
  fclose(file_out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11ba <main+0x4a>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1499 <main+0x329>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120d <main+0x9d>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe46(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1269 <main+0xf9>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xe16(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    126e <main+0xfe>
lea    -0x2c(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2,%esi
mov    $0x6,%edx
call   1030 <fread@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     12a0 <main+0x130>
jmp    1480 <main+0x310>
cmpl   $0x6,-0x38(%rbp)
je     12d2 <main+0x162>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xddc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12d7 <main+0x167>
mov    -0x2c(%rbp),%ax
mov    %ax,-0x3a(%rbp)
mov    -0x2a(%rbp),%ax
mov    %ax,-0x3c(%rbp)
mov    -0x28(%rbp),%ax
mov    %ax,-0x3e(%rbp)
mov    -0x26(%rbp),%ax
mov    %ax,-0x40(%rbp)
mov    -0x24(%rbp),%ax
mov    %ax,-0x42(%rbp)
mov    -0x22(%rbp),%ax
mov    %ax,-0x44(%rbp)
movswl -0x3a(%rbp),%eax
imul   $0x4c8b,%eax,%eax
add    $0x8000,%eax
movswl -0x3c(%rbp),%ecx
imul   $0x9646,%ecx,%ecx
add    %ecx,%eax
movswl -0x3e(%rbp),%ecx
imul   $0x1d2f,%ecx,%ecx
add    %ecx,%eax
sar    $0x10,%eax
mov    %ax,-0x46(%rbp)
movswl -0x40(%rbp),%eax
imul   $0x4c8b,%eax,%eax
add    $0x8000,%eax
movswl -0x42(%rbp),%ecx
imul   $0x9646,%ecx,%ecx
add    %ecx,%eax
movswl -0x44(%rbp),%ecx
imul   $0x1d2f,%ecx,%ecx
add    %ecx,%eax
sar    $0x10,%eax
mov    %ax,-0x48(%rbp)
movswl -0x3a(%rbp),%eax
movswl -0x40(%rbp),%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %ax,-0x4a(%rbp)
movswl -0x3c(%rbp),%eax
movswl -0x42(%rbp),%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %ax,-0x4c(%rbp)
movswl -0x3e(%rbp),%eax
movswl -0x44(%rbp),%ecx
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %ax,-0x4e(%rbp)
movswl -0x4a(%rbp),%eax
imul   $0x2b32,%eax,%ecx
mov    $0x808000,%eax
sub    %ecx,%eax
movswl -0x4c(%rbp),%ecx
imul   $0x54cd,%ecx,%ecx
sub    %ecx,%eax
movswl -0x4e(%rbp),%ecx
imul   $0x7fff,%ecx,%ecx
add    %ecx,%eax
sar    $0x10,%eax
mov    %ax,-0x50(%rbp)
movswl -0x4a(%rbp),%eax
imul   $0x7fff,%eax,%eax
add    $0x808000,%eax
movswl -0x4c(%rbp),%ecx
imul   $0x6b2e,%ecx,%ecx
sub    %ecx,%eax
movswl -0x4e(%rbp),%ecx
imul   $0x14d1,%ecx,%ecx
sub    %ecx,%eax
sar    $0x10,%eax
mov    %ax,-0x52(%rbp)
mov    -0x46(%rbp),%ax
mov    %ax,-0x34(%rbp)
mov    -0x50(%rbp),%ax
mov    %ax,-0x32(%rbp)
mov    -0x48(%rbp),%ax
mov    %ax,-0x30(%rbp)
mov    -0x52(%rbp),%ax
mov    %ax,-0x2e(%rbp)
lea    -0x34(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x2,%esi
mov    $0x4,%edx
call   1090 <fwrite@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0x4,-0x58(%rbp)
je     147b <main+0x30b>
mov    0x2b92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
mov    -0x58(%rbp),%r8d
lea    0xc59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    126e <main+0xfe>
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    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     11aa <main+0x3a>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe67(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1369 <main+0x1f9>
mov    0x8(%rbx),%rdi
lea    0xe73(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     13a1 <main+0x231>
mov    %rax,%r14
mov    %rbx,0x20(%rsp)
mov    0x10(%rbx),%rdi
lea    0xe8c(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     13c9 <main+0x259>
mov    %rax,%r15
lea    0x14(%rsp),%r12
lea    0xc(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x2,%esi
mov    $0x6,%edx
mov    %r14,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1060 <feof@plt>
test   %rax,%rax
jne    1357 <main+0x1e7>
cmp    $0x6,%ebp
jne    1378 <main+0x208>
movswl 0x14(%rsp),%edi
movswl 0x16(%rsp),%ebx
movswl 0x18(%rsp),%r9d
movswl 0x1a(%rsp),%ebp
movswl 0x1c(%rsp),%eax
movswl 0x1e(%rsp),%edx
imul   $0x4c8b,%edi,%ecx
imul   $0x9646,%ebx,%esi
add    %ecx,%esi
imul   $0x1d2f,%r9d,%ecx
lea    (%rcx,%rsi,1),%r8d
add    $0x8000,%r8d
shr    $0x10,%r8d
imul   $0x4c8b,%ebp,%ecx
imul   $0x9646,%eax,%esi
add    %ecx,%esi
imul   $0x1d2f,%edx,%ecx
add    %esi,%ecx
add    $0x8000,%ecx
shr    $0x10,%ecx
add    %edi,%ebp
mov    %ebp,%edi
shr    $0x1f,%edi
add    %ebp,%edi
sar    %edi
add    %ebx,%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
add    %r9d,%edx
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
sar    %eax
imul   $0xffffd4ce,%edi,%edx
imul   $0xffffab33,%ebp,%esi
add    %edx,%esi
mov    %eax,%edx
shl    $0xf,%edx
sub    %eax,%edx
add    %esi,%edx
add    $0x808000,%edx
shr    $0x10,%edx
mov    %edi,%esi
shl    $0xf,%esi
sub    %edi,%esi
imul   $0xffff94d2,%ebp,%edi
add    %esi,%edi
imul   $0xffffeb2f,%eax,%eax
add    %edi,%eax
add    $0x808000,%eax
shr    $0x10,%eax
mov    %r8w,0xc(%rsp)
mov    %dx,0xe(%rsp)
mov    %cx,0x10(%rsp)
mov    %ax,0x12(%rsp)
mov    %r13,%rdi
mov    $0x2,%esi
mov    $0x4,%edx
mov    %r15,%rcx
call   1090 <fwrite@plt>
cmp    $0x4,%eax
je     1200 <main+0x90>
mov    0x2cb2(%rip),%rcx
mov    (%rcx),%edi
mov    0x20(%rsp),%rcx
mov    (%rcx),%rdx
mov    0x10(%rcx),%rcx
lea    0xd80(%rip),%rsi
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rax
mov    (%rax),%rdx
lea    0xd0d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2c38(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xc73(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2c10(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rsp),%rax
mov    (%rax),%rdx
mov    0x10(%rax),%rcx
lea    0xc80(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s file-in.rgb24 file-out.rgb16\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [55 x i8] c"error: %s, could not load input file '%s' for reading\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [56 x i8] c"error: %s, could not load output file '%s' for writing\0A\00"
@.str.5 = [38 x i8] c"error: %s, could not read in data...\0A\00"
@.str.6 = [54 x i8] c"error: %s, could not write data to '%s' (%d written)\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 [6 x i16]
%9 = alloca [4 x i16]
%10 = alloca i32
%11 = alloca i16
%12 = alloca i16
%13 = alloca i16
%14 = alloca i16
%15 = alloca i16
%16 = alloca i16
%17 = alloca i16
%18 = alloca i16
%19 = alloca i16
%20 = alloca i16
%21 = alloca i16
%22 = alloca i16
%23 = alloca i16
%24 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 3
br i1 %26, label %27, label %33
27: ; preds = %2
%28 = load i32, i32* @stderr
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %31)
store i32 -1, i32* %3
br label %209
33: ; preds = %2
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %37, i32** %6
%38 = load i32*, i32** %6
%39 = icmp ne i32* %38, null
br i1 %39, label %50, label %40
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %44, i8* %47)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %33
%51 = load i8**, i8*** %5
%52 = getelementptr inbounds i8*, i8** %51, i64 2
%53 = load i8*, i8** %52
%54 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %54, i32** %7
%55 = load i32*, i32** %7
%56 = icmp ne i32* %55, null
br i1 %56, label %69, label %57
57: ; preds = %50
%58 = load i32, i32* @stderr
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 2
%64 = load i8*, i8** %63
%65 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %61, i8* %64)
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %50
br label %70
70: ; preds = %69, %203
%71 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 0
%72 = load i32*, i32** %6
%73 = call i32 @fread(i16* %71, i32 2, i32 6, i32* %72)
store i32 %73, i32* %10
%74 = load i32*, i32** %6
%75 = call i64 @feof(i32* %74)
%76 = icmp ne i64 %75, 0
br i1 %76, label %77, label %78
77: ; preds = %70
br label %204
78: ; preds = %70
%79 = load i32, i32* %10
%80 = icmp ne i32 %79, 6
br i1 %80, label %81, label %88
81: ; preds = %78
%82 = load i32, i32* @stderr
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 0
%85 = load i8*, i8** %84
%86 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %85)
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %78
br label %89
89: ; preds = %88
%90 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 0
%91 = load i16, i16* %90
store i16 %91, i16* %11
%92 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 1
%93 = load i16, i16* %92
store i16 %93, i16* %12
%94 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 2
%95 = load i16, i16* %94
store i16 %95, i16* %13
%96 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 3
%97 = load i16, i16* %96
store i16 %97, i16* %14
%98 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 4
%99 = load i16, i16* %98
store i16 %99, i16* %15
%100 = getelementptr inbounds [6 x i16], [6 x i16]* %8, i64 0, i64 5
%101 = load i16, i16* %100
store i16 %101, i16* %16
%102 = load i16, i16* %11
%103 = sext i16 %102 to i32
%104 = mul nsw i32 19595, %103
%105 = add nsw i32 32768, %104
%106 = load i16, i16* %12
%107 = sext i16 %106 to i32
%108 = mul nsw i32 38470, %107
%109 = add nsw i32 %105, %108
%110 = load i16, i16* %13
%111 = sext i16 %110 to i32
%112 = mul nsw i32 7471, %111
%113 = add nsw i32 %109, %112
%114 = ashr i32 %113, 16
%115 = trunc i32 %114 to i16
store i16 %115, i16* %17
%116 = load i16, i16* %14
%117 = sext i16 %116 to i32
%118 = mul nsw i32 19595, %117
%119 = add nsw i32 32768, %118
%120 = load i16, i16* %15
%121 = sext i16 %120 to i32
%122 = mul nsw i32 38470, %121
%123 = add nsw i32 %119, %122
%124 = load i16, i16* %16
%125 = sext i16 %124 to i32
%126 = mul nsw i32 7471, %125
%127 = add nsw i32 %123, %126
%128 = ashr i32 %127, 16
%129 = trunc i32 %128 to i16
store i16 %129, i16* %18
%130 = load i16, i16* %11
%131 = sext i16 %130 to i32
%132 = load i16, i16* %14
%133 = sext i16 %132 to i32
%134 = add nsw i32 %131, %133
%135 = sdiv i32 %134, 2
%136 = trunc i32 %135 to i16
store i16 %136, i16* %19
%137 = load i16, i16* %12
%138 = sext i16 %137 to i32
%139 = load i16, i16* %15
%140 = sext i16 %139 to i32
%141 = add nsw i32 %138, %140
%142 = sdiv i32 %141, 2
%143 = trunc i32 %142 to i16
store i16 %143, i16* %20
%144 = load i16, i16* %13
%145 = sext i16 %144 to i32
%146 = load i16, i16* %16
%147 = sext i16 %146 to i32
%148 = add nsw i32 %145, %147
%149 = sdiv i32 %148, 2
%150 = trunc i32 %149 to i16
store i16 %150, i16* %21
%151 = load i16, i16* %19
%152 = sext i16 %151 to i32
%153 = mul nsw i32 11058, %152
%154 = sub nsw i32 8421376, %153
%155 = load i16, i16* %20
%156 = sext i16 %155 to i32
%157 = mul nsw i32 21709, %156
%158 = sub nsw i32 %154, %157
%159 = load i16, i16* %21
%160 = sext i16 %159 to i32
%161 = mul nsw i32 32767, %160
%162 = add nsw i32 %158, %161
%163 = ashr i32 %162, 16
%164 = trunc i32 %163 to i16
store i16 %164, i16* %22
%165 = load i16, i16* %19
%166 = sext i16 %165 to i32
%167 = mul nsw i32 32767, %166
%168 = add nsw i32 8421376, %167
%169 = load i16, i16* %20
%170 = sext i16 %169 to i32
%171 = mul nsw i32 27438, %170
%172 = sub nsw i32 %168, %171
%173 = load i16, i16* %21
%174 = sext i16 %173 to i32
%175 = mul nsw i32 5329, %174
%176 = sub nsw i32 %172, %175
%177 = ashr i32 %176, 16
%178 = trunc i32 %177 to i16
store i16 %178, i16* %23
%179 = load i16, i16* %17
%180 = getelementptr inbounds [4 x i16], [4 x i16]* %9, i64 0, i64 0
store i16 %179, i16* %180
%181 = load i16, i16* %22
%182 = getelementptr inbounds [4 x i16], [4 x i16]* %9, i64 0, i64 1
store i16 %181, i16* %182
%183 = load i16, i16* %18
%184 = getelementptr inbounds [4 x i16], [4 x i16]* %9, i64 0, i64 2
store i16 %183, i16* %184
%185 = load i16, i16* %23
%186 = getelementptr inbounds [4 x i16], [4 x i16]* %9, i64 0, i64 3
store i16 %185, i16* %186
%187 = getelementptr inbounds [4 x i16], [4 x i16]* %9, i64 0, i64 0
%188 = load i32*, i32** %7
%189 = call i32 @fwrite(i16* %187, i32 2, i32 4, i32* %188)
store i32 %189, i32* %24
%190 = load i32, i32* %24
%191 = icmp ne i32 %190, 4
br i1 %191, label %192, label %203
192: ; preds = %89
%193 = load i32, i32* @stderr
%194 = load i8**, i8*** %5
%195 = getelementptr inbounds i8*, i8** %194, i64 0
%196 = load i8*, i8** %195
%197 = load i8**, i8*** %5
%198 = getelementptr inbounds i8*, i8** %197, i64 2
%199 = load i8*, i8** %198
%200 = load i32, i32* %24
%201 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %193, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0), i8* %196, i8* %199, i32 %200)
%202 = call i32 @exit(i32 1)
unreachable
203: ; preds = %89
br label %70
204: ; preds = %77
%205 = load i32*, i32** %6
%206 = call i32 @fclose(i32* %205)
%207 = load i32*, i32** %7
%208 = call i32 @fclose(i32* %207)
store i32 0, i32* %3
br label %209
209: ; preds = %204, %27
%210 = load i32, i32* %3
ret i32 %210
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [40 x i8] c"Usage: %s file-in.rgb24 file-out.rgb16\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [55 x i8] c"error: %s, could not load input file '%s' for reading\0A\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [56 x i8] c"error: %s, could not load output file '%s' for writing\0A\00"
@.str.5 = [38 x i8] c"error: %s, could not read in data...\0A\00"
@.str.6 = [54 x i8] c"error: %s, could not write data to '%s' (%d written)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [6 x i16]
%4 = alloca [4 x i16]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %119
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = load i8*, i8** %11
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0), i8* %17, i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %1
%29 = load i8*, i8** %22
%30 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.4, i64 0, i64 0), i8* %28, i8* %29)
%31 = tail call i32 @fclose(i32* %13)
%32 = tail call i32 @exit(i32 1)
unreachable
33: ; preds = %21
%34 = bitcast [6 x i16]* %3 to i8*
%35 = bitcast [4 x i16]* %4 to i8*
%36 = getelementptr inbounds [6 x i16], [6 x i16]* %3, i64 0, i64 0
%37 = getelementptr inbounds [6 x i16], [6 x i16]* %3, i64 0, i64 1
%38 = getelementptr inbounds [6 x i16], [6 x i16]* %3, i64 0, i64 2
%39 = getelementptr inbounds [6 x i16], [6 x i16]* %3, i64 0, i64 3
%40 = getelementptr inbounds [6 x i16], [6 x i16]* %3, i64 0, i64 4
%41 = getelementptr inbounds [6 x i16], [6 x i16]* %3, i64 0, i64 5
%42 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 0
%43 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 1
%44 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 2
%45 = getelementptr inbounds [4 x i16], [4 x i16]* %4, i64 0, i64 3
br label %46
46: ; preds = %57, %33
%47 = call i32 @fread(i16* %36, i32 2, i32 6, i32* %13)
%48 = tail call i64 @feof(i32* %13)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %116
50: ; preds = %46
%51 = icmp eq i32 %47, 6
br i1 %51, label %57, label %52
52: ; preds = %50
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %1
%55 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = tail call i32 @exit(i32 1)
unreachable
57: ; preds = %50
%58 = load i16, i16* %36
%59 = load i16, i16* %37
%60 = load i16, i16* %38
%61 = load i16, i16* %39
%62 = load i16, i16* %40
%63 = load i16, i16* %41
%64 = sext i16 %58 to i32
%65 = mul nsw i32 %64, 19595
%66 = add nsw i32 %65, 32768
%67 = sext i16 %59 to i32
%68 = mul nsw i32 %67, 38470
%69 = add nsw i32 %66, %68
%70 = sext i16 %60 to i32
%71 = mul nsw i32 %70, 7471
%72 = add nsw i32 %69, %71
%73 = lshr i32 %72, 16
%74 = trunc i32 %73 to i16
%75 = sext i16 %61 to i32
%76 = mul nsw i32 %75, 19595
%77 = add nsw i32 %76, 32768
%78 = sext i16 %62 to i32
%79 = mul nsw i32 %78, 38470
%80 = add nsw i32 %77, %79
%81 = sext i16 %63 to i32
%82 = mul nsw i32 %81, 7471
%83 = add nsw i32 %80, %82
%84 = lshr i32 %83, 16
%85 = trunc i32 %84 to i16
%86 = add nsw i32 %75, %64
%87 = sdiv i32 %86, 2
%88 = add nsw i32 %78, %67
%89 = sdiv i32 %88, 2
%90 = add nsw i32 %81, %70
%91 = sdiv i32 %90, 2
%92 = mul nsw i32 %87, -11058
%93 = add nsw i32 %92, 8421376
%94 = mul nsw i32 %89, -21709
%95 = add nsw i32 %93, %94
%96 = mul nsw i32 %91, 32767
%97 = add nsw i32 %95, %96
%98 = lshr i32 %97, 16
%99 = trunc i32 %98 to i16
%100 = mul nsw i32 %87, 32767
%101 = add nsw i32 %100, 8421376
%102 = mul nsw i32 %89, -27438
%103 = add nsw i32 %101, %102
%104 = mul nsw i32 %91, -5329
%105 = add i32 %103, %104
%106 = lshr i32 %105, 16
%107 = trunc i32 %106 to i16
store i16 %74, i16* %42
store i16 %99, i16* %43
store i16 %85, i16* %44
store i16 %107, i16* %45
%108 = call i32 @fwrite(i16* %42, i32 2, i32 4, i32* %24)
%109 = icmp eq i32 %108, 4
br i1 %109, label %46, label %110
110: ; preds = %57
%111 = load i32, i32* @stderr
%112 = load i8*, i8** %1
%113 = load i8*, i8** %22
%114 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.6, i64 0, i64 0), i8* %112, i8* %113, i32 %108)
%115 = tail call i32 @exit(i32 1)
unreachable
116: ; preds = %46
%117 = tail call i32 @fclose(i32* %13)
%118 = tail call i32 @fclose(i32* %24)
br label %119
119: ; preds = %116, %6
%120 = phi i32 [ -1, %6 ], [ 0, %116 ]
ret i32 %120
}